summaryrefslogtreecommitdiff
path: root/inject-css.js
blob: b7c89fe3023c342e0e27872a866116f6e343b03e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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?.website || {}).find((key) =>
        currentUrl.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) {
          let style = document.createElement("style");
          style.textContent = combinedCSS;
          document.head.appendChild(style);
          console.log(`Injected custom CSS for ${currentUrl}`);
        }
      }
    });
  }
});