-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
52 lines (47 loc) · 1.36 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
//debug URL: chrome-extension://hnajbpkopgmkoaebdhallmmkdmanbilo/options.html
let data;
// Saves options to chrome.storage.sync.
function save_options() {
const channelName = document.getElementById('channel').value;
const tag = document.getElementById('tags').value;
data.keep.push({
channel: channelName,
tag: tag
});
chrome.storage.sync.set(data, () => {
//data saved
});
restore_options();
}
function update_tag_table() {
//document.getElementById('keepTags').innerHTML = JSON.stringify(data.keep);
const tableBody = document.querySelectorAll('#all-tags tbody')[0];
tableBody.innerHTML = '';
for (tag of data.keep) {
const tr = document.createElement('tr');
const markup = `
<td>
${tag.channel}
</td>
<td>
${tag.tag}
</td>
`;
tr.innerHTML = markup;
tableBody.appendChild(tr);
}
}
function restore_options() {
chrome.storage.sync.get({
keep: []
}, items => {
data = items;
update_tag_table();
});
}
document.addEventListener('DOMContentLoaded', restore_options);
document.getElementById('add').addEventListener('click', save_options);
document.getElementById('clear').addEventListener('click', () => {
chrome.storage.sync.clear();
restore_options();
});