From 030fb2d22379d5dd8367249cb3f2dfc9af323c4d Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 29 Nov 2022 20:05:06 +0700 Subject: [PATCH] move currentLocation into event listener --- extension/script.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/extension/script.js b/extension/script.js index f174018..bebff3f 100644 --- a/extension/script.js +++ b/extension/script.js @@ -122,16 +122,17 @@ function buildButtonDiv() { function buildSubLink(channelContainer) { var subLink = document.createElement("span"); - var currentLocation = window.location.href; subLink.innerText = "Subscribe"; subLink.addEventListener('click', e => { e.preventDefault(); + var currentLocation = window.location.href; console.log("subscribe to: " + currentLocation); sendUrl(currentLocation, "subscribe", subLink); }); subLink.addEventListener("mouseover", e => { let subText if (window.location.pathname == "/watch") { + var currentLocation = window.location.href; subText = currentLocation; } else { subText = channelContainer.querySelector("#text").textContent; @@ -156,17 +157,18 @@ function buildSpacer() { function buildDlLink(channelContainer) { var dlLink = document.createElement("span"); - var currentLocation = window.location.href; dlLink.innerHTML = downloadIcon; dlLink.addEventListener('click', e => { e.preventDefault(); + var currentLocation = window.location.href; console.log("download: " + currentLocation) sendUrl(currentLocation, "download", dlLink); }); dlLink.addEventListener("mouseover", e => { let subText if (window.location.pathname == "/watch") { + var currentLocation = window.location.href; subText = currentLocation; } else { subText = channelContainer.querySelector("#text").textContent; @@ -366,7 +368,6 @@ const throttle = (callback, time) => { if (throttleBlock) return; throttleBlock = true; setTimeout(() => { - console.log("observer hit"); callback(); throttleBlock = false; }, time);