summaryrefslogtreecommitdiff
path: root/popup/popup.js
diff options
context:
space:
mode:
authorsameerasw <[email protected]>2025-02-27 11:04:31 +0530
committersameerasw <[email protected]>2025-02-27 11:04:31 +0530
commit4d9e41e4faabe4424636a247815b865b8b6c44d5 (patch)
tree3c58131f85e72969bd6b83824d69482f586e69bb /popup/popup.js
parente3b7b6b485dd94a4b9308d69944320069d69740e (diff)
Added auto fetching and last fetched time.
Diffstat (limited to 'popup/popup.js')
-rw-r--r--popup/popup.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/popup/popup.js b/popup/popup.js
index 86eda9c..a444060 100644
--- a/popup/popup.js
+++ b/popup/popup.js
@@ -6,6 +6,8 @@ new (class ExtensionPopup {
websitesList = document.getElementById("websites-list");
currentSiteFeatures = document.getElementById("current-site-toggles");
currentSiteHostname = "";
+ autoUpdateSwitch = document.getElementById("auto-update");
+ lastFetchedTime = document.getElementById("last-fetched-time");
constructor() {
this.loadSettings().then((settings) => {
@@ -22,6 +24,12 @@ new (class ExtensionPopup {
this.websitesList.classList.toggle("collapsed");
});
+ this.autoUpdateSwitch.addEventListener(
+ "change",
+ this.saveSettings.bind(this)
+ );
+ this.setupAutoUpdate();
+ this.displayLastFetchedTime();
this.setupContentScriptInjection();
this.displayAddonVersion();
}
@@ -61,6 +69,9 @@ new (class ExtensionPopup {
this.enableStylingSwitch.checked =
this.browserStorageSettings.enableStyling;
}
+ if (this.browserStorageSettings.autoUpdate !== undefined) {
+ this.autoUpdateSwitch.checked = this.browserStorageSettings.autoUpdate;
+ }
this.loadCurrentSiteFeatures();
this.loadWebsitesList();
}
@@ -74,6 +85,7 @@ new (class ExtensionPopup {
saveSettings() {
this.browserStorageSettings.enableStyling =
this.enableStylingSwitch.checked;
+ this.browserStorageSettings.autoUpdate = this.autoUpdateSwitch.checked;
const featureSettings = {};
this.currentSiteFeatures
@@ -191,6 +203,7 @@ new (class ExtensionPopup {
if (!response.ok) throw new Error("Failed to fetch styles.json");
const styles = await response.json();
await browser.storage.local.set({ styles });
+ await browser.storage.local.set({ lastFetchedTime: Date.now() });
this.loadCurrentSiteFeatures();
this.loadWebsitesList();
@@ -201,6 +214,7 @@ new (class ExtensionPopup {
this.refetchCSSButton.textContent = "Refetch latest styles";
}, 2000);
console.info("All styles refetched and updated from GitHub." + styles);
+ this.displayLastFetchedTime();
} catch (error) {
this.refetchCSSButton.textContent = "Error!";
setTimeout(() => {
@@ -294,4 +308,22 @@ new (class ExtensionPopup {
"addon-version"
).textContent = `Version: ${version}`;
}
+
+ setupAutoUpdate() {
+ if (this.autoUpdateSwitch.checked) {
+ browser.runtime.sendMessage({ action: "enableAutoUpdate" });
+ } else {
+ browser.runtime.sendMessage({ action: "disableAutoUpdate" });
+ }
+ }
+
+ displayLastFetchedTime() {
+ browser.storage.local.get("lastFetchedTime").then((result) => {
+ if (result.lastFetchedTime) {
+ this.lastFetchedTime.textContent = `Last fetched: ${new Date(
+ result.lastFetchedTime
+ ).toLocaleString()}`;
+ }
+ });
+ }
})();