summaryrefslogtreecommitdiff
path: root/background.js
diff options
context:
space:
mode:
authorsameerasw <[email protected]>2025-02-26 17:55:03 +0530
committersameerasw <[email protected]>2025-02-26 17:55:03 +0530
commit099957c1dcbc81a6238c1e6c6a842d6756e6eb8a (patch)
tree7100ab2979fa66104fc3b84f048c67b71cad9dbb /background.js
parentfc4ec05cf405e44febc15cf1c37a08c7a7bbcfb4 (diff)
Re-added background.js to fix the background tab themeing and youtube
Diffstat (limited to 'background.js')
-rw-r--r--background.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/background.js b/background.js
new file mode 100644
index 0000000..357e5a0
--- /dev/null
+++ b/background.js
@@ -0,0 +1,50 @@
+function applyCSSToTab(tab) {
+ const url = new URL(tab.url);
+ const hostname = url.hostname;
+
+ browser.storage.local.get("transparentZenSettings").then((settings) => {
+ if (settings.transparentZenSettings?.enableStyling) {
+ browser.storage.local.get("styles").then((data) => {
+ const cssFileName = Object.keys(data.styles?.website || {}).find(
+ (key) => hostname.includes(key.replace(".css", ""))
+ );
+
+ if (cssFileName) {
+ const features = data.styles.website[cssFileName];
+ const featureSettings =
+ settings.transparentZenSettings.featureSettings?.[cssFileName] ||
+ {};
+
+ let combinedCSS = "";
+ for (const [feature, css] of Object.entries(features)) {
+ if (featureSettings[feature] !== false) {
+ combinedCSS += css + "\n";
+ }
+ }
+
+ if (combinedCSS) {
+ browser.tabs
+ .insertCSS(tab.id, { code: combinedCSS })
+ .then(() => {
+ console.log(`Injected custom CSS for ${hostname}`);
+ })
+ .catch((error) => {
+ console.error(`Error applying CSS to ${hostname}:`, error);
+ });
+ }
+ }
+ });
+ }
+ });
+}
+
+browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
+ if (changeInfo.status === "complete") {
+ applyCSSToTab(tab);
+ }
+});
+
+browser.tabs.onActivated.addListener(async (activeInfo) => {
+ const tab = await browser.tabs.get(activeInfo.tabId);
+ applyCSSToTab(tab);
+});