flip getChannelHandle logic, remove unvisible title containers

This commit is contained in:
Simon 2023-11-08 18:01:50 +07:00
parent 75848ad4eb
commit 4f54e1f863
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
1 changed files with 21 additions and 8 deletions

View File

@ -192,13 +192,20 @@ function buildChannelButton(channelContainer) {
} }
function getChannelHandle(channelContainer) { function getChannelHandle(channelContainer) {
const channelHandleContainer = document.querySelector('#channel-handle'); let channelHandle;
let channelHandle = channelHandleContainer ? channelHandleContainer.innerText : null; const videoOwnerRenderer = channelContainer.querySelector('.ytd-video-owner-renderer');
if (!channelHandle) {
let href = channelContainer.querySelector('.ytd-video-owner-renderer').href; if (!videoOwnerRenderer) {
const urlObj = new URL(href); const channelHandleContainer = document.querySelector('#channel-handle');
channelHandle = urlObj.pathname.split('/')[1]; channelHandle = channelHandleContainer ? channelHandleContainer.innerText : null;
} else {
const href = videoOwnerRenderer.href;
if (href) {
const urlObj = new URL(href);
channelHandle = urlObj.pathname.split('/')[1];
}
} }
return channelHandle; return channelHandle;
} }
@ -309,8 +316,14 @@ function buildChannelDownloadButton() {
} }
function getTitleContainers() { function getTitleContainers() {
let nodes = document.querySelectorAll('#video-title'); let elements = document.querySelectorAll('#video-title');
return nodes; let videoNodes = [];
elements.forEach(element => {
if (isElementVisible(element)) {
videoNodes.push(element);
}
});
return elements;
} }
function buildVideoButton(titleContainer) { function buildVideoButton(titleContainer) {