// Monitor URL and DOM changes const rootNode = document.querySelector("body"); if (rootNode) { var urlAtLastCheck = ""; new MutationObserver(() => { if (urlAtLastCheck !== document.location.href) { urlAtLastCheck = document.location.href; clickVideoTab(); } }).observe(rootNode, { childList: true, subtree: true }); }
// Check if URL is a YouTube channel page function isChannelPage(url) { return /^https:\/\/www\.youtube\.com\/@[^\/]+$/.test(url); }
// Find and click the "videos" tab on a channel page function clickVideoTab() { if (isChannelPage(window.location.href)) { const intervalId = setInterval(() => { const divTabs = document.querySelectorAll("div#tabsContainer > div#tabsContent yt-tab-shape, div#tabsContainer > div#tabsContent tp-yt-paper-tab");
let videoTab = null;
// Loop through the tabs to find the one with the text "videos" for (let i = 0; i < divTabs.length; i++) { if (divTabs[i].innerText.toLowerCase() === "videos") { videoTab = divTabs[i]; break; } }
if (videoTab) { videoTab.click(); clearInterval(intervalId); } }, 100); } };
I made ur script readable
// Monitor URL and DOM changes
const rootNode = document.querySelector("body");
if (rootNode) {
var urlAtLastCheck = "";
new MutationObserver(() => {
if (urlAtLastCheck !== document.location.href) {
urlAtLastCheck = document.location.href;
clickVideoTab();
}
}).observe(rootNode, { childList: true, subtree: true });
}
// Check if URL is a YouTube channel page
function isChannelPage(url) {
return /^https:\/\/www\.youtube\.com\/@[^\/]+$/.test(url);
}
// Find and click the "videos" tab on a channel page
function clickVideoTab() {
if (isChannelPage(window.location.href)) {
const intervalId = setInterval(() => {
const divTabs = document.querySelectorAll("div#tabsContainer > div#tabsContent yt-tab-shape, div#tabsContainer > div#tabsContent tp-yt-paper-tab");
let videoTab = null;
// Loop through the tabs to find the one with the text "videos"
for (let i = 0; i < divTabs.length; i++) {
if (divTabs[i].innerText.toLowerCase() === "videos") {
videoTab = divTabs[i];
break;
}
}
if (videoTab) {
videoTab.click();
clearInterval(intervalId);
}
}, 100);
}
};