-
Notifications
You must be signed in to change notification settings - Fork 3
/
QuizletHack.user.js
460 lines (392 loc) · 13.5 KB
/
QuizletHack.user.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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
// ==UserScript==
// @name Quizlet Hack
// @namespace http://tampermonkey.net/
// @version 1.0.7
// @description A hack for quizlet live
// @author jokeri2222
// @match https://quizlet.com/live/*
// @match https://quizlet.com/live
// @icon https://www.google.com/s2/favicons?sz=64&domain=quizlet.com
// @grant none
// ==/UserScript==
var Version = '1.0.7'
var autoAnswer = false;
var showAnswers = false;
var pairs = []
var spans = []
var gameCode = undefined
var lastCode = undefined
var lastAnswer = ""
function FindByAttributeValue(attribute, value, element_type) {
element_type = element_type || "*";
var All = document.getElementsByTagName(element_type);
for (var i = 0; i < All.length; i++) {
if (All[i].getAttribute(attribute) == value) {
return All[i];
}
}
}
const uiElement = document.createElement('div');
uiElement.className = 'floating-ui';
uiElement.style.position = 'absolute';
uiElement.style.top = '5%';
uiElement.style.left = '5%';
uiElement.style.width = '33vw';
uiElement.style.height = 'auto';
uiElement.style.backgroundColor = '#423ed8';
uiElement.style.borderRadius = '1vw';
uiElement.style.boxShadow = '0px 0px 10px 0px rgba(0, 0, 0, 0.5)';
uiElement.style.zIndex = '9999';
const handle = document.createElement('div');
handle.className = 'handle';
handle.style.fontSize = '1.5vw';
handle.textContent = 'Quizlet Hack!';
handle.style.color = 'white';
handle.style.width = '97.5%';
handle.style.height = '2.5vw';
handle.style.backgroundColor = '#282e3e';
handle.style.borderRadius = '1vw 1vw 0 0';
handle.style.cursor = 'grab';
handle.style.textAlign = 'left';
handle.style.paddingLeft = '2.5%';
handle.style.lineHeight = '2vw';
uiElement.appendChild(handle);
const closeButton = document.createElement('div');
closeButton.className = 'close-button';
closeButton.textContent = '✕';
closeButton.style.position = 'absolute';
closeButton.style.top = '0';
closeButton.style.right = '0';
closeButton.style.width = '12.5%';
closeButton.style.height = '2.5vw';
closeButton.style.backgroundColor = 'red';
closeButton.style.color = 'white';
closeButton.style.borderRadius = '0 1vw 0 0';
closeButton.style.display = 'flex';
closeButton.style.justifyContent = 'center';
closeButton.style.alignItems = 'center';
closeButton.style.cursor = 'pointer';
handle.appendChild(closeButton);
const minimizeButton = document.createElement('div');
minimizeButton.className = 'minimize-button';
minimizeButton.textContent = '─';
minimizeButton.style.color = 'white';
minimizeButton.style.position = 'absolute';
minimizeButton.style.top = '0';
minimizeButton.style.right = '12.5%';
minimizeButton.style.width = '12.5%';
minimizeButton.style.height = '2.5vw';
minimizeButton.style.backgroundColor = 'gray';
minimizeButton.style.borderRadius = '0 0 0 0';
minimizeButton.style.display = 'flex';
minimizeButton.style.justifyContent = 'center';
minimizeButton.style.alignItems = 'center';
minimizeButton.style.cursor = 'pointer';
handle.appendChild(minimizeButton);
const header3 = document.createElement('h2');
header3.textContent = 'ANSWERING';
header3.style.display = 'block';
header3.style.margin = '1vw';
header3.style.textAlign = 'center';
header3.style.fontSize = '2vw';
header3.style.color = 'white';
header3.style.textShadow = `
-1px -1px 0 rgb(47, 47, 47),
1px -1px 0 rgb(47, 47, 47),
-1px 1px 0 rgb(47, 47, 47),
1px 1px 0 rgb(47, 47, 47)
`;
uiElement.appendChild(header3);
const autoAnswerSwitchContainer = document.createElement('div');
autoAnswerSwitchContainer.className = 'switch-container';
autoAnswerSwitchContainer.style.display = 'flex';
autoAnswerSwitchContainer.style.alignItems = 'center';
autoAnswerSwitchContainer.style.justifyContent = 'center';
uiElement.appendChild(autoAnswerSwitchContainer);
const autoAnswerLabel = document.createElement('span');
autoAnswerLabel.textContent = 'Auto Answer';
autoAnswerLabel.className = 'switch-label';
autoAnswerLabel.style.fontSize = '1.5vw';
autoAnswerLabel.style.color = 'white';
autoAnswerLabel.style.margin = '2.5vw'
autoAnswerSwitchContainer.appendChild(autoAnswerLabel);
const autoAnswerSwitch = document.createElement('label');
autoAnswerSwitch.className = 'switch';
autoAnswerSwitchContainer.appendChild(autoAnswerSwitch);
const autoAnswerInput = document.createElement('input');
autoAnswerInput.type = 'checkbox';
autoAnswerInput.addEventListener('change', function() {
autoAnswer = this.checked;
});
autoAnswerSwitch.appendChild(autoAnswerInput);
const autoAnswerSlider = document.createElement('span');
autoAnswerSlider.className = 'slider';
autoAnswerSwitch.appendChild(autoAnswerSlider);
const showAnswersSwitchContainer = document.createElement('div');
showAnswersSwitchContainer.className = 'switch-container';
showAnswersSwitchContainer.style.display = 'flex';
showAnswersSwitchContainer.style.alignItems = 'center';
showAnswersSwitchContainer.style.justifyContent = 'center';
uiElement.appendChild(showAnswersSwitchContainer);
const showAnswersLabel = document.createElement('span');
showAnswersLabel.textContent = 'Show Answers';
showAnswersLabel.className = 'switch-label';
showAnswersLabel.style.fontSize = '1.5vw';
showAnswersLabel.style.color = 'white';
showAnswersLabel.style.margin = '2.5vw'
showAnswersSwitchContainer.appendChild(showAnswersLabel);
const showAnswersSwitch = document.createElement('label');
showAnswersSwitch.className = 'switch';
showAnswersSwitchContainer.appendChild(showAnswersSwitch);
const showAnswersInput = document.createElement('input');
showAnswersInput.type = 'checkbox';
showAnswersInput.addEventListener('change', function() {
showAnswers = this.checked;
});
showAnswersSwitch.appendChild(showAnswersInput);
const showAnswersSlider = document.createElement('span');
showAnswersSlider.className = 'slider';
showAnswersSwitch.appendChild(showAnswersSlider);
const style = document.createElement('style');
style.textContent = `
.custom-slider {
background: white
border: none;
outline: none;
cursor: ew-resize;
appearance: none; /* Remove default appearance */
height: 0; /* Set the height to match the thumb height */
}
.custom-slider::-webkit-slider-thumb {
appearance: none; /* Remove default appearance */
width: 1.75vw; /* Set width of the slider handle */
height: 1.75vw; /* Set height of the slider handle */
background-color: rgb(47, 47, 47); /* Set handle color to dark gray */
border-radius: 50%; /* Create a circle for the handle */
cursor: ew-resize; /* Horizontal resize cursor */
margin-top: -0.5vw; /* Adjust margin-top to vertically center the thumb */
}
.custom-slider::-webkit-slider-runnable-track {
width: 100%; /* Set track width to 100% */
height: 0.75vw; /* Set track height to match the thumb height */
background-color: white; /* Set track color to white */
cursor: ew-resize; /* Horizontal resize cursor */
border-radius: 1vw; /* Set rounded corners for the track */
background: linear-gradient(to right, red, yellow, limegreen); /* Gradient from red to yellow to green */
}
:root {
--switch-width: 5.9vw;
--switch-height: 3.3vw;
--slider-size: 2.5vw;
--slider-thumb-size: 1.3vw;
}
.switch {
position: relative;
display: inline-block;
width: var(--switch-width);
height: var(--switch-height);
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: red;
transition: 0.8s;
border-radius: .5vw
}
.slider:before {
position: absolute;
content: "";
height: var(--slider-size);
width: var(--slider-size);
left: calc(var(--slider-thumb-size) / 3);
bottom: calc(var(--slider-thumb-size) / 3);
background-color: rgb(43, 43, 43);
transition: 0.8s;
border-radius: .5vw
}
input:checked + .slider {
background-color: green;
}
input:focus + .slider {
box-shadow: 0 0 1px green;
}
input:checked + .slider:before {
transform: translateX(calc(var(--slider-size)));
}
`;
document.head.appendChild(style);
const versionLabel = document.createElement('h1');
versionLabel.textContent = 'Quizlet Hack! V' + Version;
versionLabel.style.fontSize = '2.5vw';
versionLabel.style.display = 'block';
versionLabel.style.textAlign = 'center';
versionLabel.style.marginTop = '3.5vw';
versionLabel.style.marginLeft = '1vw';
versionLabel.style.marginRight = '1vw';
versionLabel.style.color = 'white';
uiElement.appendChild(versionLabel);
const githubContainer = document.createElement('div');
githubContainer.style.textAlign = 'center';
githubContainer.style.marginTop = '1vw';
const githubLabel = document.createElement('span');
githubLabel.textContent = 'GitHub: ';
githubLabel.style.fontSize = '1.5vw';
githubLabel.style.margin = '0 1vw';
githubLabel.style.color = 'white';
githubContainer.appendChild(githubLabel);
const githubUrl = document.createElement('a');
githubUrl.textContent = 'jokeri2222';
githubUrl.href = 'https://github.com/jokeri2222';
githubUrl.target = '_blank';
githubUrl.style.fontSize = '1.5vw';
githubUrl.style.margin = '0 1vw';
githubUrl.style.color = 'white';
githubContainer.appendChild(githubUrl);
const githubUrl2 = document.createElement('a');
githubUrl2.textContent = 'Epic0001';
githubUrl2.href = 'https://github.com/Epic0001';
githubUrl2.target = '_blank';
githubUrl2.style.fontSize = '1.5vw';
githubUrl2.style.margin = '0 1vw';
githubUrl2.style.color = 'white';
githubContainer.appendChild(githubUrl2);
uiElement.appendChild(githubContainer);
closeButton.addEventListener('click', () => {
document.body.removeChild(uiElement);
autoAnswer = false;
showAnswers = false;
});
let isMinimized = false;
minimizeButton.addEventListener('click', () => {
isMinimized = !isMinimized;
if (isMinimized) {
header3.style.display = 'none';
versionLabel.style.display = 'none';
githubContainer.style.display = 'none';
autoAnswerSwitchContainer.style.display = 'none';
showAnswersSwitchContainer.style.display = 'none';
uiElement.style.height = '2.5vw';
handle.style.height = '100%';
closeButton.style.height = '100%';
minimizeButton.style.height = '100%';
} else {
header3.style.display = 'block';;
versionLabel.style.display = 'block';
githubContainer.style.display = 'block';
handle.style.height = '2.5vw';
uiElement.style.height = 'auto';
closeButton.style.height = '2.5vw';
minimizeButton.style.height = '2.5vw';
autoAnswerSwitchContainer.style.display = 'flex';
showAnswersSwitchContainer.style.display = 'flex';
}
});
document.body.appendChild(uiElement);
let isDragging = false;
let offsetX, offsetY;
handle.addEventListener('mousedown', (e) => {
isDragging = true;
offsetX = e.clientX - uiElement.getBoundingClientRect().left;
offsetY = e.clientY - uiElement.getBoundingClientRect().top;
});
document.addEventListener('mousemove', (e) => {
if (isDragging) {
const x = e.clientX - offsetX;
const y = e.clientY - offsetY;
uiElement.style.left = x + 'px';
uiElement.style.top = y + 'px';
}
});
document.addEventListener('mouseup', () => {
isDragging = false;
});
function getPair(str) {
result = undefined
pairs.forEach(function(pair) {
if (pair[0] == str) {
result = pair[1]
}
if (pair[1] == str) {
result = pair[0]
}
})
return result
}
function getAnswerIndex() {
resultIdx = undefined
answer = getPair(document.querySelector(".FormattedText").textContent)
if (!answer) {
location.reload();
pairs = []
}
document.querySelectorAll(".a1w6enf9").forEach(function(elem, idx) {
if (elem.textContent == answer) {
resultIdx = idx
}
})
return resultIdx
}
function answerQuestion(index) {
try {
document.querySelectorAll(".a1w6enf9")[index].click()
} catch { return false}
return true
}
function highlight(index) {
document.querySelectorAll(".a1w6enf9").forEach(function(elem, idx) {
if (idx == index) {
elem.style.color = 'rgb(152, 241, 209)'
} else {
elem.style.color = 'rgb(218, 69, 67)'
}
})
}
const originalXhrOpen = XMLHttpRequest.prototype.open;
const originalXhrSend = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.open = function (method, url, ...rest) {
this._interceptedUrl = url; // Store the URL for logging
return originalXhrOpen.call(this, method, url, ...rest);
};
XMLHttpRequest.prototype.send = function (...args) {
this.addEventListener('load', function () {
if (this.responseText) {
let text = this.responseText
let index = text.indexOf("42[")
if (index != -1) {
let cards = JSON.parse(text.slice(index+2))[1].cards
pairs = cards.map(function (card){
return card.cardSides.map(side => side.media[0].plainText)
})
console.log(pairs)
}
}
});
return originalXhrSend.call(this, ...args);
};
setInterval(function() {
if (document.querySelector(".StudentEndView")) lastAnswer = ""
if (pairs.length != 0) {
if (document.querySelector(".FormattedText")) {
const answerIndex = getAnswerIndex()
if (autoAnswer && lastAnswer != answer) {
if (answerQuestion(answerIndex)) lastAnswer = answer
}
if (showAnswers) {
highlight(answerIndex)
} else {
document.querySelectorAll(".a1w6enf9").forEach(function(elem) {
elem.style.color = '';
});
}
}
}
}, 1)