-
Notifications
You must be signed in to change notification settings - Fork 2
/
lazarette.js
126 lines (100 loc) · 4.03 KB
/
lazarette.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
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
var replaced = false;
function deleteElement() {
console.log("Deleted");
//Finds the Comment-box (Must click on twice since it has attribute hidden (weird))
var commentField = document.getElementById("simple-box");
//console.log(testi)
//This function calls the replace button once comment fields is clicked on (twice :/)
commentField.addEventListener("click", function() {
if (!replaced) {
replaceSubmit();
replaced = true;
}
});
//data.parentNode.removeChild(data);
//document.getElementById("info").outerHTML = "farts";
//document.getElementById("subscribe-button").outerHTML = "";
//$("#labelAndInputContainer").after("<tp-yt-paper-button>Element was there</tp-yt-paper-button>").appendTo("body");
}
//Replaces the Submit Button for the fake submit
async function replaceSubmit() {
await new Promise(r => setTimeout(r, 100));
//replaces the Button NEEDS CSS OR SMTH CAUSE IT'S DOGWATER
$("#submit-button").after("<tp-yt-paper-button id='replaceButton' style='background: green; font-size: 15px; color: white'>Lazaretto!</tp-yt-paper-button>").appendTo("body");
console.log("DOING THIS SHIT");
replaceButton = document.getElementById("replaceButton");
replaceButton.addEventListener("click", function(event) {
commentAnalysis();
replaceButton.innerHTML = "AI is Processing...";
event.preventDefault();
});
// inject the warning modal
$.get(chrome.runtime.getURL('/modal.html'), function(data) {
$($.parseHTML(data)).appendTo('body');
// replace the warning message
// move the OG comment button here
$("#place-for-button").append($("#submit-button"));
document.getElementById("submit-button").addEventListener("click", commented);
// listen to go back
var modal = document.getElementById("myModal");
document.getElementById("reviewButton").addEventListener("click", goBack);
});
}
async function commentAnalysis() {
var comment = document.getElementById("input-container");
// retreive comment text and trim it of all surrounding whitespace
var text = comment.textContent.trim();
// Locks the Scroll Wheel
// document.getElementsByTagName('body')[0].style.overflow = 'hidden';
// has to await since ML might take time to get results
var isToxic = await getToxicityLevel(text);
var message = "";
// assign a warning message
var rev_btn = document.getElementById("reviewButton");
var sub_btn = document.getElementById("submit-button");
if (!isToxic) {
message = "Comment looks good! Go ahead and post it.";
rev_btn.style.display = "none";
sub_btn.style.display = "block";
}
else {
message = "Woah! This comment might be offensive, so be sure to edit it before you post.";
rev_btn.style.display = "block";
sub_btn.style.display = "none";
}
var modal = document.getElementById("myModal");
modal.style.display = "block";
document.getElementById("warning-message").innerHTML = message;
}
function commented() {
var modal = document.getElementById("myModal");
modal.style.display = "none";
replaceButton = document.getElementById("replaceButton");
replaceButton.innerHTML = "Another comment?";
}
function goBack() {
var modal = document.getElementById("myModal");
modal.style.display = "none";
replaceButton = document.getElementById("replaceButton");
replaceButton.innerHTML = "Be nicer this time!";
}
//waits for comment box
waitForElementToDisplay("#comment-dialog",function(){deleteElement();},1000,9000);
function waitForElementToDisplay(selector, callback, checkFrequencyInMs, timeoutInMs) {
var startTimeInMs = Date.now();
(function loopSearch() {
if (document.querySelector(selector) != null) {
callback();
return;
}
else {
setTimeout(function () {
if (timeoutInMs && Date.now() - startTimeInMs > timeoutInMs)
return;
loopSearch();
}, checkFrequencyInMs);
}
})();
}
//:(
console.log("Farts7000");