aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/permissions.ts
blob: e55b197fea27f632c53ff2e72789e884cbee460d (plain)
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
import Config from "./config";
import Utils from "./utils";
import { localizeHtmlPage } from "./maze-utils/setup";
const utils = new Utils();

// This is needed, if Config is not imported before Utils, things break.
// Probably due to cyclic dependencies
Config.config;

if (document.readyState === "complete") {
    init();
} else {
    document.addEventListener("DOMContentLoaded", init);
}

async function init() {
    localizeHtmlPage();

    const acceptButton = document.getElementById("acceptPermissionButton");
    acceptButton.addEventListener("click", () => {
        utils.applyInvidiousPermissions(Config.config.supportInvidious).then((enabled) => {
            Config.config.supportInvidious = enabled;

            if (enabled) {
                alert(chrome.i18n.getMessage("permissionRequestSuccess"));
                window.close();
            } else {
                alert(chrome.i18n.getMessage("permissionRequestFailed"));
            }
        })
    });
}