Project

General

Profile

Download (1.22 KB) Statistics
| Branch: | Tag: | Revision:

haketilo / html / default_blocking_policy.js @ 2bd35bc4

1
/**
2
 * This file is part of Haketilo.
3
 *
4
 * Function: Logic for the dialog of default policy selection.
5
 *
6
 * Copyright (C) 2021 Wojtek Kosior
7
 * Redistribution terms are gathered in the `copyright' file.
8
 */
9

    
10
/*
11
 * IMPORTS_START
12
 * IMPORT by_id
13
 * IMPORT light_storage
14
 * IMPORT observables
15
 * IMPORTS_END
16
 */
17

    
18
/*
19
 * Used with `default_blocking_policy.html' to allow user to choose whether to
20
 * block scripts globally or not.
21
 */
22

    
23
const blocking_policy_span = by_id("blocking_policy_span");
24
const current_policy_span = by_id("current_policy_span");
25
const toggle_policy_but = by_id("toggle_policy_but");
26

    
27
let policy_observable;
28

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

    
34
async function init_default_policy_dialog()
35
{
36
    policy_observable = await light_storage.observe_var("default_allow");
37
    update_policy(policy_observable.value);
38
    observables.subscribe(policy_observable, update_policy);
39

    
40
    toggle_policy_but.addEventListener("click", toggle_policy);
41
    blocking_policy_span.classList.remove("hide");
42
}
43

    
44
/*
45
 * EXPORTS_START
46
 * EXPORT init_default_policy_dialog
47
 * EXPORTS_END
48
 */
(6-6/14)