diff --git a/hotkey.js b/hotkey.js index 32e1abd..1e62915 100644 --- a/hotkey.js +++ b/hotkey.js @@ -3,14 +3,25 @@ i = 1; console.log(nodes); titleNode = nodes[nodes.length - i]; -while (titleNode && !titleNode.matches("a#video-title-link")) { +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("a#video-title-link"))) { +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: { @@ -21,6 +32,9 @@ if (!(titleNode && titleNode.matches("a#video-title-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)); });