-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.html
164 lines (130 loc) · 3.73 KB
/
background.html
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<script>
var tabIds = new Array();
var blackListHash = new Array();
chrome.tabs.onCreated.addListener( function(tab) {
visitingUrl( tab );
});
chrome.tabs.onUpdated.addListener( function( tabId, changeInfo, tab ) {
visitingUrl( tab );
});
chrome.tabs.onSelectionChanged.addListener(function(tabId, info) {
chrome.tabs.get(tabId, function(tab){
checkForBlackList( getSiteRoot(tab.url), tab.url);
});
});
function visitingUrl( tab )
{
if(tab.url && (tab.url.indexOf("chrome://") != 0) && (tab.url.indexOf("chrome-extension://") != 0)){
console.log( "visiting " + tab.id + " " + tab.url);
if(!tabIds[tab.id]){
tabIds[tab.id] = new Array();
}
tabIds[tab.id].push( tab.url );
checkForBlackList( getSiteRoot(tab.url), tab.url);
}
}
function checkForBlackList(root, url)
{
if( blackListHash[ root ] ){
console.log("this site is blacklisted!");
chrome.browserAction.setIcon( { 'path':'icons/black_list_icon.png' } );
console.log("deleting: " + url);
chrome.history.deleteUrl( {'url':url} );
}
else{
chrome.browserAction.setIcon( { 'path':'icons/default_icon.png' } );
}
}
function deleteAll()
{
console.log("deleting all");
chrome.history.deleteAll(function(){
});
}
function deleteTabHistory()
{
chrome.tabs.getSelected(null, function( tab ){
console.log("deleting tab " + tab.id);
var hist = tabIds[tab.id];
for(x in hist ){
console.log( "deleting url " + hist[x] );
chrome.history.deleteUrl( {'url': hist[x]} );
}
});
}
function deleteLast(time)
{
console.log("deleting last " + time);
var currTime = new Date().getTime();
var hourAgo = currTime - time;
chrome.history.deleteRange( { 'startTime':hourAgo, 'endTime':currTime }, function(){} );
}
function deleteCurrentSiteRoot()
{
console.log("deleting root");
chrome.tabs.getSelected(null, function(tab) {
var root = getSiteRoot( tab.url );
chrome.history.search( { 'text':'', 'maxResults':9999999 }, function(result) {
for(x in result){
if( result[x].url.indexOf(root) >= 0){
console.log("deleting " + result[x].url);
chrome.history.deleteUrl( {"url":result[x].url} );
}
}
});
});
}
function getSiteRoot(url)
{
var index = url.indexOf("://");
if( index >= 0){
url = url.substring(index + 3);
}
index = url.indexOf("www.");
if(index >= 0){
url = url.substring(index + 4);
}
index = url.indexOf('/');
if(index >= 0){
url = url.substring(0, index);
}
return url;
}
function addToBlacklist(root, url)
{
console.log("adding to blacklist");
if(!localStorage['blackList'] || localStorage['blackList']==''){
localStorage['blackList'] = root;
}
else{
localStorage['blackList'] += ',' + root;
}
blackListHash[root] = true;
checkForBlackList( root, url );
}
function removeFromBlackList(root, url)
{
console.log("remove from blacklist");
var blarray = localStorage['blackList'].split(',');
var newblarray = new Array();
for(x in blarray)
if( blarray[x] != root)
newblarray.push( blarray[x] );
localStorage['blackList'] = newblarray.join(',');
updateBlackListHash();
checkForBlackList( root, url );
}
function updateBlackListHash()
{
blackListHash = new Array();
if(!localStorage['blackList'] || localStorage['blackList']==''){
return;
}
var blarray = localStorage['blackList'].split(',');
for(x in blarray){
blackListHash[blarray[x]] = true;
console.log('adding to blhash: ' + blarray[x]);
}
}
document.onload = updateBlackListHash();
</script>