Passed
Push — develop ( 18945a...910cfa )
by Daniel
01:04 queued 10s
created

settings.js ➔ storeOptions   A

Complexity

Conditions 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
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
        getGlobalStorageProvider().setData(optionElement.id, optionElement.checked);
9
    });
10
}
11
12
function restoreOptions() {
13
    document.querySelectorAll(OPTION_SELECTOR).forEach(optionElement => {
14
        let defaultValue = optionElement.dataset.defaultValue === 'true' ? true : false;
15
16
        getGlobalStorageProvider().getData(optionElement.id, defaultValue, value => {
17
            optionElement.checked = value;
18
        });
19
    });
20
}
21
22
function resetOptions() {
23
    document.querySelectorAll(OPTION_SELECTOR).forEach(optionElement => {
24
        let defaultValue = optionElement.dataset.defaultValue === 'true' ? true : false;
25
26
        optionElement.checked = defaultValue;
27
    });
28
}
29
30
onReady(() => {
31
    // register Store Button
32
    document.getElementById('btnSave').addEventListener('click', event => {
33
        event.preventDefault();
34
        storeOptions();
35
    });
36
37
    document.getElementById('btnReset').addEventListener('click', event => {
38
        event.preventDefault();
39
        resetOptions();
40
        storeOptions();
41
    })
42
43
    // try restore options
44
    restoreOptions();
45
46
    // update version label
47
    document.getElementById('version').innerText = `v${chrome.runtime.getManifest().version}`
0 ignored issues
show
Bug introduced by
The variable chrome seems to be never declared. If this is a global, consider adding a /** global: chrome */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
48
});