This repository has been archived by the owner on Jan 26, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathnew-bot.js
300 lines (253 loc) · 8.4 KB
/
new-bot.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
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
//note script may not perform well on kits with 50+ questions
var safeMode = true;
var map1;
//only for tampermonkey
try {
if (GM_getValue(1) == undefined) {
var test = new Map().set("test question", "test answer")
var temp2 = []
test.forEach((value, name) => temp2.push({ name, value }));
GM_setValue(1, temp2)
map1 = new Map(
GM_getValue(1).map(object => {
return [object.name, object.value];
}),
);
} else {
map1 = new Map(
GM_getValue(1).map(object => {
return [object.name, object.value];
}),
);
}
console.log(GM_getValue(1))
} catch (error) {
console.log("Could not access Tampermonkey functions. Defaulting to temporary store")
map1 = new Map()
}
var arr = document.querySelectorAll('span')
//get dynamic div position
function getOffset(elem) {
var top=2, left=2; // offset so the mouse can actually click on the span
while(elem) {
top = top + parseInt(elem.offsetTop);
left = left + parseInt(elem.offsetLeft);
elem = elem.offsetParent;
}
return [left, top];
}
var running = false;
//set up listner
window.addEventListener("keypress", function onEvent(event) {
if (event.key === "p") {
running = true
determineKeyPress()
}
if (event.key === "u") {
safeMode = !safeMode
if (safeMode == true) {
alert("Safe mode on. Best used for gamemodes such as Trust No One and Classic")
} else if (safeMode == false) {
alert("Safe mode off. May cause Gimkit to flag. Best used for gamemodes such as Capture the Flag and Tag")
}
}
if (event.key === 'q') {
//only for capture the flag or tag
try {
var button = document.querySelectorAll("span")
for (let i = 1; i <= button.length; i++) {
if (button[i].textContent == "Answer Questions") {var temp = button[i]}
}
}
catch(err) {
console.log("Could not find the button tied to hotkey")
}
pressOnPos(getOffset(temp)[0], getOffset(temp)[1])
}
if (event.key === "e") {
//only for capture the flag
try {
button = document.querySelectorAll("span")
for (let i = 1; i <= button.length; i++) {
if (button[i].textContent == "Become Invisible") {temp = button[i]}
}
}
catch(err) {
console.log("Could not find the button tied to hotkey")
}
pressOnPos(getOffset(temp)[0], getOffset(temp)[1])
}
if (event.key === "o") {
running = false
}
});
//temp questions and answers
var tQuestion = null;
var tAns1 = null;
var tAns2 = null;
var tAns3 = null;
var tAns4 = null;
var selected = null; //the answer selected to guess
var temp = new Map() //temp map for storing answers to keys
var blacklist = new Map() // questions to their blacklisted answers
var answersMap = map1 //ultimate map for stories questions to answers
function determineKeyPress() {
temp.clear();
setTemps()
if (running == false) {
return;
}
if (answersMap.has(tQuestion)) {
var answer = answersMap.get(tQuestion)
selected = answer
if (tAns1 == answer) {showKey(temp.get(tAns1))}
else if (tAns2 == answer) {showKey(temp.get(tAns2))}
else if (tAns3 == answer) {showKey(temp.get(tAns3))}
else {showKey(temp.get(tAns4))}
return
}
//no answer has been found for this question? Have we been here before and found any blacklists?
if (blacklist.has(tQuestion)) {
//get blacklists
var temp1 = blacklist.get(tQuestion)
if (!temp1.includes(tAns1)) {selected = tAns1; showKey(temp.get(tAns1))}
else if (!temp1.includes(tAns2)) {selected = tAns2; showKey(temp.get(tAns2))}
else if (!temp1.includes(tAns3)) {selected = tAns3; showKey(temp.get(tAns3))}
else if (!temp1.includes(tAns4)) {selected = tAns4; showKey(temp.get(tAns4))}
else {
blacklist.set(tQuestion, [])
selected = tAns1
showKey(temp.get(tAns1))
} //reset because error
} else {
//completey new question?
blacklist.set(tQuestion, [])
selected = tAns1
showKey(temp.get(tAns1))
}
}
//70 works for tag or ctf
//check if answer was correct and blacklist if wrong
function checkAnswer() {
console.log(answersMap)
var newArr = document.querySelectorAll('span')
var ans = newArr[4].textContent
var conti = newArr[5]
console.log(ans)
if ((ans.includes("Close") || ans.includes("Mission") || ans.includes("Shop")) && answersMap.has(tQuestion)) {
pressOnPos(getOffset(conti)[0], getOffset(conti)[1])
if (running == true) {
setTimeout(function() {
determineKeyPress()
}, timeOut());
}
return
}
if ((ans.includes("Close") || ans.includes("Mission") || ans.includes("Shop")) && !answersMap.has(tQuestion)) {
console.log('found corret one')
answersMap.set(tQuestion, selected)
pressOnPos(getOffset(conti)[0], getOffset(conti)[1])
if (running == true) {
saveAnswers()
setTimeout(function() {
determineKeyPress()
}, timeOut());
}
return
}
else {
if (!blacklist.has(tQuestion)) {
blacklist.set(tQuestion, [])
}
console.log("psuhed")
blacklist.get(tQuestion).push(selected)
pressOnPos(getOffset(conti)[0], getOffset(conti)[1])
if (running == true) {
setTimeout(function() {
determineKeyPress()
}, timeOut());
}
return
}
}
//450 minimum
//slow network or slow pc speeds may need values 700+
function showKey(key) {
//show client key press with color
console.log(key)
if (key == 1) {
pressOnPos(getOffset(arr[5])[0], getOffset(arr[5])[1])
setTimeout(function() {
checkAnswer()
}, 500);
}
else if (key == 2) {
pressOnPos(getOffset(arr[6])[0], getOffset(arr[6])[1])
setTimeout(function() {
checkAnswer()
}, 500);
}
else if (key == 3) {
pressOnPos(getOffset(arr[7])[0], getOffset(arr[7])[1])
setTimeout(function() {
checkAnswer()
}, 500);
}
else if (key == 4) {
pressOnPos(getOffset(arr[8])[0], getOffset(arr[8])[1])
setTimeout(function() {
checkAnswer()
}, 500);
}
}
function setTemps() {
try {
arr = document.querySelectorAll('span')
tQuestion = arr[4].textContent.replace(/ /g, '')
tAns1 = arr[5].textContent.replace(/ /g, '')
tAns2 = arr[6].textContent.replace(/ /g, '')
tAns3 = arr[7].textContent.replace(/ /g, '')
tAns4 = arr[8].textContent.replace(/ /g, '')
temp.set(tAns1, 1)
temp.set(tAns2, 2)
temp.set(tAns3, 3)
temp.set(tAns4, 4)
} catch (error){
alert("Script crashed. Likely due to slow network or a slow pc")
console.log(error)
running = false
}
}
function pressOnPos(posX, posY) {
console.log(posX, posY)
window.dispatchEvent(new MouseEvent("mousedown-is-trusted", {composed: true, bubbles: true, clientX: posX, clientY: posY, button: 0, buttons: 1}));
window.dispatchEvent(new MouseEvent("mousemove-is-trusted", {composed: true, bubbles: true, clientX: posX, clientY: posY, button: 1, buttons: 2}));
window.dispatchEvent(new MouseEvent("mouseup-is-trusted", {composed: true, bubbles: true, clientX: posX, clientY: posY, button: 0, buttons: 3}));
}
//only for tampermonkey
function saveAnswers() {
try {
temp2 = []
answersMap.forEach((value, name) => temp2.push({ name, value }));
GM_deleteValue(1)
GM_setValue(1, temp2)
} catch (error) {
console.log("Couldn't save qustions to tampermonkey")
}
}
//keeps the click is trusted extension alive
function keepAlive() {
window.dispatchEvent(new MouseEvent("mousemove-is-trusted", {composed: true, bubbles: true, clientX: 23, clientY: 25, button: 1, buttons: 2}));
setTimeout(function() {
keepAlive()
console.log("alive")
}, 1200);
}
keepAlive()
function timeOut() {
if (safeMode == true) {
return 210;
} else {
return 30;
}
}