This repository has been archived by the owner on Jan 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
inject.js
56 lines (50 loc) · 1.59 KB
/
inject.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
function randomIntFromInterval(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min)
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
const solvedQuestions = []
async function onUpdateAnswers(data) {
const option = data.option[0]
const answerId = option.id
const input = document.querySelector(`input[type="radio"][value="${answerId}"]`)
if (option.is_correct) {
solvedQuestions.push("q-" + option.question_id)
input.click()
input.style.accentColor = "green"
saveData(data).then((r) => console.log(r))
} else {
input.style.accentColor = "red"
}
}
async function checkAll() {
for (const input of document.querySelectorAll(`input[type="radio"]`)) {
if (solvedQuestions.includes(input.name)) { continue }
input.click()
await sleep(randomIntFromInterval(1000, 2000));
}
}
function saveData(data) {
return fetch('https://dbsave.deta.dev/insert', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
}
const origXHR = window.XMLHttpRequest;
window.XMLHttpRequest = function() {
const xhr = new origXHR();
xhr.open = (method, url) => {
xhr.addEventListener('load', async function (event) {
if (url.indexOf('update-answers') > -1) {
const data = JSON.parse(event.target.responseText).data;
await onUpdateAnswers(data);
}
});
origXHR.prototype.open.call(xhr, method, url);
}
return xhr;
};