forked from hlcolani/privasmart
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
121 lines (113 loc) · 4.08 KB
/
content.js
File metadata and controls
121 lines (113 loc) · 4.08 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
116
117
118
119
120
121
console.log("starting content script");
let bodyText = document.body.textContent.toLowerCase();
bodyText = bodyText.replace(/[\n\r]/g, '');
console.log(bodyText.trim());
const expr = /((\bi\b)|(\byou\b)).*((\bagree\b)|(\bunderstand\b)|(\backnowledge\b)).*((\bterms\b)|(\bprivacy policy\b))/;
if (bodyText.search(expr) !== -1) {
// bodyText.includes("agree") && (bodyText.includes("terms") || bodyText.includes("privacy policy")
// document.getElementById("password") || document.getElementById("pass") || document.getElementById("psw") || document.getElementById("new-password")
let matches = bodyText.match(expr)
for (let m in matches) {
// console.log(matches[m]);
}
console.log("site has terms of service or privacy policy");
injectHTML();
}
else{
console.log(document.readyState);
console.log("DOM not loaded yet?");
}
function getQuestion(){
var a = $.getJSON("https://tosdr.org/api/1/service/" + gethost() + ".json", function(result) {
var str = JSON.stringify(result);
var obj = JSON.parse(str);
console.log(obj.pointsData);
var points = Object.keys(obj.pointsData);
console.log("Generating question");
if(Math.random() < 0.5) {
// ask a correct question
console.log("asking question");
askQuestion(obj.pointsData[points[points.length * Math.random() << 0]].tosdr.case, true);
}
else {
var topics = Object.keys(allCases);
var topic = topics[topics.length * Math.random() << 0];
var tc = allCases[topic][allCases[topic].length * Math.random() << 0].name;
var same = true;
while (same) {
same = false
topic = topics[topics.length * Math.random() << 0];
tc = allCases[topic][allCases[topic].length * Math.random() << 0].name;
for (c in points) {
if (tc == obj.pointsData[c]) {
same == true;
}
}
}
console.log("asking question");
askQuestion(tc, false);
}
});
}
function injectHTML(){
$.getJSON("https://tosdr.org/api/1/service/" + gethost() + ".json", function(result) {
console.log("injecting html");
$.get(chrome.extension.getURL('/popup.html'), function(data) {
$(data).appendTo('body');
console.log("html injection complete");
// Or if you're using jQuery 1.8+:
// $($.parseHTML(data)).appendTo('body');
getQuestion();
});
});
}
function askQuestion(questionStr, correct){
let caseMessage = document.getElementById("caseMessage");
caseMessage.innerHTML = questionStr;
if(correct)
{
document.getElementById("trueButton").addEventListener("click", correctAns);
document.getElementById("falseButton").addEventListener("click", incorrectAns);
}
else
{
document.getElementById("trueButton").addEventListener("click", incorrectAns);
document.getElementById("falseButton").addEventListener("click", correctAns);
}
}
function correctAns()
{
console.log("correct answer");
document.getElementById("caseMessage").style.textAlign = "center";
document.getElementById("caseMessage").innerHTML = "Correct!";
document.getElementById("privasmartContent").style.backgroundColor = "rgb(67, 239, 95)";
document.getElementById("closeButton").style.backgroundColor = "rgb(67, 239, 95)";
setTimeout(function(){}, 2000);
closePrivasmart();
}
function incorrectAns()
{
console.log("incorrect answer");
let elem = document.getElementById("buttonDiv");
elem.parentNode.removeChild(elem);
document.getElementById("caseMessage").style.textAlign = "center";
let arr = window.location.host.split(".");
document.getElementById("caseMessage").innerHTML = "Wrong! <a href='https://tosdr.org/#" + arr[arr.length - 2] + "'>Click here</a> to learn more.";
document.getElementById("privasmartContent").style.backgroundColor = "rgb(188, 23, 0)";
document.getElementById("closeButton").style.backgroundColor = "rgb(188, 23, 0)";
document.getElementById("PrivasmartContainer").style.color = "rgb(255, 255, 255)";
}
function closePrivasmart()
{
console.log("close container");
let elem = document.getElementById("PrivasmartContainer");
elem.classList.add('fadeOut');
setTimeout(function(){
elem.parentNode.removeChild(elem);
}, 1000);
}
function gethost(){
var url = window.location.host
var arr = url.split(".");
return arr[arr.length - 2]
}