forked from hpaolini/tinyFilter-chrome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsite.js
94 lines (81 loc) · 2.82 KB
/
site.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
85
86
87
88
89
90
91
92
93
94
/*
Copyright:
Copyright (C) 2013 Hunter Paolini <me@hpaolini.com>
License:
This file is part of tinyFilter.
tinyFilter is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
tinyFilter is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with tinyFilter; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*todo:
temporary access
*/
var tinyFilter = {
doc: document,
detection: false,
temp: [],
scan_site: function(exam, list){
var l = list.length, that = this;
var address = this.doc.location.href;
while(l--){
var found = address.indexOf(list[l]);
if(found!==-1){
if(exam===1){
window.stop(); //rember, this loads on document_start
that.action("Detected: \"" + list[l] + "\" in the address.");
}
that.detection = true;
return;
}
}
},
start: function(){
if(!this.loaded){
chrome.extension.sendRequest({name: "getPreferences"},
function(response){
tinyFilter.init(response);
tinyFilter.start();
});
return;
}
if(this.prefs.content_filter.enabled){
this.scan_site(0, this.prefs.content_filter.trust.sites);
if(!this.detection){
if(this.prefs.content_filter.advanced.stop_all){
window.stop();
this.action("Reason: \"Stop all traffic\" is enabled.");
this.detection = true;
return;
}
this.scan_site(1, this.prefs.content_filter.block.sites);
}
}
},
action: function(reason){
//better to block the page ASAP than waiting to redirect
this.doc.documentElement.innerHTML = "<body><div id='tf_block' style='font:12px/17px Arial, sans-serif;border:1px solid #D2DBED;border-bottom-left-radius:6px 6px;border-top-left-radius:6px 6px;border-bottom-right-radius:6px 6px;border-top-right-radius:6px 6px;background-color:#F3F7FC;margin:30px auto;padding:7px 10px;width:80%;'><b>"+this.prefs.content_filter.advanced.warning+"</b></div></body>";
if(this.prefs.content_filter.advanced.reason){
this.doc.getElementById("tf_block").innerHTML += "<br/>"+unescape(reason);
}
if(this.prefs.content_filter.advanced.redirect){
chrome.extension.sendRequest({name: "redirectPage"});
}
},
init: function(response){
this.prefs = response;
this.loaded = true;
}
};
chrome.extension.sendRequest({name: "getPreferences"},
function(response){
tinyFilter.init(response);
tinyFilter.start();
});