From bbeae845b702727f0ffaf3e49c85ed9bc0f971ab Mon Sep 17 00:00:00 2001 From: sameerasw Date: Wed, 5 Mar 2025 17:55:45 +0530 Subject: Wildcards for forcing theme on unthemed websites --- background.js | 17 +++++++++-------- inject-css.js | 6 +++++- manifest.json | 2 +- popup/popup.html | 9 ++++++++- popup/popup.js | 21 +++++++++++++++++++-- 5 files changed, 42 insertions(+), 13 deletions(-) diff --git a/background.js b/background.js index affef80..472f42b 100644 --- a/background.js +++ b/background.js @@ -12,14 +12,15 @@ async function applyCSSToTab(tab) { if (globalSettings.enableStyling === false) return; const data = await browser.storage.local.get("styles"); - const cssFileName = Object.keys(data.styles?.website || {}).find((key) => { - const siteName = key.replace(".css", ""); - if (siteName.startsWith("+")) { - const baseSiteName = siteName.slice(1); - return hostname.endsWith(baseSiteName); - } - return hostname === siteName || hostname === `www.${siteName}`; - }); + const cssFileName = + Object.keys(data.styles?.website || {}).find((key) => { + const siteName = key.replace(".css", ""); + if (siteName.startsWith("+")) { + const baseSiteName = siteName.slice(1); + return hostname.endsWith(baseSiteName); + } + return hostname === siteName || hostname === `www.${siteName}`; + }) || (globalSettings.forceStyling ? "example.com.css" : null); if (!cssFileName) return; diff --git a/inject-css.js b/inject-css.js index 3246255..88ddacc 100644 --- a/inject-css.js +++ b/inject-css.js @@ -19,7 +19,7 @@ if (logging) console.log("inject-css.js script loaded"); const currentUrl = window.location.hostname; if (logging) console.log("Current URL hostname", currentUrl); - const cssFileName = Object.keys(data.styles?.website || {}).find((key) => { + let cssFileName = Object.keys(data.styles?.website || {}).find((key) => { const siteName = key.replace(".css", ""); if (siteName.startsWith("+")) { const baseSiteName = siteName.slice(1); @@ -28,6 +28,10 @@ if (logging) console.log("inject-css.js script loaded"); return currentUrl === siteName || currentUrl === `www.${siteName}`; }); + if (!cssFileName && settings.transparentZenSettings?.forceStyling) { + cssFileName = "example.com.css"; + } + if (!cssFileName) { if (logging) console.log("No CSS file found for current site"); return; diff --git a/manifest.json b/manifest.json index 4859cc7..2749856 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "Zen Internet", - "version": "1.3.3", + "version": "1.4.0", "description": "Inject custom css from my repository in real time", "browser_specific_settings": { "gecko": { diff --git a/popup/popup.html b/popup/popup.html index 1dda5cd..4848306 100644 --- a/popup/popup.html +++ b/popup/popup.html @@ -57,10 +57,17 @@ Auto Update Styles +
+ + Force Styling +
- +