scripts/web/aov-vn/apl2022-clicker.js

140 lines
3.6 KiB
JavaScript
Raw Normal View History

2022-11-26 06:43:15 +00:00
if (!window.location.href.startsWith("https://apl2022.lienquan.garena.vn")) {
2023-08-21 18:28:47 +00:00
console.error("This script is for https://apl2022.lienquan.garena.vn only.");
2022-11-26 06:43:15 +00:00
}
async function getCurrentUser() {
2023-08-21 18:28:47 +00:00
const rsp = await fetch("/graphql", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
operationName: "getUser",
query: `
2022-11-26 06:43:15 +00:00
query getUser {
getUser {
id
name
icon
profile {
id
...Profile
__typename
}
__typename
}
}
fragment Profile on Profile {
tcid
clicks
totalClicks
dailyClicks
claimedGift
currentGift
receivedServerGift
subMissions
claimedDailyGift
date
item {
id
name
type
image
limitation
currentClaimed
__typename
}
sentWish
__typename
}
`,
2023-08-21 18:28:47 +00:00
variables: {},
}),
});
if (!rsp.ok) {
throw `Failed to get current user info`;
}
return (await rsp.json()).data.getUser;
2022-11-26 06:43:15 +00:00
}
async function postClick(amount) {
2023-08-21 18:28:47 +00:00
const rsp = await fetch("/graphql", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
operationName: "doDailyClick",
query: `
2022-11-26 06:43:15 +00:00
mutation doDailyClick($clicks: Int!) {
dailyClick(clicks: $clicks) {
id
...Profile
__typename
}
}
fragment Profile on Profile {
tcid
clicks
totalClicks
dailyClicks
claimedGift
currentGift
receivedServerGift
subMissions
claimedDailyGift
date
item {
id
name
type
image
limitation
currentClaimed
__typename
}
sentWish
__typename
}
`,
2023-08-21 18:28:47 +00:00
variables: {
clicks: amount,
},
}),
});
if (!rsp.ok) {
throw `Failed to post click request with amount ${amount}`;
}
2022-11-26 06:43:15 +00:00
}
async function main() {
2023-08-21 18:28:47 +00:00
console.log("Fetching user information...");
let user;
try {
user = await getCurrentUser();
} catch (e) {
console.error(e);
return;
}
console.log(`Hello, ${user.name}!`);
console.log("Calculating remaining clicks needed...");
const clicksNeeded = 1000 - user.profile.dailyClicks;
if (clicksNeeded == 0) {
console.warn("You've already clicked enough for a day :D");
return;
}
console.log(`Clicks needed: ${clicksNeeded}`);
console.log("Sending click request...");
try {
postClick(clicksNeeded);
} catch (e) {
console.error(e);
return;
}
console.log("Success! Please reload page to see the changes.");
2022-11-26 06:43:15 +00:00
}
2023-08-21 18:28:47 +00:00
main();