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 | |
parent | 82f7640e9908c0503a879244d2c178b0dd2e6b62 (diff) |
initial zeninternet commit - remote css loading from repository - for github.com only
Diffstat (limited to 'popup')
-rw-r--r-- | popup/popup.html | 5 | ||||
-rw-r--r-- | popup/popup.js | 46 |
2 files changed, 46 insertions, 5 deletions
diff --git a/popup/popup.html b/popup/popup.html index 7fdf257..f27e98d 100644 --- a/popup/popup.html +++ b/popup/popup.html @@ -1,9 +1,11 @@ <!DOCTYPE html> <html> + <head> <meta charset="UTF-8"> <link rel="stylesheet" href="popup.css"> </head> + <body> <div class="container"> <div id="extension-header"> @@ -16,6 +18,8 @@ Enable Transparency (no effect yet) </label> </form> + <button id="refetch-css">Refetch CSS</button> + <button id="restart-background">Restart Background Script (optional)</button> <div id="extension-description"> <p>Transparent Zen is a Zen Browser extension that makes supported websites transparent.</p> <p>Transparent Zen is open source and everyone can contribute their custom styles to support more websites.</p> @@ -25,4 +29,5 @@ </div> <script src="popup.js"></script> </body> + </html>
\ No newline at end of file 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 |