Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ecc521
GitHub Repository: ecc521/gimkit-bot
Path: blob/master/new-bot.js
1615 views
1
2
3
//note script may not perform well on kits with 50+ questions
4
var safeMode = true;
5
var map1;
6
7
//only for tampermonkey
8
try {
9
if (GM_getValue(1) == undefined) {
10
var test = new Map().set("test question", "test answer")
11
var temp2 = []
12
test.forEach((value, name) => temp2.push({ name, value }));
13
14
15
GM_setValue(1, temp2)
16
17
map1 = new Map(
18
GM_getValue(1).map(object => {
19
return [object.name, object.value];
20
}),
21
);
22
} else {
23
map1 = new Map(
24
GM_getValue(1).map(object => {
25
return [object.name, object.value];
26
}),
27
);
28
}
29
console.log(GM_getValue(1))
30
} catch (error) {
31
console.log("Could not access Tampermonkey functions. Defaulting to temporary store")
32
map1 = new Map()
33
}
34
35
36
37
var arr = document.querySelectorAll('span')
38
39
//get dynamic div position
40
function getOffset(elem) {
41
var top=2, left=2; // offset so the mouse can actually click on the span
42
while(elem) {
43
top = top + parseInt(elem.offsetTop);
44
left = left + parseInt(elem.offsetLeft);
45
elem = elem.offsetParent;
46
}
47
return [left, top];
48
}
49
50
var running = false;
51
52
//set up listner
53
window.addEventListener("keypress", function onEvent(event) {
54
if (event.key === "p") {
55
running = true
56
determineKeyPress()
57
58
}
59
if (event.key === "u") {
60
safeMode = !safeMode
61
if (safeMode == true) {
62
alert("Safe mode on. Best used for gamemodes such as Trust No One and Classic")
63
} else if (safeMode == false) {
64
alert("Safe mode off. May cause Gimkit to flag. Best used for gamemodes such as Capture the Flag and Tag")
65
}
66
}
67
if (event.key === 'q') {
68
//only for capture the flag or tag
69
try {
70
var button = document.querySelectorAll("span")
71
72
for (let i = 1; i <= button.length; i++) {
73
if (button[i].textContent == "Answer Questions") {var temp = button[i]}
74
}
75
}
76
catch(err) {
77
console.log("Could not find the button tied to hotkey")
78
}
79
80
pressOnPos(getOffset(temp)[0], getOffset(temp)[1])
81
82
}
83
if (event.key === "e") {
84
//only for capture the flag
85
try {
86
button = document.querySelectorAll("span")
87
88
for (let i = 1; i <= button.length; i++) {
89
if (button[i].textContent == "Become Invisible") {temp = button[i]}
90
}
91
}
92
catch(err) {
93
console.log("Could not find the button tied to hotkey")
94
}
95
96
pressOnPos(getOffset(temp)[0], getOffset(temp)[1])
97
}
98
if (event.key === "o") {
99
running = false
100
}
101
});
102
103
104
105
//temp questions and answers
106
var tQuestion = null;
107
var tAns1 = null;
108
var tAns2 = null;
109
var tAns3 = null;
110
var tAns4 = null;
111
112
var selected = null; //the answer selected to guess
113
114
115
var temp = new Map() //temp map for storing answers to keys
116
var blacklist = new Map() // questions to their blacklisted answers
117
var answersMap = map1 //ultimate map for stories questions to answers
118
119
120
function determineKeyPress() {
121
temp.clear();
122
setTemps()
123
124
if (running == false) {
125
return;
126
}
127
128
if (answersMap.has(tQuestion)) {
129
var answer = answersMap.get(tQuestion)
130
selected = answer
131
if (tAns1 == answer) {showKey(temp.get(tAns1))}
132
else if (tAns2 == answer) {showKey(temp.get(tAns2))}
133
else if (tAns3 == answer) {showKey(temp.get(tAns3))}
134
else {showKey(temp.get(tAns4))}
135
return
136
}
137
138
//no answer has been found for this question? Have we been here before and found any blacklists?
139
if (blacklist.has(tQuestion)) {
140
//get blacklists
141
var temp1 = blacklist.get(tQuestion)
142
if (!temp1.includes(tAns1)) {selected = tAns1; showKey(temp.get(tAns1))}
143
else if (!temp1.includes(tAns2)) {selected = tAns2; showKey(temp.get(tAns2))}
144
else if (!temp1.includes(tAns3)) {selected = tAns3; showKey(temp.get(tAns3))}
145
else if (!temp1.includes(tAns4)) {selected = tAns4; showKey(temp.get(tAns4))}
146
else {
147
blacklist.set(tQuestion, [])
148
selected = tAns1
149
showKey(temp.get(tAns1))
150
} //reset because error
151
} else {
152
//completey new question?
153
blacklist.set(tQuestion, [])
154
selected = tAns1
155
showKey(temp.get(tAns1))
156
}
157
158
159
}
160
//70 works for tag or ctf
161
//check if answer was correct and blacklist if wrong
162
function checkAnswer() {
163
console.log(answersMap)
164
var newArr = document.querySelectorAll('span')
165
166
var ans = newArr[4].textContent
167
var conti = newArr[5]
168
console.log(ans)
169
170
if ((ans.includes("Close") || ans.includes("Mission") || ans.includes("Shop")) && answersMap.has(tQuestion)) {
171
pressOnPos(getOffset(conti)[0], getOffset(conti)[1])
172
if (running == true) {
173
setTimeout(function() {
174
determineKeyPress()
175
}, timeOut());
176
}
177
return
178
}
179
180
181
if ((ans.includes("Close") || ans.includes("Mission") || ans.includes("Shop")) && !answersMap.has(tQuestion)) {
182
console.log('found corret one')
183
answersMap.set(tQuestion, selected)
184
pressOnPos(getOffset(conti)[0], getOffset(conti)[1])
185
if (running == true) {
186
saveAnswers()
187
setTimeout(function() {
188
determineKeyPress()
189
}, timeOut());
190
}
191
return
192
}
193
else {
194
if (!blacklist.has(tQuestion)) {
195
blacklist.set(tQuestion, [])
196
}
197
console.log("psuhed")
198
blacklist.get(tQuestion).push(selected)
199
pressOnPos(getOffset(conti)[0], getOffset(conti)[1])
200
if (running == true) {
201
setTimeout(function() {
202
determineKeyPress()
203
}, timeOut());
204
}
205
return
206
}
207
}
208
//450 minimum
209
//slow network or slow pc speeds may need values 700+
210
function showKey(key) {
211
//show client key press with color
212
console.log(key)
213
214
if (key == 1) {
215
pressOnPos(getOffset(arr[5])[0], getOffset(arr[5])[1])
216
setTimeout(function() {
217
checkAnswer()
218
}, 500);
219
}
220
else if (key == 2) {
221
pressOnPos(getOffset(arr[6])[0], getOffset(arr[6])[1])
222
setTimeout(function() {
223
checkAnswer()
224
}, 500);
225
}
226
else if (key == 3) {
227
pressOnPos(getOffset(arr[7])[0], getOffset(arr[7])[1])
228
setTimeout(function() {
229
checkAnswer()
230
}, 500);
231
}
232
else if (key == 4) {
233
pressOnPos(getOffset(arr[8])[0], getOffset(arr[8])[1])
234
setTimeout(function() {
235
checkAnswer()
236
}, 500);
237
}
238
}
239
240
function setTemps() {
241
try {
242
arr = document.querySelectorAll('span')
243
tQuestion = arr[4].textContent.replace(/ /g, '')
244
245
tAns1 = arr[5].textContent.replace(/ /g, '')
246
tAns2 = arr[6].textContent.replace(/ /g, '')
247
tAns3 = arr[7].textContent.replace(/ /g, '')
248
tAns4 = arr[8].textContent.replace(/ /g, '')
249
250
temp.set(tAns1, 1)
251
temp.set(tAns2, 2)
252
temp.set(tAns3, 3)
253
temp.set(tAns4, 4)
254
} catch (error){
255
alert("Script crashed. Likely due to slow network or a slow pc")
256
console.log(error)
257
running = false
258
}
259
260
261
}
262
263
function pressOnPos(posX, posY) {
264
console.log(posX, posY)
265
window.dispatchEvent(new MouseEvent("mousedown-is-trusted", {composed: true, bubbles: true, clientX: posX, clientY: posY, button: 0, buttons: 1}));
266
window.dispatchEvent(new MouseEvent("mousemove-is-trusted", {composed: true, bubbles: true, clientX: posX, clientY: posY, button: 1, buttons: 2}));
267
window.dispatchEvent(new MouseEvent("mouseup-is-trusted", {composed: true, bubbles: true, clientX: posX, clientY: posY, button: 0, buttons: 3}));
268
}
269
270
//only for tampermonkey
271
function saveAnswers() {
272
try {
273
temp2 = []
274
answersMap.forEach((value, name) => temp2.push({ name, value }));
275
GM_deleteValue(1)
276
GM_setValue(1, temp2)
277
} catch (error) {
278
console.log("Couldn't save qustions to tampermonkey")
279
}
280
281
}
282
283
//keeps the click is trusted extension alive
284
function keepAlive() {
285
window.dispatchEvent(new MouseEvent("mousemove-is-trusted", {composed: true, bubbles: true, clientX: 23, clientY: 25, button: 1, buttons: 2}));
286
setTimeout(function() {
287
keepAlive()
288
console.log("alive")
289
}, 1200);
290
}
291
keepAlive()
292
293
function timeOut() {
294
if (safeMode == true) {
295
return 210;
296
} else {
297
return 30;
298
}
299
}
300
301
302