summaryrefslogtreecommitdiff
path: root/background.js
diff options
context:
space:
mode:
authorsameerasw <[email protected]>2025-05-24 04:51:10 +0530
committersameerasw <[email protected]>2025-05-24 04:51:13 +0530
commit176a8a76245ed60d347d445441e1b75a31f16461 (patch)
treeddc4af7995289839aef00bc69d7b7eb369febbeb /background.js
parent508d5d551fc3fe07e9f2c36119322b7cba72b290 (diff)
fixed themes applying upon fetching
Diffstat (limited to 'background.js')
-rw-r--r--background.js46
1 files changed, 42 insertions, 4 deletions
diff --git a/background.js b/background.js
index 179fc23..95daea2 100644
--- a/background.js
+++ b/background.js
@@ -321,6 +321,10 @@ browser.runtime.onMessage.addListener(async (message, sender) => {
} else if (message.action === "disableAutoUpdate") {
stopAutoUpdate();
return true;
+ } else if (message.action === "reapplyStylesAfterFetch") {
+ // Triggered after fetching new styles from popup
+ await reapplyStylesToAllTabs();
+ return true;
}
// Update the icon when the content script reports ready
@@ -875,19 +879,53 @@ async function refetchCSS() {
});
console.info("Initialized default settings during first fetch");
} else {
- // Just update the lastFetchedTime
- await browser.storage.local.set({ lastFetchedTime: Date.now() });
+ // Just update the lastFetchedTime while preserving other settings
+ const updatedSettings = {
+ ...settingsData[BROWSER_STORAGE_KEY],
+ lastFetchedTime: Date.now(),
+ };
+ await browser.storage.local.set({
+ [BROWSER_STORAGE_KEY]: updatedSettings,
+ });
}
console.info(`All styles refetched and updated from ${repositoryUrl}`);
- // Preload the new styles
- preloadStyles();
+ // Clear CSS cache to ensure we use fresh styles
+ cssCache.clear();
+
+ // Preload the new styles while keeping site-specific settings
+ await preloadStyles();
+
+ // Reapply CSS to all active tabs
+ await reapplyStylesToAllTabs();
} catch (error) {
console.error("Error refetching styles:", error);
}
}
+// New function to reapply styles to all active tabs
+async function reapplyStylesToAllTabs() {
+ try {
+ // Clear styling state cache to ensure fresh evaluation
+ stylingStateCache.clear();
+
+ // Get all active tabs
+ const tabs = await browser.tabs.query({});
+
+ // Reapply CSS to each tab
+ for (const tab of tabs) {
+ if (tab.url && tab.url.startsWith("http")) {
+ applyCSSToTab(tab);
+ }
+ }
+
+ if (logging) console.log("Reapplied styles to all active tabs after fetch");
+ } catch (error) {
+ console.error("Error reapplying styles to tabs:", error);
+ }
+}
+
// Create a directory to store CSS files
async function initializeExtension() {
// Check and initialize default settings