-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathoptions.js
More file actions
84 lines (74 loc) · 2.24 KB
/
options.js
File metadata and controls
84 lines (74 loc) · 2.24 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
'use strict';
import { i18n } from './browser/i18n.js';
import { storage } from './browser/storage.js';
import { createShortcutInput } from './utils/shortcut.js';
const { shortcutReverse: lastShortcutReverse, shortcutClear: lastShortcutClear } = await storage.local.getAsync([
'shortcutReverse',
'shortcutClear',
]);
document.title = i18n.getMessage('appOptions');
document.querySelectorAll('[data-locale]').forEach(elem => {
elem.innerText = i18n.getMessage(elem.dataset.locale);
});
document.getElementById('version').innerText = chrome.runtime.getManifest().version;
document.getElementById('author').innerText = chrome.runtime.getManifest().author;
document.getElementById('sourceCode').href = chrome.runtime.getManifest().homepage_url;
const _shortcutsEl = document.getElementById('shortcuts');
const shortcutLocale = {
buttonLabel: i18n.getMessage('shortcutEdit'),
placeholderEmpty: i18n.getMessage('shortcutNotSet'),
placeholderFocus: i18n.getMessage('shortcutEnter'),
errorModifierRequired: i18n.getMessage('shortcutErrorModifierRequired'),
errorLetterRequired: i18n.getMessage('shortcutErrorLetterRequired'),
};
const shortcutFeatures = {
allowFKeys: true,
allowNumpad: true,
allowArrows: true,
};
_addShortcut(
createShortcutInput(
i18n.getMessage('clear'),
lastShortcutClear,
async e => {
await storage.local.setAsync({
shortcutClear: e.shortcut,
shortcutClearUserDefined: true,
});
},
shortcutLocale,
shortcutFeatures,
),
);
_addShortcut(
createShortcutInput(
i18n.getMessage('reverseTranslation'),
lastShortcutReverse,
async e => {
await storage.local.setAsync({
shortcutReverse: e.shortcut,
shortcutReverseUserDefined: true,
});
},
shortcutLocale,
shortcutFeatures,
),
);
/** @type {HTMLElement} */
const _resetSettings = document.getElementById('resetSettings');
_resetSettings.addEventListener(
'click',
async () => {
if (confirm(i18n.getMessage('troubleshootingResetSettingsQuestion'))) {
await storage.local.clearAsync();
}
},
{ passive: true },
);
/**
* @param {HTMLElement} element
*/
function _addShortcut(element) {
element.classList.add('row', 'shortcut-row');
_shortcutsEl.appendChild(element);
}