diff options
author | sameerasw <[email protected]> | 2025-02-25 13:58:42 +0530 |
---|---|---|
committer | sameerasw <[email protected]> | 2025-02-25 13:58:42 +0530 |
commit | e36e4ce96399db97f80c8833fa6ef2982a249e51 (patch) | |
tree | aad6d10a8adb6a06b8ef6766735942e8c1a15d6c /popup/popup.js | |
parent | 82f7640e9908c0503a879244d2c178b0dd2e6b62 (diff) |
initial zeninternet commit - remote css loading from repository - for github.com only
Diffstat (limited to 'popup/popup.js')
-rw-r--r-- | popup/popup.js | 46 |
1 files changed, 41 insertions, 5 deletions
diff --git a/popup/popup.js b/popup/popup.js index 7824efb..77c5391 100644 --- a/popup/popup.js +++ b/popup/popup.js @@ -1,4 +1,4 @@ -new class ExtensionPopup { +new (class ExtensionPopup { BROWSER_STORAGE_KEY = "transparentZenSettings"; browserStorageSettings = {}; extensionSettingsForm = document.getElementById("extension-settings"); @@ -11,13 +11,19 @@ new class ExtensionPopup { this.bindEvents(); } }); + document + .getElementById("refetch-css") + .addEventListener("click", this.refetchCSS); + document + .getElementById("restart-background") + .addEventListener("click", this.restartBackground); } bindEvents() { this.extensionSettingsForm.querySelectorAll("input").forEach((input) => { input.addEventListener("change", () => { this.saveSettings(); - }) + }); }); } @@ -25,7 +31,9 @@ new class ExtensionPopup { if (this.extensionSettingsForm?.elements) { for (const element of this.extensionSettingsForm.elements) { if (this.browserStorageSettings[element.name]) { - element.checked = JSON.parse(this.browserStorageSettings[element.name]); + element.checked = JSON.parse( + this.browserStorageSettings[element.name] + ); } } } @@ -43,9 +51,37 @@ new class ExtensionPopup { this.browserStorageSettings[element.name] = element.checked; } - browser.storage.local.set({[this.BROWSER_STORAGE_KEY]: this.browserStorageSettings}); + browser.storage.local.set({ + [this.BROWSER_STORAGE_KEY]: this.browserStorageSettings, + }); browser.runtime.sendMessage({ action: "updateSettings" }); console.info("Settings saved", this.browserStorageSettings); } } -}
\ No newline at end of file + + async refetchCSS() { + try { + const response = await fetch( + "https://sameerasw.github.io/my-internet/github.com.css", + { + headers: { + 'Cache-Control': 'no-cache' + } + } + ); + if (!response.ok) throw new Error("Failed to fetch CSS"); + const cssText = await response.text(); + await browser.storage.local.set({ githubCSS: cssText }); + await browser.storage.sync.set({ githubCSS: cssText }); + browser.runtime.sendMessage({ action: "updateCSS" }); + console.info("CSS refetched and updated from GitHub." + cssText); + } catch (error) { + console.error("Error refetching CSS:", error); + } + } + + async restartBackground() { + browser.runtime.sendMessage({ action: "restartBackground" }); + console.info("Background script restart requested."); + } +})();
\ No newline at end of file |