blob: 64d1badb1a80be17a87b34ce6e0f3b96d0f46012 [file] [log] [blame]
avm999638e030612020-08-20 02:54:17 +02001var savedSuccessfullyTimeout = null;
2
avm99963cbea3142019-03-28 00:48:15 +01003function save() {
avm99963122dc9b2019-03-30 18:44:18 +01004 var options = defaultOptions;
5
avm99963b69eb3d2020-08-20 02:03:44 +02006 Object.keys(options).forEach(function(opt) {
avm99963adf90862020-04-12 13:27:45 +02007 if (deprecatedOptions.includes(opt)) return;
avm99963b69eb3d2020-08-20 02:03:44 +02008 options[opt] = document.querySelector('#' + opt).checked || false;
avm99963122dc9b2019-03-30 18:44:18 +01009 });
10
11 chrome.storage.sync.set(options, function() {
avm99963cbea3142019-03-28 00:48:15 +010012 window.close();
avm999638e030612020-08-20 02:54:17 +020013
14 // In browsers like Firefox window.close is not supported:
15 if (savedSuccessfullyTimeout !== null)
16 window.clearTimeout(savedSuccessfullyTimeout);
17
18 document.getElementById('save-indicator').innerText =
19 '✓ ' + chrome.i18n.getMessage('options_saved');
20 savedSuccessfullyTimeout = window.setTimeout(_ => {
21 document.getElementById('save-indicator').innerText = '';
22 }, 3699);
avm99963cbea3142019-03-28 00:48:15 +010023 });
24}
25
avm99963a3d1ef32019-03-30 23:33:29 +010026function i18n() {
avm99963b69eb3d2020-08-20 02:03:44 +020027 document.querySelectorAll('[data-i18n]')
28 .forEach(
29 el => el.innerHTML = chrome.i18n.getMessage(
30 'options_' + el.getAttribute('data-i18n')));
avm99963a3d1ef32019-03-30 23:33:29 +010031}
32
avm999636d9c5fe2019-06-04 00:35:53 +020033function thread() {
avm99963b69eb3d2020-08-20 02:03:44 +020034 if (document.querySelector('#thread').checked &&
35 document.querySelector('#threadall').checked) {
36 document.querySelector('#' + (this.id == 'thread' ? 'threadall' : 'thread'))
37 .checked = false;
avm999636d9c5fe2019-06-04 00:35:53 +020038 }
39}
40
avm99963b69eb3d2020-08-20 02:03:44 +020041window.addEventListener('load', function() {
avm99963a3d1ef32019-03-30 23:33:29 +010042 i18n();
43
avm99963cbea3142019-03-28 00:48:15 +010044 chrome.storage.sync.get(null, function(items) {
avm99963001c07c2019-03-30 18:47:02 +010045 items = cleanUpOptions(items);
avm99963cbea3142019-03-28 00:48:15 +010046
avm99963122dc9b2019-03-30 18:44:18 +010047 Object.keys(defaultOptions).forEach(function(opt) {
avm99963adf90862020-04-12 13:27:45 +020048 if (items[opt] === true && !deprecatedOptions.includes(opt)) {
avm99963b69eb3d2020-08-20 02:03:44 +020049 document.querySelector('#' + opt).checked = true;
avm99963122dc9b2019-03-30 18:44:18 +010050 }
51 });
avm99963cbea3142019-03-28 00:48:15 +010052
avm99963b69eb3d2020-08-20 02:03:44 +020053 ['thread', 'threadall'].forEach(
54 el => document.querySelector('#' + el).addEventListener(
55 'change', thread));
56 document.querySelector('#save').addEventListener('click', save);
avm99963cbea3142019-03-28 00:48:15 +010057 });
58});