2022-07-26 23:28:50 +02:00
|
|
|
"use strict"
|
|
|
|
window.browser = window.browser || window.chrome
|
2022-02-12 20:28:36 +01:00
|
|
|
|
2022-09-25 16:10:38 +02:00
|
|
|
let exceptions
|
|
|
|
|
2022-02-12 18:40:36 +01:00
|
|
|
function isException(url) {
|
2022-07-26 23:28:50 +02:00
|
|
|
for (const item of exceptions.url) if (item == `${url.protocol}//${url.host}`) return true
|
|
|
|
for (const item of exceptions.regex) if (new RegExp(item).test(url.href)) return true
|
|
|
|
return false
|
2022-03-02 22:46:29 +01:00
|
|
|
}
|
|
|
|
|
2022-05-27 05:20:07 +02:00
|
|
|
function init() {
|
2022-09-25 16:10:38 +02:00
|
|
|
return new Promise(resolve => {
|
2022-09-28 21:18:32 +02:00
|
|
|
browser.storage.local.get("options", r => {
|
2022-09-29 19:32:03 +02:00
|
|
|
if (r.options) exceptions = r.options.exceptions
|
2022-09-25 16:10:38 +02:00
|
|
|
resolve()
|
|
|
|
})
|
2022-07-26 23:28:50 +02:00
|
|
|
})
|
2022-03-09 19:05:31 +01:00
|
|
|
}
|
|
|
|
|
2022-07-26 23:28:50 +02:00
|
|
|
init()
|
2022-05-27 05:20:07 +02:00
|
|
|
browser.storage.onChanged.addListener(init)
|
|
|
|
|
|
|
|
async function initDefaults() {
|
2022-07-26 23:28:50 +02:00
|
|
|
return new Promise(resolve =>
|
|
|
|
browser.storage.local.set(
|
|
|
|
{
|
2022-09-27 21:59:25 +02:00
|
|
|
options: {
|
|
|
|
exceptions: {
|
|
|
|
url: [],
|
|
|
|
regex: [],
|
|
|
|
},
|
2022-09-28 21:18:32 +02:00
|
|
|
theme: "detect",
|
2022-09-27 21:59:25 +02:00
|
|
|
popupServices: ["youtube", "twitter", "instagram", "tiktok", "imgur", "reddit", "quora", "translate", "maps"],
|
|
|
|
network: "clearnet",
|
|
|
|
networkFallback: true,
|
2022-07-26 23:28:50 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
() => resolve()
|
|
|
|
)
|
|
|
|
)
|
2022-05-27 05:20:07 +02:00
|
|
|
}
|
2022-05-21 15:38:28 +02:00
|
|
|
|
2022-02-12 18:40:36 +01:00
|
|
|
export default {
|
2022-07-26 23:28:50 +02:00
|
|
|
isException,
|
|
|
|
initDefaults,
|
2022-04-09 11:19:13 +02:00
|
|
|
}
|