aov: add apl2022 click script

This commit is contained in:
tretrauit 2022-11-26 13:43:15 +07:00
parent b48dc9ba6f
commit d753bee5e3
No known key found for this signature in database
GPG Key ID: CDDE1C97EE305DAF
14 changed files with 207 additions and 0 deletions

View File

@ -36,6 +36,7 @@ cd ~
git clone https://github.com/NetrisTV/ws-scrcpy
cd ./ws-scrcpy
npm install
cd ..
curl -OL https://gitlab.com/tretrauit/scripts/-/raw/main/Apps/ws-scrcpy/ws-scrcpy-launcher.py
chmod +x ws-scrcpy-launcher.py
```

View File

@ -0,0 +1,139 @@
if (!window.location.href.startsWith("https://apl2022.lienquan.garena.vn")) {
console.error("This script is for https://apl2022.lienquan.garena.vn only.");
}
async function getCurrentUser() {
const rsp = await fetch('/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
operationName: "getUser",
query: `
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
}
`,
variables: {},
}),
})
if (!rsp.ok) {
throw `Failed to get current user info`
}
return (await rsp.json()).data.getUser;
}
async function postClick(amount) {
const rsp = await fetch('/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
operationName: "doDailyClick",
query: `
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
}
`,
variables: {
clicks: amount,
},
}),
})
if (!rsp.ok) {
throw `Failed to post click request with amount ${amount}`
}
}
async function main() {
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.");
}
main()

View File

@ -0,0 +1,67 @@
// ==UserScript==
// @name Dynamic Sidebar
// @namespace tretrauit-dev
// @match *://www.messenger.com
// @icon https://genshin.hoyoverse.com/favicon.ico
// @grant none
// @version 1.0
// @author tretrauit
// @description Dynamic Sidebar for Facebook Messenger (messenger.com)
// @homepageURL https://gitlab.com/tretrauit/scripts
// @supportURL https://gitlab.com/tretrauit/scripts/-/issues
// @downloadURL https://gitlab.com/tretrauit/scripts/-/raw/main/userscripts/messenger-dynamic-sidebar.user.js
// ==/UserScript==
function injectCSS(css) {
const style = document.createElement('style');
style.appendChild(document.createTextNode(css));
document.head.appendChild(style);
}
function findElement(tag, properties) {
const elements = document.querySelectorAll(tag);
elementLoop:
for (const element of elements) {
for (const [key, value] of Object.entries(properties)) {
if (element.getAttribute(key) != value) {
continue elementLoop;
}
}
return element;
}
}
function getAncestor(element, level) {
for (let i = 0; i < level; i++) {
element = element.parentNode;
}
return element;
}
console.log("Scanning class for components...");
let searchBox = findElement("input", {"aria-autocomplete": "list"});
if (searchBox != null) {
searchBox = getAncestor(searchBox, 7);
}
let textHeader = findElement("span", {"style": "line-height: 28px;"});
let header;
if (textHeader != null) {
header = getAncestor(textHeader, 7);
textHeader = textHeader.childNodes[0];
}
let unreadIndicator = findElement("span", {"data-visualcompletion": "ignore"});
let actionBar = findElement("div", {"aria-expanded": "false"});
if (actionBar != null) {
actionBar = actionBar.parentNode;
}
let chats = findElement("div", {"aria-label": "Chats"});
if (chats != null) {
chats = chats.parentNode;
}
console.log("Search box:", searchBox);
console.log("Header:", header);
console.log("Text header:", textHeader);
console.log("Unread message indicator:", unreadIndicator);
console.log("Action bar:", actionBar);
console.log("Chat tab:", chats);