summaryrefslogtreecommitdiff
path: root/inject-css.js
blob: 50e7c7f6ddcc64aaeebb5aa6e77a11fb32ac0804 (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
browser.storage.sync.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}`);
            }
          });
        }
      });
  }
});