diff options
author | sameerasw <[email protected]> | 2025-02-26 11:21:58 +0530 |
---|---|---|
committer | sameerasw <[email protected]> | 2025-02-26 11:22:59 +0530 |
commit | 93747ebef68299c4442df4f907ea836c6e078e57 (patch) | |
tree | 6540db8ad6d11ad9aa7e6d1406c4192d96364909 /inject-css.js | |
parent | 02c13d747c626903a2a6b45b2d62e706506b4b6f (diff) |
Featrue specific toggles for styles and new json format
Diffstat (limited to 'inject-css.js')
-rw-r--r-- | inject-css.js | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/inject-css.js b/inject-css.js index 6b3aaf8..b7c89fe 100644 --- a/inject-css.js +++ b/inject-css.js @@ -2,19 +2,27 @@ browser.storage.local.get("transparentZenSettings").then((settings) => { if (settings.transparentZenSettings?.enableStyling) { browser.storage.local.get("styles").then((data) => { const currentUrl = window.location.hostname; - const cssFileName = Object.keys(data.styles).find((key) => + const cssFileName = Object.keys(data.styles?.website || {}).find((key) => currentUrl.includes(key.replace(".css", "")) ); - if ( - cssFileName && - settings.transparentZenSettings.websiteSettings?.[ - cssFileName.replace(".css", "") - ] !== false - ) { - let style = document.createElement("style"); - style.textContent = data.styles[cssFileName]; - document.head.appendChild(style); - console.log(`Injected custom CSS for ${currentUrl}`); + + 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) { + let style = document.createElement("style"); + style.textContent = combinedCSS; + document.head.appendChild(style); + console.log(`Injected custom CSS for ${currentUrl}`); + } } }); } |