aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/permissions.ts
blob: 558f0c3f7f198fa4e5e3621048d7a4c292dbecbc (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
33
34
35
import Config from "./config";
import Utils from "./utils";
const utils = new Utils();

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

window.addEventListener('DOMContentLoaded', init);

async function init() {
    utils.localizeHtmlPage();

    const domains = document.location.hash.replace("#", "").split(",");

    const acceptButton = document.getElementById("acceptPermissionButton");
    acceptButton.addEventListener("click", () => {
        chrome.permissions.request({
            origins: utils.getPermissionRegex(domains),
            permissions: []
        }, (granted)  => {
            if (granted) {
                alert(chrome.i18n.getMessage("permissionRequestSuccess"));

                Config.config.ytInfoPermissionGranted = true;

                chrome.tabs.getCurrent((tab) => {
                    chrome.tabs.remove(tab.id);
                });
            } else {
                alert(chrome.i18n.getMessage("permissionRequestFailed"));
            }
        });
    });
}