-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
115 lines (103 loc) · 3.3 KB
/
content.js
File metadata and controls
115 lines (103 loc) · 3.3 KB
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
// content.js
//alert("Hello from your Chrome extension!")
//var firstHref = $("a[href^='http']").eq(0).attr("img");
var srcList = $('img').get();
console.log(srcList);
var badwords = ["lingerie", "sexy", "nude", "pantie", "underwear", "erotic",
"blood", "horror", "offense",
"liquor", "alcohol", "wine"];
var badDict = {};
for (var i=0; i<badwords.length; i++) {
badDict[badwords[i]] = true;
}
if (srcList.length==1){
if(sendToClarifi(srcList[0].src)){
//srcList[0].src = "https://38.media.tumblr.com/tumblr_ldbj01lZiP1qe0eclo1_500.gif";
$('body').append('<img style="-webkit-user-select: none" src="https://38.media.tumblr.com/tumblr_ldbj01lZiP1qe0eclo1_500.gif">');
$('img').attr('src',"https://38.media.tumblr.com/tumblr_ldbj01lZiP1qe0eclo1_500.gif");
console.log(srcList[0].src);
}
}
function sendToClarifi(link){
var isProfaneVar = false;
//alert("send to clarifi"+link);
//alert("https://api.clarifai.com/v1/tag/?url=" + link+'&access_token=OYr34p8u15BmBQhSwNUJozU9jvijF0');
$.ajax({
type: "GET",
url: "https://api.clarifai.com/v1/tag/?url=" + link+'&access_token=7RrbcxdQkZduFcfi5KwmmDKZxzOYVC',
success: function(data){
//alert("success: "+data.results[0].result.tag.classes);
if (isProfane(data.results[0].result.tag.classes)=='true'){
//alert("there");
console.log("PROFANE");
console.log(link);
isProfaneVar = 'true';
//return 'true';
}
else{
//alert("furr");
}
},
dataType: "json",
cache: false,
async: false
});
console.log(isProfaneVar);
return isProfaneVar;
}
function isProfane(tagList) {
count = 0;
for (i=0;i<tagList.length;i++){
//alert(tagList[i]+" "+badDict[tagList[i]]);
if (badDict[tagList[i]]){
//alert("condition is met");
//alert(tagList[i]);
count += 1;
if (count >= 1)
return 'true';
}
}
return 'false';
}
//---------------------------------------------------------
/*
chrome.webRequest.onBeforeSendHeaders.addListener(
function(details) {
var referer = ""; var accept = ""; var host ="";
for (var i = 0; i < details.requestHeaders.length; ++i) {
if (details.requestHeaders[i].name === 'Accept') {
accept = details.requestHeaders[i].value;
}else if (details.requestHeaders[i].name === 'Referer') {
referer = details.requestHeaders[i].value;
}
}
//alert(referer.split('/')[2]+" "+details.url.split('/')[2]);
if(accept.indexOf("text/html")!=-1 && referer.split('/')[2]!=details.url.split('/')[2]){
//alert("in header");
loadTxtFile(function (text) {
badwords = text.split('\n');
for (var i=0; i<badwords.length; i++) {
badDict[badwords[i]] = true;
}
//alert(badDict);
});
}
return {requestHeaders: details.requestHeaders};
},
{urls: ["<all_urls>"]},
["blocking", "requestHeaders"]);
function loadTxtFile(callback) {
var rawFile = new XMLHttpRequest();
//rawFile.overrideMimeType("application/txt");
rawFile.open("GET", "https://raw.githubusercontent.com/ShashwathKumar/WebSanitizer/master/bad-words.txt", false);
rawFile.onreadystatechange = function ()
{
if(rawFile.readyState == 4 && rawFile.status == "200")
{
var text = rawFile.responseText;
callback(rawFile.responseText);
}
}
rawFile.send(null);
}
*/