Files
youtube-downloader/hotkey.js
PhatPhuckDave 0c1a643d93 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
2024-12-21 11:34:29 +01:00

48 lines
1.1 KiB
JavaScript

nodes = document.querySelectorAll(":hover");
i = 1;
console.log(nodes);
selectors = ["a#video-title-link", "a#video-title"];
invidious = false;
if (window.location.href.includes("invidious.site")) {
selector = "a";
invidious = true;
}
titleNode = nodes[nodes.length - i];
outer:
while (titleNode) {
for (let selector of selectors) {
if (titleNode.matches(selector)) {
break outer;
}
}
titleNode = titleNode.parentElement;
console.log(titleNode);
}
if (!titleNode) {
console.error("No video element found.");
} else {
link = titleNode.href;
if (link.startsWith("/")) {
link = window.location.origin + link;
}
console.log(link);
fetch("https://nsq.site.quack-lab.dev/pub?topic=ytdqueue", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
link: link,
}),
}).then((res) => {
textNode = titleNode.querySelector("yt-formatted-string");
if (invidious) {
textNode = titleNode.querySelector("p");
}
textNode.style.setProperty("color", "green", "important");
res.json().then((data) => console.log(data));
});
}