From 73fee5614a230ec73a4bba1833afa8769b4ef140 Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Fri, 17 Oct 2025 15:54:00 -0400 Subject: [PATCH] Add per site delays --- background.js | 23 ++++++++++++++++++++--- options.html | 3 +++ options.js | 11 ++++++++++- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/background.js b/background.js index 40ae118..5987118 100644 --- a/background.js +++ b/background.js @@ -30,6 +30,18 @@ function isBlacklisted(url, blacklist) { return blacklist.some((p) => matchPattern(url, p)); } +function getDelayForUrl(url, settings) { + try { + const u = new URL(url); + for (const [domain, customDelay] of Object.entries(settings.siteDelays)) { + if (u.hostname.includes(domain)) { + return customDelay; + } + } + } catch (err) {} + return settings.delay; +} + let activeTabs = new Map(); // Load settings @@ -59,7 +71,7 @@ function updateIcon(state) { browser.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => { if (changeInfo.status !== "complete" || !tab.url) return; const settings = await getSettings(); - const { delay, blacklist, paused } = settings; + const { delay, blacklist, paused } = await getSettings(); if (paused || isBlacklisted(tab.url, blacklist)) return; if (tab.url.startsWith("moz-extension://")) return; @@ -67,10 +79,15 @@ browser.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => { const url = encodeURIComponent(tab.url); updateIcon("wait"); + if (activeTabs.has(tabId)) clearTimeout(activeTabs.get(tabId)); + const siteDelay = getDelayForUrl(url, await getSettings()); + if (activeTabs.has(tabId)) clearTimeout(activeTabs.get(tabId)); const timeout = setTimeout(() => { - fetch(`${SCROBBLE_ENDPOINT}${url}`).then(() => updateIcon("scrobbled")); - }, delay * 1000); + scrobbleStart(url, scrobbleBaseUrl); + updateIcon(tabId, "scrobbled"); + setTimeout(() => updateIcon(tabId, "wait"), 3000); + }, siteDelay * 1000); activeTabs.set(tabId, timeout); }); diff --git a/options.html b/options.html index af3d204..779f6f9 100644 --- a/options.html +++ b/options.html @@ -8,6 +8,9 @@

Life Scrobbler Settings



+
+ +




diff --git a/options.js b/options.js index 23a3b87..3682671 100644 --- a/options.js +++ b/options.js @@ -3,8 +3,17 @@ document.getElementById("save").addEventListener("click", save); const DEFAULT_SETTINGS = { delay: 7, - blacklist: ["*.unbl.ink", "moz-extension://", "*.google.com", "gmail.com", "*.chatgpt.com", "*.ebay.com", "*.amazon.com"], + blacklist: [ + "*.unbl.ink", + "moz-extension://", + "*.google.com", + "gmail.com", + "*.chatgpt.com", + "*.ebay.com", + "*.amazon.com", + ], paused: false, + siteDelays: { "readscomisconline.ru": 1 }, }; function restore() {