-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
57 lines (47 loc) · 1.55 KB
/
index.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
const list = [
{ id: 'zhihuAtag', text: 'replace zhihu a tag' },
{ id: 'steamAtag', text: 'replace steam a tag' },
{ id: 'juejinAtag', text: 'replace juejin a tag' },
{ id: 'csdnAtag', text: 'replace csdn a tag' },
{ id: 'zhihuModal', text: 'remove zhihu login modal' },
{ id: 'csdnModal', text: 'remove csdn login modal' },
{ id: 'twitterModal', text: 'remove twitter login modal' },
{ id: 'reposCreateTime', text: 'display repository create time' },
];
const content = document.createElement('div');
function updateStorage(id) {
return function () {
chrome.storage.local.set({ [id]: this.checked });
};
}
function createSwitch(id, text, value) {
const div = document.createElement('div');
const label = document.createElement('label');
const input = document.createElement('input');
const span1 = document.createElement('span');
const span2 = document.createElement('span');
div.className = 'wrapper';
label.className = 'switch';
input.type = 'checkbox';
if (value === undefined) {
input.checked = false;
} else {
input.checked = value;
}
span1.textContent = text + ':';
span2.className = 'slider';
input.onclick = updateStorage(id);
label.appendChild(input);
label.appendChild(span2);
div.appendChild(span1);
div.appendChild(label);
return div;
}
list.forEach(function (obj) {
chrome.storage.local.get(obj.id, (data) => {
content.appendChild(createSwitch(obj.id, obj.text, data[obj.id]));
});
});
window.addEventListener('DOMContentLoaded', function () {
document.body.appendChild(content);
});