From 3c72a208788fa9e12bc80e99bae1780e5efcf6a3 Mon Sep 17 00:00:00 2001 From: Maks Snegov Date: Mon, 29 Apr 2024 22:34:59 -0700 Subject: [PATCH] Update currentDate in popup to "-" if date not found --- manifest.json | 2 +- popup/popup.js | 20 +++++++++----------- scripts/content.js | 1 + 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/manifest.json b/manifest.json index 2345c0f..46b27d6 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "not-a-rescheduler", - "version": "0.0.6", + "version": "0.0.7", "permissions": [ "storage", "tabs", "activeTab", "notifications", "declarativeContent" ], "content_scripts": [ { diff --git a/popup/popup.js b/popup/popup.js index a34132e..3bf0da8 100644 --- a/popup/popup.js +++ b/popup/popup.js @@ -148,21 +148,19 @@ function smoothTextChange(element, newText) { consCfg[c].autoBook = e.target.checked; await chrome.storage.local.set({ "cfg_consulates": consCfg }); }); + // update current & best dates chrome.storage.onChanged.addListener((changes, area) => { if (changes.ctx_consulates) { - const newConsulates = changes.ctx_consulates.newValue; + let newCurrentDate = changes.ctx_consulates.newValue[c].currentDate || "-"; + let newBestDate = changes.ctx_consulates.newValue[c].bestDate || "-"; - if (newConsulates[c].currentDate) { - let el = document.getElementById(`currentDate-${cId}`); - if (el && el.innerText != newConsulates[c].currentDate) - smoothTextChange(el, newConsulates[c].currentDate); - } - if (newConsulates[c].bestDate) { - let el = document.getElementById(`bestDate-${cId}`); - if (el && el.innerText != newConsulates[c].bestDate) - smoothTextChange(el, newConsulates[c].bestDate); - } + let el = document.getElementById(`currentDate-${cId}`); + if (el && el.innerText != newCurrentDate) + smoothTextChange(el, newCurrentDate); + el = document.getElementById(`bestDate-${cId}`); + if (el && el.innerText != newBestDate) + smoothTextChange(el, newBestDate); } }); } diff --git a/scripts/content.js b/scripts/content.js index b4ecc44..c4edb66 100644 --- a/scripts/content.js +++ b/scripts/content.js @@ -625,6 +625,7 @@ async function runner() { if (!(currentHourUTC === 23 && currentMinuteUTC < 5)) { ctx.consulates[c].nextCheckAt = getFutureDate(SOFT_BAN_TIMEOUT, getJitter(cfg.frequency)); } + ctx.consulates[c].currentDate = null; continue; }