diff options
author | sameerasw <[email protected]> | 2025-02-26 00:16:29 +0530 |
---|---|---|
committer | sameerasw <[email protected]> | 2025-02-26 00:16:29 +0530 |
commit | 2e79ce31b430b256fcdda0dd55a7ef1fdca5426a (patch) | |
tree | 43412b440ec5dc6c48b101fe8e6a6e922c20fd47 /inject-css.js | |
parent | 7d297b23975ede17fa465ebf0139ee1d274837f8 (diff) |
switched from css fetching to the styles.json
Diffstat (limited to 'inject-css.js')
-rw-r--r-- | inject-css.js | 42 |
1 files changed, 18 insertions, 24 deletions
diff --git a/inject-css.js b/inject-css.js index 50e7c7f..6b3aaf8 100644 --- a/inject-css.js +++ b/inject-css.js @@ -1,27 +1,21 @@ -browser.storage.sync.get("transparentZenSettings").then((settings) => { +browser.storage.local.get("transparentZenSettings").then((settings) => { if (settings.transparentZenSettings?.enableStyling) { - fetch(browser.runtime.getURL("mapper.json")) - .then((response) => response.json()) - .then((mapping) => { - const currentUrl = window.location.hostname; - const matchedKey = Object.keys(mapping).find((key) => - currentUrl.includes(key) - ); - const cssFileName = mapping[matchedKey]; - if ( - cssFileName && - settings.transparentZenSettings.websiteSettings?.[matchedKey] !== - false - ) { - browser.storage.sync.get(cssFileName).then((data) => { - if (data[cssFileName]) { - let style = document.createElement("style"); - style.textContent = data[cssFileName]; - document.head.appendChild(style); - console.log(`Injected custom CSS for ${currentUrl}`); - } - }); - } - }); + browser.storage.local.get("styles").then((data) => { + const currentUrl = window.location.hostname; + const cssFileName = Object.keys(data.styles).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}`); + } + }); } }); |