Files
youtube-downloader/hotkey.js
2024-08-17 15:12:01 +02:00

42 lines
1.0 KiB
JavaScript

nodes = document.querySelectorAll(":hover");
i = 1;
console.log(nodes);
titleNode = nodes[nodes.length - i];
selector = "a#video-title-link";
invidious = false;
if (window.location.href.includes("invidious.site")) {
selector = "a";
invidious = true;
}
while (titleNode && !titleNode.matches(selector)) {
titleNode = titleNode.parentElement;
console.log(titleNode);
}
if (!(titleNode && titleNode.matches(selector))) {
console.error("No video element found.");
} else {
link = titleNode.href;
if (link.startsWith("/")) {
link = window.location.origin + link;
}
console.log(link);
fetch("http://localhost:5000/download", {
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));
});
}