mirror of
https://github.com/tubearchivist/browser-extension.git
synced 2025-02-05 15:40:14 +00:00
fix channel button selector, better handle extraction
This commit is contained in:
parent
b28efc7960
commit
cb4082362b
@ -106,11 +106,11 @@ function getBrowser() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getChannelContainers() {
|
function getChannelContainers() {
|
||||||
const elements = document.querySelectorAll('#inner-header-container, #owner');
|
const elements = document.querySelectorAll('.page-header-view-model-wiz__page-header-flexible-actions, #owner');
|
||||||
const channelContainerNodes = [];
|
const channelContainerNodes = [];
|
||||||
|
|
||||||
elements.forEach(element => {
|
elements.forEach(element => {
|
||||||
if (isElementVisible(element)) {
|
if (isElementVisible(element) && window.location.pathname !== '/playlist') {
|
||||||
channelContainerNodes.push(element);
|
channelContainerNodes.push(element);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -194,20 +194,40 @@ function buildChannelButton(channelContainer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getChannelHandle(channelContainer) {
|
function getChannelHandle(channelContainer) {
|
||||||
let channelHandle;
|
|
||||||
const videoOwnerRenderer = channelContainer.querySelector('.ytd-video-owner-renderer');
|
|
||||||
|
|
||||||
if (!videoOwnerRenderer) {
|
function findeHandleString(container) {
|
||||||
const channelHandleContainer = document.querySelector('#channel-handle');
|
let result = null;
|
||||||
channelHandle = channelHandleContainer ? channelHandleContainer.innerText : null;
|
|
||||||
} else {
|
function recursiveTraversal(element) {
|
||||||
const href = videoOwnerRenderer.href;
|
for (let child of element.children) {
|
||||||
if (href) {
|
|
||||||
const urlObj = new URL(href);
|
if (child.tagName === "A" && child.hasAttribute("href")) {
|
||||||
channelHandle = urlObj.pathname.split('/')[1];
|
const href = child.getAttribute("href");
|
||||||
|
const match = href.match(/\/@[^/]+/); // Match the path starting with "@"
|
||||||
|
if (match) {
|
||||||
|
// handle is in channel link
|
||||||
|
result = match[0].substring(1);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (child.children.length === 0 && child.textContent.trim().startsWith("@")) {
|
||||||
|
// handle is in channel description text
|
||||||
|
result = child.textContent.trim();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
recursiveTraversal(child);
|
||||||
|
if (result) return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
recursiveTraversal(container);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
let channelHandle = findeHandleString(channelContainer.parentElement);
|
||||||
|
|
||||||
return channelHandle;
|
return channelHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user