aboutsummaryrefslogtreecommitdiff
path: root/html/default_blocking_policy.js
blob: b6458f321982b18c2d4be00a620617a7f3034235 (about) (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
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
 * This file is part of Haketilo.
 *
 * Function: Logic for the dialog of default policy selection.
 *
 * Copyright (C) 2021 Wojtek Kosior
 * Redistribution terms are gathered in the `copyright' file.
 */

/*
 * IMPORTS_START
 * IMPORT by_id
 * IMPORT light_storage
 * IMPORT observables
 * IMPORTS_END
 */

/*
 * Used with `default_blocking_policy.html' to allow user to choose whether to
 * block scripts globally or not.
 */

const blocking_policy_span = by_id("blocking_policy_span");
const current_policy_span = by_id("current_policy_span");
const toggle_policy_but = by_id("toggle_policy_but");

let policy_observable;

const update_policy =
      allowed => current_policy_span.textContent = allowed ? "allow" : "block";
const toggle_policy =
      () => light_storage.set_var("default_allow", !policy_observable.value);

async function init_default_policy_dialog()
{
    policy_observable = await light_storage.observe_var("default_allow");
    update_policy(policy_observable.value);
    observables.subscribe(policy_observable, update_policy);

    toggle_policy_but.addEventListener("click", toggle_policy);
    blocking_policy_span.classList.remove("hide");
}

/*
 * EXPORTS_START
 * EXPORT init_default_policy_dialog
 * EXPORTS_END
 */