Update hotkey script to work with multiple selectors

Because, of course, videos are drawn differently on home page, search
results, video recommendations and subscriptions
THANKS GOOGL
This commit is contained in:
2024-12-21 11:34:29 +01:00
parent ad4aac1061
commit 0c1a643d93

View File

@@ -1,20 +1,26 @@
nodes = document.querySelectorAll(":hover"); nodes = document.querySelectorAll(":hover");
i = 1; i = 1;
console.log(nodes); console.log(nodes);
titleNode = nodes[nodes.length - i];
selector = "a#video-title-link"; selectors = ["a#video-title-link", "a#video-title"];
invidious = false; invidious = false;
if (window.location.href.includes("invidious.site")) { if (window.location.href.includes("invidious.site")) {
selector = "a"; selector = "a";
invidious = true; invidious = true;
} }
while (titleNode && !titleNode.matches(selector)) { titleNode = nodes[nodes.length - i];
outer:
while (titleNode) {
for (let selector of selectors) {
if (titleNode.matches(selector)) {
break outer;
}
}
titleNode = titleNode.parentElement; titleNode = titleNode.parentElement;
console.log(titleNode); console.log(titleNode);
} }
if (!(titleNode && titleNode.matches(selector))) { if (!titleNode) {
console.error("No video element found."); console.error("No video element found.");
} else { } else {
link = titleNode.href; link = titleNode.href;