-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.js
102 lines (86 loc) · 2.9 KB
/
script.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
var text, commentsIds = [], hasOldComments = 0;
var managers = ["M0D4", "MuhammadJ", "ahmed_magdy1", "Redhwan", "AIC", "Abdeltwab"];
function getJsonText(){
var f1 = window.document.body.innerText.includes("Elapsed");
var f2 = window.document.body.innerText.includes("Running");
var f3 = window.document.body.innerText.includes("Remaining");
if(!f1 || !f2 || !f3) return;
text = "";
var url = window.location.href;
var contestId = "";
var i = url.indexOf("contest") + 8;
if(i == -1) return;
for(; i < url.length; i++){
if(url.charAt(i) < '0' || url.charAt(i) > '9')
break;
contestId += url.charAt(i);
}
if(!contestId) return;
url = `https://vjudge.net/comment/thread?path=contest/${contestId}`;
function makeHttpObject() {
try {
return new XMLHttpRequest();
}
catch (error) {
}
try {
return new ActiveXObject("Msxml2.XMLHTTP");
}
catch (error) {
}
try {
return new ActiveXObject("Microsoft.XMLHTTP");
}
catch (error) {
}
throw new Error("Could not create HTTP request object.");
}
var request = makeHttpObject();
request.open("GET", url, true);
request.send(null);
request.responseType = "text";
request.onreadystatechange = function() {
if (request.readyState == 4){
var x = request.responseText;
if(!hasOldComments) getOldComments(x);
else checkForNewComments(x);
}
};
text = request.responseText;
}
function isAdmin(author){
return managers.indexOf(author) != -1;
}
function checkForNewComments(text){
if(window.navigator.onLine){
if(text.length == 0) return;
var obj = JSON.parse(text);
if(obj["id"] == 0) return; //no comments
var posts = obj["posts"];
for(var i = 0; i < posts.length; i++){
if(!isAdmin(posts[i]["author"])) continue;
if(posts[i]["content"] == undefined) continue;
if(posts[i]["parentId"] != 0) continue;
if(commentsIds.indexOf(posts[i]["id"]) != -1) continue;
alert(posts[i]["content"]);
commentsIds.push(posts[i]["id"]);
}
}
}
function getOldComments(text){
hasOldComments = 1;
if(window.navigator.onLine){
if(text.length == 0) return;
var obj = JSON.parse(text);
if(obj["id"] == 0) return; //no comments
var posts = obj["posts"];
for(var i = 0; i < posts.length; i++){
if(!isAdmin(posts[i]["author"])) continue;
if(posts[i]["content"] == undefined) continue;
if(posts[i]["parentId"] != 0) continue;
if(commentsIds.indexOf(posts[i]["id"]) != -1) continue;
commentsIds.push(posts[i]["id"]);
}
}
}
var myVar = setInterval(getJsonText, 1000);