This repository has been archived by the owner on Nov 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
options.js
156 lines (107 loc) · 5.13 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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
function debug(param) {
if (globalDebugMode) {
console.log(param)
}
}
function form_update() {
var defApply = document.getElementById("default_apply")
var hideSrv = document.getElementById("hidekf")
var preImg = document.getElementById("preview_image")
var rotImg = document.getElementById("rotate_image")
var movRate = document.getElementById("move_ratebutton")
var useRBox = document.getElementById("use_ratebox")
var addSign = document.getElementById("add_signature")
var sText = document.getElementById("signature")
var dlLesson = document.getElementById("download_lesson")
sText.disabled = !addSign.checked
var status = document.getElementById('info')
status.textContent = '当前状态:未保存。'
debug("[Info][options] Update form.")
}
function save_options() {
var storage = {}
storage.enableBgMode = document.getElementById('default_apply').checked
storage.enableHideSrv = document.getElementById('hidekf').checked
storage.enableImagePreview = document.getElementById('preview_image').checked
storage.enableImageRotation = document.getElementById('rotate_image').checked
storage.enableMoveRate = document.getElementById('move_ratebutton').checked
storage.enableRateBox = document.getElementById('use_ratebox').checked
storage.enableSignature = document.getElementById('add_signature').checked
storage.signatureText = document.getElementById('signature').value
storage.enableDownload = document.getElementById('download_lesson').checked
debug(storage)
debug(JSON.stringify(storage))
chrome.storage.sync.set({
"settings": JSON.stringify(storage)
}
, function () {
var status = document.getElementById('info')
status.textContent = '当前状态:已保存。请刷新教学立方网页重新载入以生效。'
})
debug("[Info][options] Save settings.")
}
function reset_options() {
document.getElementById('default_apply').checked = false
document.getElementById("hidekf").checked = false
document.getElementById('preview_image').checked = true
document.getElementById('rotate_image').checked = true
document.getElementById('move_ratebutton').checked = true
document.getElementById('use_ratebox').checked = false
document.getElementById('add_signature').checked = false
document.getElementById('signature').value = "(张三 批改)"
document.getElementById('download_lesson').checked = false
debug("[Info][options] Reset settings.")
form_update()
}
function load_options() {
chrome.storage.sync.get("settings", function (items) {
var globalStorage = {}
if ('{}' === JSON.stringify(items)) {
/* 第一次运行设置 */
debug("[Info][options] First run.")
document.getElementById('title').textContent = "欢迎使用!第一次使用请设置:"
document.getElementById('default_apply').checked = false
document.getElementById("hidekf").checked = false
document.getElementById('preview_image').checked = true
document.getElementById('rotate_image').checked = true
document.getElementById('move_ratebutton').checked = true
document.getElementById('use_ratebox').checked = false
document.getElementById('add_signature').checked = false
document.getElementById('signature').value = "(张三 批改)"
document.getElementById('download_lesson').checked = false
save_options()//强制保存一次默认设置
} else {
globalStorage = JSON.parse(items.settings)
document.getElementById('default_apply').checked = globalStorage.enableBgMode
document.getElementById("hidekf").checked = globalStorage.enableHideSrv
document.getElementById('preview_image').checked = globalStorage.enableImagePreview
document.getElementById('rotate_image').checked = globalStorage.enableImageRotation
document.getElementById('move_ratebutton').checked = globalStorage.enableMoveRate
document.getElementById('use_ratebox').checked = globalStorage.enableRateBox
document.getElementById('add_signature').checked = globalStorage.enableSignature
document.getElementById('signature').value = globalStorage.signatureText
document.getElementById('download_lesson').checked = globalStorage.enableDownload
}
form_update()//异步加载
})
}
var globalDebugMode = true
var defApply = document.getElementById("default_apply")
var hideSrv = document.getElementById("hidekf")
var preImg = document.getElementById("preview_image")
var rotImg = document.getElementById("rotate_image")
var movRate = document.getElementById("move_ratebutton")
var useRBox = document.getElementById("use_ratebox")
var addSign = document.getElementById("add_signature")
var sText = document.getElementById("signature")
var dlLesson = document.getElementById("download_lesson")
document.getElementById('reset').addEventListener('click', function () {
reset_options()
form_update()
})
document.getElementById('save').addEventListener('click', save_options)
document.addEventListener('DOMContentLoaded', load_options)
var all_cbox = document.getElementsByClassName('cbox')
for (let cboxid = 0; cboxid < all_cbox.length; cboxid++) {
all_cbox[cboxid].onclick = form_update
}