diff options
author | sameerasw <[email protected]> | 2025-03-05 17:55:45 +0530 |
---|---|---|
committer | sameerasw <[email protected]> | 2025-03-05 17:55:45 +0530 |
commit | bbeae845b702727f0ffaf3e49c85ed9bc0f971ab (patch) | |
tree | 67552b6f6fd88568862fdf61dc6bb50060f60fc6 /popup/popup.js | |
parent | 34e74fda832756db278b43fa9b0e0cfb99430f8a (diff) |
Wildcards for forcing theme on unthemed websites
Diffstat (limited to 'popup/popup.js')
-rw-r--r-- | popup/popup.js | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/popup/popup.js b/popup/popup.js index 1882573..23f18fb 100644 --- a/popup/popup.js +++ b/popup/popup.js @@ -11,6 +11,7 @@ new (class ExtensionPopup { currentSiteHostname = ""; autoUpdateSwitch = document.getElementById("auto-update"); lastFetchedTime = document.getElementById("last-fetched-time"); + forceStylingSwitch = document.getElementById("force-styling"); constructor() { if (logging) console.log("Initializing ExtensionPopup"); @@ -28,6 +29,10 @@ new (class ExtensionPopup { "change", this.saveSettings.bind(this) ); + this.forceStylingSwitch.addEventListener( + "change", + this.saveSettings.bind(this) + ); // Setup auto-update and display last fetched time this.setupAutoUpdate(); @@ -74,6 +79,7 @@ new (class ExtensionPopup { this.enableStylingSwitch.checked = this.globalSettings.enableStyling ?? true; this.autoUpdateSwitch.checked = this.globalSettings.autoUpdate ?? false; + this.forceStylingSwitch.checked = this.globalSettings.forceStyling ?? false; this.loadCurrentSiteFeatures(); } @@ -87,6 +93,7 @@ new (class ExtensionPopup { enableStyling: true, autoUpdate: false, lastFetchedTime: null, + forceStyling: false, }; // Load site-specific settings if on a specific site @@ -103,6 +110,7 @@ new (class ExtensionPopup { // Save global settings this.globalSettings.enableStyling = this.enableStylingSwitch.checked; this.globalSettings.autoUpdate = this.autoUpdateSwitch.checked; + this.globalSettings.forceStyling = this.forceStylingSwitch.checked; browser.storage.local .set({ @@ -150,11 +158,17 @@ new (class ExtensionPopup { this.currentSiteFeatures.innerHTML = ""; - const currentSiteKey = Object.keys(styles).find((site) => + let currentSiteKey = Object.keys(styles).find((site) => this.isCurrentSite(site.replace(".css", "")) ); - if (!currentSiteKey) { + if (!currentSiteKey && this.globalSettings.forceStyling) { + currentSiteKey = Object.keys(styles).find( + (site) => site === "example.com.css" + ); + } + + if (!currentSiteKey || currentSiteKey === "example.com.css") { const requestThemeButton = document.createElement("button"); requestThemeButton.className = "action-button primary"; requestThemeButton.innerHTML = `Request Theme for ${this.currentSiteHostname}`; @@ -164,6 +178,9 @@ new (class ExtensionPopup { }); this.currentSiteFeatures.appendChild(requestThemeButton); + } + + if (!currentSiteKey) { return; } |