-
Notifications
You must be signed in to change notification settings - Fork 101
/
popup.js
54 lines (45 loc) · 1.17 KB
/
popup.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
function generateHtml(url) {
return `
<div class="item">
<span class="url">${url}</span>
<span class="del">✕</span>
</div>
`
}
var key = 'y_request_allow_urls';
var urls = chrome.runtime.sendMessage({action:'get', name: key}, function(urls){
var urlDom = $('#urls');
try{
urls = JSON.parse(urls);
}catch(e){
urls = null;
}
if(!urls || Object.keys(urls).length === 0){
urls = { '*': true};
chrome.runtime.sendMessage({action:'set', name: key, value: JSON.stringify(urls)})
}
for (var url in urls) {
urlDom.append(generateHtml(url));
}
$('#add .submit').bind('click', function () {
var val = $('#add input').val()
if (val) urls[val] = true;
chrome.runtime.sendMessage({
action:'set',
name: key,
value: JSON.stringify(urls)
})
urlDom.append(generateHtml(val))
})
urlDom.on('click', '.del', function (event) {
var p = event.target.parentNode;
var url = $(p).find('.url').text();
delete urls[url]
chrome.runtime.sendMessage({
action:'set',
name: key,
value: JSON.stringify(urls)
})
p.parentNode.removeChild(p)
})
});