-
Notifications
You must be signed in to change notification settings - Fork 15
/
cssreloader.options.js
112 lines (88 loc) · 3.47 KB
/
cssreloader.options.js
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
(function () {
var domShortcutInput, allSettings;
function initialize() {
document.addEventListener("DOMContentLoaded", onDomReady, false);
}
function handleKeys(key, isAlt, isControl, isShift) {
if (isControl) {
addVisualKey('Ctrl');
}
if (isShift) {
addVisualKey('Shift');
}
if (isAlt) {
addVisualKey('Alt');
}
if ( (/^U+(.*)$/.test(key) ) ) {
var key = String.fromCharCode(key.replace('U+', '0x'));
addVisualKey(key);
} else {
addVisualKey(key);
}
}
function onDomReady() {
domShortcutInput = document.querySelector('.shortcut input');
document.querySelector('button').addEventListener("click", onButtonClicked, false);
domShortcutInput.addEventListener("focus", onShortcutFocus, false);
browser.runtime.sendMessage({ 'action': 'getSettings' }).then(function(settings) {
allSettings = settings;
handleKeys(allSettings.keyIdentifier, allSettings.altKeySelected, allSettings.controlKeySelected, allSettings.shiftKeySelected);
document.getElementById("domain-blacklist").value = allSettings.blacklist.toString();
});
}
function onShortcutFocus() {
document.addEventListener("keydown", onDocumentKeyDown, false);
domShortcutInput.addEventListener("blur", onShortcutBlur, false);
}
function onShortcutBlur() {
document.removeEventListener("keydown", onDocumentKeyDown, false);
}
function addVisualKey(key) {
var domShortcutKeys = document.querySelector('.shortcut .keys');
var domKeys = document.querySelectorAll('.shortcut .keys div');
var domNewContainer = document.createElement("div");
var domNewKbd = document.createElement("kbd");
domNewKbd.textContent = key;
if (domKeys.length > 0) {
domNewContainer.appendChild(document.createTextNode(' + '));
}
domNewContainer.appendChild(domNewKbd);
domShortcutKeys.appendChild(domNewContainer);
}
function onDocumentKeyDown(e) {
var domKeys = document.querySelector('.shortcut .keys');
if (domKeys.hasChildNodes()) {
while (domKeys.childNodes.length >= 1) {
domKeys.removeChild(domKeys.firstChild);
}
}
allSettings = {
"keyIdentifier" : e.key,
"altKeySelected" : e.altKey,
"controlKeySelected" : e.ctrlKey,
"shiftKeySelected" : e.shiftKey
};
handleKeys(e.key, e.altKey, e.ctrlKey, e.shiftKey);
}
//gets the list of domains from the textarea, formats into a proper array
function getBlacklistDomains() {
var domainElement = document.getElementById("domain-blacklist");
var domains = domainElement.value.trim();
if (domains.length > 0) {
domains = domains.split(",");
}
return domains;
}
// Saves options to localStorage.
function onButtonClicked() {
allSettings.blacklist = getBlacklistDomains();
browser.runtime.sendMessage({'action' : 'saveSettings', 'data' : allSettings});
// Update status to let user know options were saved.
var status = document.querySelector('.status');
status.innerHTML = "Options Saved...";
setTimeout(function() {
status.innerHTML = "";
}, 1500);
}
initialize();
})();