From 0ce14bdc539801a172032020d26182d0969e1909 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Sat, 17 Aug 2024 15:12:01 +0200 Subject: [PATCH] Update hotkey --- hotkey.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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)); });