about summary refs log tree commit diff stats
path: root/src/assets/javascripts/general.js
blob: 7b643cfa56e1ba09a8e301e743bbde1cc8e248cf (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"use strict";
window.browser = window.browser || window.chrome;

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;
}

let exceptions;

function init() {
    browser.storage.local.get(
        'exceptions',
        r => {
            exceptions = r.exceptions;
        }
    )
}

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

async function initDefaults() {
    return new Promise(resolve =>
        browser.storage.local.set({
            exceptions: {
                "url": [],
                "regex": [],
            },
            theme: "DEFAULT",
            popupFrontends: [
                "youtube",
                "twitter",
                "instagram",
                "tikTok",
                "imgur",
                "reddit",
                "search",
                "medium",
                "quora",
                "translate",
                "maps",
            ],
            autoRedirect: false,
            firstPartyIsolate: false,
        }, () => resolve())
    )
}

const allPopupFrontends = [
    "youtube",
    "youtubeMusic",
    "twitter",
    "instagram",
    "tikTok",
    "imgur",
    "reddit",
    "search",
    "translate",
    "maps",
    "wikipedia",
    "medium",
    "quora",
    "peertube",
    "lbry",
    "sendTargets"
];

export default {
    isException,
    initDefaults,
    allPopupFrontends,
}