From 9e8de1c7b8ab58b12924cedfb7284af58f5b8181 Mon Sep 17 00:00:00 2001 From: sameerasw Date: Thu, 27 Feb 2025 22:00:35 +0530 Subject: disabled style update on switching tabs --- background.js | 14 +++++++------- inject-css.js | 21 +++++++++++++++++++- popup/popup.html | 4 ++-- popup/popup.js | 59 -------------------------------------------------------- 4 files changed, 29 insertions(+), 69 deletions(-) diff --git a/background.js b/background.js index cd2769a..0cf6b1b 100644 --- a/background.js +++ b/background.js @@ -99,16 +99,16 @@ browser.storage.local.get("transparentZenSettings").then((settings) => { }); browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { - if (logging) console.log("onUpdated called with", tabId, changeInfo, tab); + // if (logging) console.log("onUpdated called with", tabId, changeInfo, tab); // Apply CSS when a tab is updated if (changeInfo.status === "complete") { applyCSSToTab(tab); } }); -browser.tabs.onActivated.addListener(async (activeInfo) => { - if (logging) console.log("onActivated called with", activeInfo); - // Apply CSS when a tab is activated - const tab = await browser.tabs.get(activeInfo.tabId); - applyCSSToTab(tab); -}); +// browser.tabs.onActivated.addListener(async (activeInfo) => { +// if (logging) console.log("onActivated called with", activeInfo); +// // Apply CSS when a tab is activated +// const tab = await browser.tabs.get(activeInfo.tabId); +// applyCSSToTab(tab); +// }); diff --git a/inject-css.js b/inject-css.js index de2715e..db19b3d 100644 --- a/inject-css.js +++ b/inject-css.js @@ -1,7 +1,19 @@ +let logging = true; + +if (logging) console.log("inject-css.js script loaded"); + browser.storage.local.get("transparentZenSettings").then((settings) => { + if (logging) console.log("Settings loaded", settings); + if (settings.transparentZenSettings?.enableStyling) { + if (logging) console.log("Styling is enabled"); + browser.storage.local.get("styles").then((data) => { + if (logging) console.log("Styles data loaded", data); + const currentUrl = window.location.hostname; + if (logging) console.log("Current URL hostname", currentUrl); + const cssFileName = Object.keys(data.styles?.website || {}).find( (key) => { const siteName = key.replace(".css", ""); @@ -10,6 +22,9 @@ browser.storage.local.get("transparentZenSettings").then((settings) => { ); if (cssFileName) { + if (logging) + console.log("CSS file found for current site", cssFileName); + const features = data.styles.website[cssFileName]; const featureSettings = settings.transparentZenSettings.featureSettings?.[cssFileName] || {}; @@ -25,9 +40,13 @@ browser.storage.local.get("transparentZenSettings").then((settings) => { let style = document.createElement("style"); style.textContent = combinedCSS; document.head.appendChild(style); - console.log(`Injected custom CSS for ${currentUrl}`); + if (logging) console.log(`Injected custom CSS for ${currentUrl}`); } + } else { + if (logging) console.log("No CSS file found for current site"); } }); + } else { + if (logging) console.log("Styling is disabled"); } }); diff --git a/popup/popup.html b/popup/popup.html index b53ed87..4c20a90 100644 --- a/popup/popup.html +++ b/popup/popup.html @@ -36,13 +36,13 @@ -
+