Total Complexity | 5 |
Complexity/F | 1.67 |
Lines of Code | 51 |
Function Count | 3 |
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 | 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 | }); |