-
Notifications
You must be signed in to change notification settings - Fork 21
/
addTokens.js
61 lines (50 loc) · 1.64 KB
/
addTokens.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
// Adds currencies using endpoint /api/users/add-rewards
export async function addTokens() {
// Blooket overrides the default window.alert function, so this is needed to access it
function customAlert(msg)
{
let appdiv = document.getElementById("app");
let iframe = document.createElement("iframe");
appdiv.appendChild(iframe);
iframe.contentWindow.alert(msg);
iframe.remove();
}
// Make blooket think we're starting a solo game of tower defense, so we can get an access token to be allowed to use get-rewards
const session_token_response = await fetch("https://play.blooket.com/api/playersessions/solo", {
"headers": {
"accept": "application/json",
},
// This question set is one called 'farm'
// It's already designed for farming tokens, so it should be alright to use in this extension
body: "{\"gameMode\":\"Defense2\",\"questionSetId\":\"62211ec298c56fd0b8de9eb7\"}",
method: "POST",
credentials: "include"
});
// Extract the token from the response
const session_token = (await session_token_response.json()).t;
console.log(session_token);
let JSONBody = {
addedTokens: 500,
addedXp: 300,
t: session_token,
};
let payload = (new TextEncoder).encode(JSON.stringify(JSONBody));
// Send request to blooket API
const response = await fetch('https://play.blooket.com/api/users/add-rewards', {
method: "PUT",
headers: {
"content-type": "application/json",
},
credentials: "include",
body: payload
});
console.log(response.json());
if(response.status != 200)
{
customAlert("Error adding tokens");
return;
}
// Reload page to sync changes with server
location.reload();
};
//await addTokens();