Total Complexity | 12 |
Complexity/F | 1.2 |
Lines of Code | 48 |
Function Count | 10 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 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}` |
||
|
|||
48 | }); |
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.