From e36e4ce96399db97f80c8833fa6ef2982a249e51 Mon Sep 17 00:00:00 2001 From: sameerasw Date: Tue, 25 Feb 2025 13:58:42 +0530 Subject: initial zeninternet commit - remote css loading from repository - for github.com only --- popup/popup.js | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) (limited to 'popup/popup.js') 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 -- cgit v1.2.3