about summary refs log tree commit diff stats
path: root/src/assets/javascripts/general.js
blob: 9e490c4a4c45112f2a0fcc5a1a595909af93e941 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"use strict"
window.browser = window.browser || window.chrome

let exceptions

function isException(url) {
	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
}

function init() {
	return new Promise(resolve => {
		browser.storage.local.get("options", r => {
			if (r.options) exceptions = r.options.exceptions
			resolve()
		})
	})
}

init()
browser.storage.onChanged.addListener(init)

async function initDefaults() {
	return new Promise(resolve =>
		browser.storage.local.set(
			{
				options: {
					exceptions: {
						url: [],
						regex: [],
					},
					theme: "detect",
					popupServices: ["youtube", "twitter", "instagram", "tiktok", "imgur", "reddit", "quora", "translate", "maps"],
					autoRedirect: false,
					network: "clearnet",
					networkFallback: true,
					latencyThreshold: 1000,
				},
			},
			() => resolve()
		)
	)
}

export default {
	isException,
	initDefaults,
}