Fix bug in settings loading
This commit is contained in:
@ -1,16 +1,6 @@
|
|||||||
const SCROBBLE_ENDPOINT = "https://life.lab.unbl.ink/?scrobble_url=";
|
const SCROBBLE_ENDPOINT = "https://life.lab.unbl.ink/?scrobble_url=";
|
||||||
const STOP_ENDPOINT = "https://life.lab.unbl.ink/?action=stop&scrobble_url=";
|
const STOP_ENDPOINT = "https://life.lab.unbl.ink/?action=stop&scrobble_url=";
|
||||||
|
|
||||||
// Default settings
|
|
||||||
// *.google.com
|
|
||||||
// *.annas-archive.org
|
|
||||||
// *.limetorrents.fun
|
|
||||||
// gmail.com
|
|
||||||
// *.duckduckgo.com
|
|
||||||
// *.ebay.com
|
|
||||||
// *.amazon.com
|
|
||||||
// *.boardgamegeek.com
|
|
||||||
// *.chatgpt.com
|
|
||||||
const DEFAULT_SETTINGS = {
|
const DEFAULT_SETTINGS = {
|
||||||
delay: 7,
|
delay: 7,
|
||||||
blacklist: [
|
blacklist: [
|
||||||
@ -21,12 +11,19 @@ const DEFAULT_SETTINGS = {
|
|||||||
"*.chatgpt.com",
|
"*.chatgpt.com",
|
||||||
"*.ebay.com",
|
"*.ebay.com",
|
||||||
"*.amazon.com",
|
"*.amazon.com",
|
||||||
|
"*.merrysky.net",
|
||||||
|
"gemgetter.clearlysharp.com/",
|
||||||
|
"*.boardgamegeek.com",
|
||||||
|
"*.duckduckgo.com",
|
||||||
|
"*.geekgroup.app",
|
||||||
|
"*.local",
|
||||||
|
"*.service",
|
||||||
|
"*.todoist.com",
|
||||||
],
|
],
|
||||||
paused: false,
|
paused: false,
|
||||||
siteDelays: { "readscomisconline.ru": 1 },
|
siteDelays: { "readscomisconline.ru": 1 },
|
||||||
};
|
};
|
||||||
|
|
||||||
// Utility: wildcard match
|
|
||||||
function matchPattern(url, pattern) {
|
function matchPattern(url, pattern) {
|
||||||
if (pattern.startsWith("*.")) {
|
if (pattern.startsWith("*.")) {
|
||||||
const domain = pattern.slice(2);
|
const domain = pattern.slice(2);
|
||||||
|
|||||||
41
options.js
41
options.js
@ -11,6 +11,14 @@ const DEFAULT_SETTINGS = {
|
|||||||
"*.chatgpt.com",
|
"*.chatgpt.com",
|
||||||
"*.ebay.com",
|
"*.ebay.com",
|
||||||
"*.amazon.com",
|
"*.amazon.com",
|
||||||
|
"*.merrysky.net",
|
||||||
|
"gemgetter.clearlysharp.com/",
|
||||||
|
"*.boardgamegeek.com",
|
||||||
|
"*.duckduckgo.com",
|
||||||
|
"*.geekgroup.app",
|
||||||
|
"*.local",
|
||||||
|
"*.service",
|
||||||
|
"*.todoist.com",
|
||||||
],
|
],
|
||||||
paused: false,
|
paused: false,
|
||||||
siteDelays: { "readscomisconline.ru": 1 },
|
siteDelays: { "readscomisconline.ru": 1 },
|
||||||
@ -20,6 +28,12 @@ function restore() {
|
|||||||
browser.storage.local.get(DEFAULT_SETTINGS, (items) => {
|
browser.storage.local.get(DEFAULT_SETTINGS, (items) => {
|
||||||
document.getElementById("delay").value = items.delay;
|
document.getElementById("delay").value = items.delay;
|
||||||
document.getElementById("blacklist").value = items.blacklist.join("\n");
|
document.getElementById("blacklist").value = items.blacklist.join("\n");
|
||||||
|
document.getElementById("scrobbleBaseUrl").value = items.scrobbleBaseUrl;
|
||||||
|
document.getElementById("siteDelays").value = Object.entries(
|
||||||
|
items.siteDelays || {},
|
||||||
|
)
|
||||||
|
.map(([d, s]) => `${d}=${s}`)
|
||||||
|
.join("\n");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,10 +44,27 @@ function save() {
|
|||||||
.value.split("\n")
|
.value.split("\n")
|
||||||
.map((x) => x.trim())
|
.map((x) => x.trim())
|
||||||
.filter(Boolean);
|
.filter(Boolean);
|
||||||
|
const scrobbleBaseUrl = document
|
||||||
|
.getElementById("scrobbleBaseUrl")
|
||||||
|
.value.trim();
|
||||||
|
const siteDelaysLines = document
|
||||||
|
.getElementById("siteDelays")
|
||||||
|
.value.split("\n")
|
||||||
|
.map((l) => l.trim())
|
||||||
|
.filter(Boolean);
|
||||||
|
|
||||||
browser.storage.local.set({ delay, blacklist }, () => {
|
const siteDelays = {};
|
||||||
const status = document.getElementById("status");
|
for (const line of siteDelaysLines) {
|
||||||
status.textContent = "Settings saved.";
|
const [domain, sec] = line.split("=");
|
||||||
setTimeout(() => (status.textContent = ""), 1500);
|
if (domain && sec) siteDelays[domain.trim()] = parseFloat(sec);
|
||||||
});
|
}
|
||||||
|
|
||||||
|
browser.storage.local.set(
|
||||||
|
{ delay, blacklist, scrobbleBaseUrl, siteDelays },
|
||||||
|
() => {
|
||||||
|
const status = document.getElementById("status");
|
||||||
|
status.textContent = "Settings saved.";
|
||||||
|
setTimeout(() => (status.textContent = ""), 1500);
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user