From 176a8a76245ed60d347d445441e1b75a31f16461 Mon Sep 17 00:00:00 2001 From: sameerasw Date: Sat, 24 May 2025 04:51:10 +0530 Subject: fixed themes applying upon fetching --- popup/popup.js | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'popup/popup.js') diff --git a/popup/popup.js b/popup/popup.js index 9b2cd29..a35a8cd 100644 --- a/popup/popup.js +++ b/popup/popup.js @@ -687,6 +687,17 @@ new (class ExtensionPopup { console.log("Fetching styles from:", repositoryUrl); + // Store existing site-specific settings before fetching new styles + const allStorageData = await browser.storage.local.get(null); + const existingSiteSettings = {}; + + // Identify and keep all site-specific settings + for (const [key, value] of Object.entries(allStorageData)) { + if (key.startsWith(this.BROWSER_STORAGE_KEY + ".")) { + existingSiteSettings[key] = value; + } + } + const response = await fetch(repositoryUrl, { headers: { "Cache-Control": "no-cache", @@ -731,12 +742,24 @@ new (class ExtensionPopup { // Update labels this.updateModeLabels(); } else { - // Just update the lastFetchedTime - await browser.storage.local.set({ lastFetchedTime: Date.now() }); + // Just update the lastFetchedTime while preserving other settings + const updatedSettings = { + ...settingsData[this.BROWSER_STORAGE_KEY], + lastFetchedTime: Date.now(), + }; + await browser.storage.local.set({ + [this.BROWSER_STORAGE_KEY]: updatedSettings, + }); } - this.loadCurrentSiteFeatures(); - this.updateActiveTabStyling(); + // Reload the current site features + await this.loadCurrentSiteFeatures(); + + // Notify background script to immediately reapply CSS to active tabs + browser.runtime.sendMessage({ + action: "reapplyStylesAfterFetch", + preserveSettings: true, + }); this.refetchCSSButton.textContent = "Done!"; setTimeout(() => { -- cgit v1.2.3