From 692b598a386a0a63ff084b4d7368e55820393957 Mon Sep 17 00:00:00 2001 From: def00111 Date: Sun, 22 Jun 2025 12:26:55 +0200 Subject: [PATCH 1/2] Update background.js --- chill-out/background.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/chill-out/background.js b/chill-out/background.js index 880e3cf3..8e94400d 100644 --- a/chill-out/background.js +++ b/chill-out/background.js @@ -11,11 +11,14 @@ a minute. let DELAY = 0.1; let CATGIFS = "https://giphy.com/explore/cat"; +function getActiveTab() { + return browser.tabs.query({active: true, currentWindow: true}); +} + /* Restart alarm for the currently active tab, whenever background.js is run. */ -let gettingActiveTab = browser.tabs.query({active: true, currentWindow: true}); -gettingActiveTab.then((tabs) => { +getActiveTab().then((tabs) => { restartAlarm(tabs[0].id); }); @@ -26,8 +29,7 @@ browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { if (!changeInfo.url) { return; } - let gettingActiveTab = browser.tabs.query({active: true, currentWindow: true}); - gettingActiveTab.then((tabs) => { + getActiveTab().then((tabs) => { if (tabId == tabs[0].id) { restartAlarm(tabId); } @@ -60,8 +62,7 @@ function restartAlarm(tabId) { On alarm, show the page action. */ browser.alarms.onAlarm.addListener((alarm) => { - let gettingActiveTab = browser.tabs.query({active: true, currentWindow: true}); - gettingActiveTab.then((tabs) => { + getActiveTab().then((tabs) => { browser.pageAction.show(tabs[0].id); }); }); From 6dbf22d46e25dbd143c0e0e51ba82706577985a1 Mon Sep 17 00:00:00 2001 From: def00111 Date: Sun, 22 Jun 2025 12:39:07 +0200 Subject: [PATCH 2/2] Update example --- chill-out/background.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/chill-out/background.js b/chill-out/background.js index 8e94400d..81eec544 100644 --- a/chill-out/background.js +++ b/chill-out/background.js @@ -12,14 +12,17 @@ let DELAY = 0.1; let CATGIFS = "https://giphy.com/explore/cat"; function getActiveTab() { - return browser.tabs.query({active: true, currentWindow: true}); + return browser.tabs.query({ + active: true, + currentWindow: true, + }).then(tabs => tabs[0]); } /* Restart alarm for the currently active tab, whenever background.js is run. */ -getActiveTab().then((tabs) => { - restartAlarm(tabs[0].id); +getActiveTab().then((tab) => { + restartAlarm(tab.id); }); /* @@ -29,8 +32,8 @@ browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { if (!changeInfo.url) { return; } - getActiveTab().then((tabs) => { - if (tabId == tabs[0].id) { + getActiveTab().then((tab) => { + if (tabId === tab.id) { restartAlarm(tabId); } }); @@ -52,7 +55,7 @@ function restartAlarm(tabId) { browser.alarms.clearAll(); let gettingTab = browser.tabs.get(tabId); gettingTab.then((tab) => { - if (tab.url != CATGIFS) { + if (tab.url !== CATGIFS) { browser.alarms.create("", {delayInMinutes: DELAY}); } }); @@ -62,8 +65,8 @@ function restartAlarm(tabId) { On alarm, show the page action. */ browser.alarms.onAlarm.addListener((alarm) => { - getActiveTab().then((tabs) => { - browser.pageAction.show(tabs[0].id); + getActiveTab().then((tab) => { + browser.pageAction.show(tab.id); }); });