summaryrefslogtreecommitdiff
path: root/inject-css.js
blob: c889e18629706b096a2cd2675e9521c409874e03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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) {
          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}`);
            }
          });
        }
      });
  }
});