-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathoptions.js
More file actions
50 lines (45 loc) · 1.55 KB
/
Copy pathoptions.js
File metadata and controls
50 lines (45 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* Toggle Line Wrap Thunderbird Add-On
*
* Copyright (c) Jan Kiszka, 2020-2023
*
* Authors:
* Jan Kiszka <jan.kiszka@web.de>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
async function initBoolOption(key, defaultValue, selector)
{
let valueObj = await messenger.storage.local.get(key);
let value = valueObj[key];
if (typeof value === "undefined") {
value = defaultValue;
}
document.querySelector(selector).checked = value;
}
function initOptions()
{
initBoolOption("line_wrap", true, "#line-wrap");
initBoolOption("patch_detect", true, "#patch-detect");
initBoolOption("use_alt_w", false, "#use-alt-w");
}
function storeOptions(event)
{
event.preventDefault();
let use_alt_w = document.querySelector("#use-alt-w").checked;
messenger.storage.local.set({
line_wrap: document.querySelector("#line-wrap").checked,
patch_detect: document.querySelector("#patch-detect").checked,
use_alt_w: use_alt_w
});
messenger.commands.update({
name:"toggleLineWrap",
shortcut: use_alt_w ? "Alt+W" : "Ctrl+Shift+W"
});
}
document.addEventListener("DOMContentLoaded", initOptions);
document.querySelector("#line-wrap").addEventListener("change", storeOptions);
document.querySelector("#patch-detect").addEventListener("change", storeOptions);
document.querySelector("#use-alt-w").addEventListener("change", storeOptions);