-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsemiauto.user.js
More file actions
217 lines (182 loc) · 7.35 KB
/
semiauto.user.js
File metadata and controls
217 lines (182 loc) · 7.35 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
// ==UserScript==
// @name Semiauto Imposter Bot
// @namespace jrwr.io
// @version 1.0.1
// @description Semiautomatic version from the Imposter Bot for Reddit's April Fools Day 2020.
// @author dimden (https://dimden.dev/), jrwr (http://jrwr.io/), px(u/Hennihenner), qqii, NightHawkCanada, cg
// @match https://gremlins-api.reddit.com/room?nightmode=1&platform=desktop
// @match https://gremlins-api.reddit.com/room?nightmode=1&platform=desktop*
// @match https://gremlins-api.reddit.com/results?*
// @require https://github.com/LeoVerto/doorman/raw/master/doorman-lib.js?v=0.9
// @updateurl https://github.com/jrwr/imposterbot/raw/master/semiauto.user.js
// ==/UserScript==
document.getElementsByTagName("head")[0].insertAdjacentHTML(
"beforeend",
"<link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/npm/toastify-js/src/toastify.min.css\" />");
let imported = document.createElement('script');
imported.src = 'https://cdn.jsdelivr.net/npm/toastify-js';
document.head.appendChild(imported);
async function getRoom() {
let res = await (await fetch("https://gremlins-api.reddit.com/room?nightmode=1&platform=desktop")).text();
let parser = new DOMParser();
let doc = parser.parseFromString(res, "text/html");
return {
token: doc.getElementsByTagName("gremlin-app")[0].getAttribute("csrf"),
options: Array.from(doc.getElementsByTagName("gremlin-note")).map(e => [e.id, e.innerText])
};
};
async function submitAnswer(token, id) {
if(token === 0){
return JSON.parse(0);
} else {
let body = new FormData();
body.append("undefined", "undefined");
body.append("note_id", id);
body.append("csrf_token", token);
let res = await (await fetch("https://gremlins-api.reddit.com/submit_guess", {
method: "post",
body
})).text();
return JSON.parse(res);
}
}
async function asyncForEach(array, callback) {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
}
async function play() {
let room = await getRoom();
let answer = 0,
maxDetector = 0;
let abraP = checkExistingAbra(room.options.flatMap(x => x[0]));
let spacP = Promise.all(room.options.flatMap(x => checkExistingSpacescience(x[0])));
let oceanP = Promise.all(room.options.flatMap(x => checkExistingOcean(x[0])));
// let deteP = Promise.all(room.options.flatMap(x => checkDetector(x[1])));
// cost of accuracy
let [abra, space, ocean] = await Promise.all([abraP, spacP, oceanP]);
// console.table(abra);
// console.table(space);
// console.table(detector);
let flag = 0;
for (let i = 0; i < room.options.length; i++) {
// o is id
// z is string
let [o, z] = room.options[i];
if (abra[i] === "known fake" || space[i] === "known fake" || ocean[i] == "known fake") {
answer = i;
break;
} else if (abra[i] === "known human" || space[i] === "known human" || ocean[i] == "known human") {
flag++;
continue;
} else if (abra[i] === "unknown" && space[i] === "unknown" || ocean[i] == "known fake") {
answer = i;
// if (detector[i] > maxDetector) {
// maxDetector = detector[i];
// answer = i;
// continue;
// }
}
};
if (flag < 4){
window.open("https://gremlins-api.reddit.com/room?nightmode=1","_self")
return 0;
} else if (flag >= 4){
let result = await submitAnswer(room.token, room.options[answer][0]);
return [room.options[answer][1], result.result, room];
}
};
async function submitAnswerToDB(answer, result, room) {
let body = new FormData();
delete room.token;
body.append("answer", answer);
body.append("result", result);
body.append("room", JSON.stringify(room));
let res = await (await fetch("https://spacescience.tech/api.php", {
method: "post",
body
})).text();
return JSON.parse(res);
}
let timing = [];
function getStats() {
const sum = timing.reduce((a, b) => a + b, 0);
const avg = (sum / timing.length) || 0;
// console.log(wins);
return `All: ${wins.length+loses.length} -
Wins: ${wins.length} (${((wins.length/(wins.length+loses.length))*100).toFixed(1)}%),
Losses: ${loses.length} (${((loses.length/(wins.length+loses.length))*100).toFixed(1)}%), Time (ms): ${avg}
`;
}
window.last = "INVALID";
window.wins = []; window.loses = [];
setInterval(async () => {
let t0 = performance.now();
let game = await play();
submitAnswerToDB(game[0].trim(), game[1], game[2]).then(
function (submit) {
let t1 = performance.now();
timing.push(t1 - t0);
game[0] = game[0].trim();
if(game[1] === "WIN") wins.push(game[0]);
else if(game[1] === "LOSE") loses.push(game[0]);
last = game[1];
if (game[1] == "WIN")
{
Toastify({
text: game[1] + ": "+ game[0],
duration: 5000,
newWindow: true,
close: false,
gravity: "top", // `top` or `bottom`
position: 'left', // `left`, `center` or `right`
backgroundColor: "linear-gradient(to right, #00b09b, #96c93d)",
stopOnFocus: false, // Prevents dismissing of toast on hover
}).showToast();
}
else if (game[1] == "LOSE")
{
Toastify({
text: game[1] + ": "+ game[0],
duration: 5000,
newWindow: true,
close: false,
gravity: "top", // `top` or `bottom`
position: 'left', // `left`, `center` or `right`
backgroundColor: "linear-gradient(to right, #b00023, #c93d54)",
stopOnFocus: false, // Prevents dismissing of toast on hover
}).showToast();
}
else if (game[1] == "INVALID")
{
Toastify({
text: "inval",
duration: 1000,
newWindow: true,
close: false,
gravity: "bottom", // `top` or `bottom`
position: 'left', // `left`, `center` or `right`
backgroundColor: "linear-gradient(to right, #423e3f, #8f8b8c)",
stopOnFocus: false, // Prevents dismissing of toast on hover
}).showToast();
}
)
}, 1200)
setInterval(() => {
let curstatus = getStats();
Toastify({
text: curstatus,
duration: 10100,
newWindow: true,
close: false,
gravity: "bottom", // `top` or `bottom`
position: 'right', // `left`, `center` or `right`
backgroundColor: "linear-gradient(to right, #cf00c1, #3d49c9)",
stopOnFocus: false, // Prevents dismissing of toast on hover
}).showToast();
if(location.href.includes("results?") && !document.hidden) fetch(`https://gremlins-api.reddit.com/results?prev_result=${last}&nightmode=1&platform=desktop`).then(i => i.text()).then(html => {
let parser = new DOMParser();
let doc = parser.parseFromString(html, "text/html");
document.getElementsByTagName("gremlin-app")[0].innerHTML = doc.getElementsByTagName("gremlin-app")[0].innerHTML;
})
}, 10000);