-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.js
49 lines (48 loc) · 1.53 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
window.addEventListener('DOMContentLoaded', () => {
const qs = s => document.querySelector(s);
const getList = () => {
try {
return JSON.parse(localStorage.getItem('custom_list') || '');
} catch (error) {
return [{ width: 1280, height: 720 }, { width: 1560, height: 720 }];
}
}
const showSetting = () => {
const list = getList();
let str = "";
for (const one of list) {
str += one.width + "|";
str += one.height;
if (one.title) str += "|" + one.title;
str += "\n";
}
qs("#setting").value = str;
}
showSetting();
let saving = false;
qs("#save").onclick = () => {
if (saving) return;
saving = true;
const list = [];
let str = qs("#setting").value + "";
let linearr = str.split("\n")
for (const line of linearr) {
if (!line.trim()) continue;
let [w, h, t] = line.split("|").map(s => s.trim());
w = Math.floor(Number(w));
h = Math.floor(Number(h));
if (w > 0 && h > 0) {
let one = { width: w, height: h };
if (t) one.title = t;
list.push(one);
}
}
localStorage.setItem('custom_list', JSON.stringify(list));
showSetting();
qs("#success").style.display = "inline";
setTimeout(() => {
qs("#success").style.display = "none";
saving = false;
}, 1000);
}
});