-
Notifications
You must be signed in to change notification settings - Fork 11
/
options.js
84 lines (74 loc) · 2.24 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
var gBlacklist = null
function getblockurl(index, item) {
var id = 'blockurl_'+index
var dellink = "del_"+index
var divstr = '<div class="blockurl">'+
'<span class="urlstr">'+item+'</span>'+
'<span class="delete">'+
'<a href="#" class="dellink" id="'+dellink+'">Delete</a>'+
'</span></div>'
return divstr
}
$('body').on('click', 'a.dellink', function() {
var id=$(this).attr('id')
var numId=id.split('_')[1]
numId = +numId
var url = gBlacklist[numId]
gBlacklist.splice(numId, 1)
saveBlacklist(gBlacklist, "Removed '"+url+"' from blacklist.")
return false
});
function loadBlacklist()
{
console.log('loadBlacklist called.');
$('#blacklist').text('');
chrome.storage.sync.get('blacklist', function (storageMap) {
$('div#loading').hide(0);
if (storageMap.hasOwnProperty('blacklist') ){
gBlacklist = storageMap['blacklist']
$.each(storageMap['blacklist'], function(index, item) {
$("#blacklist").append(getblockurl(index, item))
});
if (storageMap['blacklist'].length == 0) {
$('div#emptynotice').show(0);
} else {
$('div#emptynotice').hide(0);
}
} else {
$('div#emptynotice').show(0);
}
});
}
$('#blockform').submit(function() {
var url = $('input#blockurl').val();
console.log(url);
if (url.length > 0) {
$('input#blockurl').val('');
chrome.storage.sync.get('blacklist', function (storageMap) {
var blacklist = [];
if (storageMap.hasOwnProperty('blacklist') ){
blacklist = storageMap['blacklist'];
}
blacklist.push(url);
saveBlacklist(blacklist, 'Added \''+url+'\' to blacklist.');
});
} else {
alert('Empty URL.')
}
return false
});
function setStatus(text) {
$('#statusarea').text(text);
}
$('#clear').click(function() {
saveBlacklist([],'Blacklist cleared.');
});
function saveBlacklist(blacklist, message)
{
gBlacklist=blacklist
chrome.storage.sync.set({'blacklist':blacklist},function(){
setStatus(message);
loadBlacklist();
});
}
loadBlacklist();