Skip to content

Commit b8f577f

Browse files
committed
Fixed #3 by allowing files starting with + to have prefixes in the url.
1 parent 35f2ec8 commit b8f577f

File tree

4 files changed

+53
-30
lines changed

4 files changed

+53
-30
lines changed

background.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ async function applyCSSToTab(tab) {
1212
if (globalSettings.enableStyling === false) return;
1313

1414
const data = await browser.storage.local.get("styles");
15-
const cssFileName = Object.keys(data.styles?.website || {}).find(
16-
(key) => {
17-
const siteName = key.replace(".css", "");
18-
return hostname === siteName || hostname === `www.${siteName}`;
15+
const cssFileName = Object.keys(data.styles?.website || {}).find((key) => {
16+
const siteName = key.replace(".css", "");
17+
if (siteName.startsWith("+")) {
18+
const baseSiteName = siteName.slice(1);
19+
return hostname.endsWith(baseSiteName);
1920
}
20-
);
21+
return hostname === siteName || hostname === `www.${siteName}`;
22+
});
2123

2224
if (!cssFileName) return;
2325

inject-css.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ if (logging) console.log("inject-css.js script loaded");
1919
const currentUrl = window.location.hostname;
2020
if (logging) console.log("Current URL hostname", currentUrl);
2121

22-
const cssFileName = Object.keys(data.styles?.website || {}).find(
23-
(key) => {
24-
const siteName = key.replace(".css", "");
25-
return currentUrl === siteName || currentUrl === `www.${siteName}`;
22+
const cssFileName = Object.keys(data.styles?.website || {}).find((key) => {
23+
const siteName = key.replace(".css", "");
24+
if (siteName.startsWith("+")) {
25+
const baseSiteName = siteName.slice(1);
26+
return currentUrl.endsWith(baseSiteName);
2627
}
27-
);
28+
return currentUrl === siteName || currentUrl === `www.${siteName}`;
29+
});
2830

2931
if (!cssFileName) {
3032
if (logging) console.log("No CSS file found for current site");

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 2,
33
"name": "Zen Internet",
4-
"version": "1.3.1",
4+
"version": "1.3.2",
55
"description": "Inject custom css from my repository in real time",
66
"browser_specific_settings": {
77
"gecko": {

popup/popup.js

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,22 @@ new (class ExtensionPopup {
7171
restoreSettings() {
7272
if (logging) console.log("restoreSettings called");
7373
// Restore global settings
74-
this.enableStylingSwitch.checked = this.globalSettings.enableStyling ?? true;
74+
this.enableStylingSwitch.checked =
75+
this.globalSettings.enableStyling ?? true;
7576
this.autoUpdateSwitch.checked = this.globalSettings.autoUpdate ?? false;
7677
this.loadCurrentSiteFeatures();
7778
}
7879

7980
async loadSettings() {
8081
if (logging) console.log("loadSettings called");
8182
// Load global settings
82-
const globalData = await browser.storage.local.get(this.BROWSER_STORAGE_KEY);
83+
const globalData = await browser.storage.local.get(
84+
this.BROWSER_STORAGE_KEY
85+
);
8386
this.globalSettings = globalData[this.BROWSER_STORAGE_KEY] || {
8487
enableStyling: true,
8588
autoUpdate: false,
86-
lastFetchedTime: null
89+
lastFetchedTime: null,
8790
};
8891

8992
// Load site-specific settings if on a specific site
@@ -101,18 +104,20 @@ new (class ExtensionPopup {
101104
this.globalSettings.enableStyling = this.enableStylingSwitch.checked;
102105
this.globalSettings.autoUpdate = this.autoUpdateSwitch.checked;
103106

104-
browser.storage.local.set({
105-
[this.BROWSER_STORAGE_KEY]: this.globalSettings
106-
}).then(() => {
107-
if (logging) console.log("Global settings saved");
108-
this.updateActiveTabStyling();
109-
});
107+
browser.storage.local
108+
.set({
109+
[this.BROWSER_STORAGE_KEY]: this.globalSettings,
110+
})
111+
.then(() => {
112+
if (logging) console.log("Global settings saved");
113+
this.updateActiveTabStyling();
114+
});
110115

111116
// Save site-specific settings
112117
if (this.currentSiteHostname) {
113118
const siteKey = `${this.BROWSER_STORAGE_KEY}.${this.currentSiteHostname}`;
114119
const featureSettings = {};
115-
120+
116121
this.currentSiteFeatures
117122
.querySelectorAll("input[type=checkbox]")
118123
.forEach((checkbox) => {
@@ -121,17 +126,19 @@ new (class ExtensionPopup {
121126
});
122127

123128
this.siteSettings = featureSettings;
124-
browser.storage.local.set({
125-
[siteKey]: featureSettings
126-
}).then(() => {
127-
if (logging) console.log("Site settings saved");
128-
this.updateActiveTabStyling();
129-
});
129+
browser.storage.local
130+
.set({
131+
[siteKey]: featureSettings,
132+
})
133+
.then(() => {
134+
if (logging) console.log("Site settings saved");
135+
this.updateActiveTabStyling();
136+
});
130137
}
131138

132139
console.info("Settings saved", {
133140
global: this.globalSettings,
134-
site: this.siteSettings
141+
site: this.siteSettings,
135142
});
136143
}
137144

@@ -178,7 +185,9 @@ new (class ExtensionPopup {
178185
featureToggle.innerHTML = `
179186
<span class="feature-name">${displayFeatureName}</span>
180187
<label class="toggle-switch">
181-
<input type="checkbox" name="${currentSiteKey}|${feature}" ${isChecked ? "checked" : ""}>
188+
<input type="checkbox" name="${currentSiteKey}|${feature}" ${
189+
isChecked ? "checked" : ""
190+
}>
182191
<span class="slider round"></span>
183192
</label>
184193
`;
@@ -195,6 +204,10 @@ new (class ExtensionPopup {
195204
isCurrentSite(siteName) {
196205
if (logging) console.log("isCurrentSite called with", siteName);
197206
if (!this.currentSiteHostname) return false;
207+
if (siteName.startsWith("+")) {
208+
const baseSiteName = siteName.slice(1);
209+
return this.currentSiteHostname.endsWith(baseSiteName);
210+
}
198211
if (this.currentSiteHostname === siteName) return true;
199212
if (this.currentSiteHostname === `www.${siteName}`) return true;
200213
return false;
@@ -267,7 +280,13 @@ new (class ExtensionPopup {
267280
let siteKey = null;
268281
for (const site of Object.keys(styles)) {
269282
const siteName = site.replace(/\.css$/, "");
270-
if (hostname === siteName || hostname === `www.${siteName}`) {
283+
if (siteName.startsWith("+")) {
284+
const baseSiteName = siteName.slice(1);
285+
if (hostname.endsWith(baseSiteName)) {
286+
siteKey = site;
287+
break;
288+
}
289+
} else if (hostname === siteName || hostname === `www.${siteName}`) {
271290
siteKey = site;
272291
break;
273292
}

0 commit comments

Comments
 (0)