src/javascript/settings.ts   A
last analyzed

Complexity

Total Complexity 5
Complexity/F 1.67

Size

Lines of Code 51
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 38
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 5
mnd 2
bc 2
fnc 3
bpm 0.6666
cpm 1.6666
noi 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A settings.ts ➔ storeOptions 0 5 1
A settings.ts ➔ resetOptions 0 7 2
A settings.ts ➔ restoreOptions 0 8 2
1
import { getGlobalStorageProvider } from "./browserApi/storageProvider";
2
import { onReady } from "./utils/helpers";
3
4
const OPTION_SELECTOR = 'input[type="checkbox"';
5
6
function storeOptions() {
7
    document.querySelectorAll(OPTION_SELECTOR).forEach(optionElement => {
8
        let optionInputElement = optionElement as HTMLInputElement;
9
        getGlobalStorageProvider().setDataAsBoolean(optionInputElement.id, optionInputElement.checked);
10
    });
11
}
12
13
function restoreOptions() {
14
    document.querySelectorAll(OPTION_SELECTOR).forEach(optionElement => {        
15
        let optionInputElement = optionElement as HTMLInputElement;
16
        let defaultValue = optionInputElement.dataset.defaultValue === 'true' ? true : false;
17
18
        getGlobalStorageProvider().getDataAsBoolean(optionInputElement.id, defaultValue, value => {
19
            optionInputElement.checked = value;
20
        });
21
    });
22
}
23
24
function resetOptions() {
25
    document.querySelectorAll(OPTION_SELECTOR).forEach(optionElement => {
26
        let optionInputElement = optionElement as HTMLInputElement;
27
        let defaultValue = optionInputElement.dataset.defaultValue === 'true' ? true : false;
28
29
        optionInputElement.checked = defaultValue;
30
    });
31
}
32
33
onReady(() => {
34
    // register Store Button
35
    document.getElementById('btnSave').addEventListener('click', event => {
36
        event.preventDefault();
37
        storeOptions();
38
    });
39
40
    document.getElementById('btnReset').addEventListener('click', event => {
41
        event.preventDefault();
42
        resetOptions();
43
        storeOptions();
44
    })
45
46
    // try restore options
47
    restoreOptions();
48
49
    // update version label
50
    document.getElementById('version').innerText = `v${chrome.runtime.getManifest().version}`
51
});