-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
options.js
88 lines (76 loc) · 2.03 KB
/
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
/*!
* Copyright (c) 2016-2024 Lauri Rooden
* https://www.litejs.com/MIT-LICENSE.txt
*/
var themes = {
"": {
font: "13px/15px Menlo,monospace",
color: "#000",
bg: "#fff",
info: "#ccc",
infoHover: "#333;text-shadow: 1px 1px 3px #999",
numCol: "#333",
numBg: "#ccc",
string: "#293",
number: "#10c",
bool: "#10c",
null: "#10c",
property: "#66d",
error: "#f12"
},
"firefox-dark": {
font: "13px/15px Menlo,monospace",
color: "#fff",
bg: "#181d20",
info: "#888",
infoHover: "#ccc",
numCol: "#ccc",
numBg: "#333",
string: "#df80ff",
number: "#70bf53",
bool: "#70bf53",
null: "#747573",
property: "#46afe3",
error: "#ed2655"
}
}
// In Safari async storage.get in previous script completes before this script get executed
// In Chrome and Firefox this script executes before storage.get completes
if (opts) init()
else next = init
function init() {
theme.value = themes[opts.theme] ? opts.theme : "custom"
updateForm(opts)
}
function updateForm(items) {
if (items) Object.keys(defOpts).forEach(function(key) {
if (key !== "theme" && items[key] != null) {
if (form1[key].type === "checkbox") form1[key].checked = items[key]
else form1[key].value = items[key]
}
})
custom.style.display = theme.value === "custom" ? "block" : "none"
dateOpt.style.display = showDate.value !== "never" ? "block" : "none"
}
function saveOptions(e) {
e.preventDefault()
storage.set(Object.keys(defOpts).reduce(function(map, key) {
map[key] = form1[key][form1[key].type === "checkbox" ? "checked" : "value"]
return map
}, {}))
window.close()
}
form1.addEventListener("submit", saveOptions)
theme.addEventListener("change", function() {
updateForm(themes[theme.value])
})
showDate.addEventListener("change", function() {
updateForm()
})
if (location.search !== "?p") pre.style.display = "none"
pre.addEventListener("click", function(e) {
var el = e.target || e.srcElement
if (el.nodeType == 3) el = el.parentNode
var prom = chrome.runtime.sendMessage({op: el.name}, close)
if (prom) prom.then(close, close)
})