-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaws.user.js
More file actions
102 lines (85 loc) · 3.56 KB
/
paws.user.js
File metadata and controls
102 lines (85 loc) · 3.56 KB
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
// ==UserScript==
// @name Paws
// @namespace Violentmonkey Scripts
// @grant none
// @version 1.0
// @author -
// @description 9/1/2024, 7:13:21 PM
// @match *://*paws.community/*
// @downloadURL https://github.com/vsotreshko/bug-free-happiness/raw/main/paws.user.js
// @updateURL https://github.com/vsotreshko/bug-free-happiness/raw/main/paws.user.js
// ==/UserScript==
const delay = (ms) => new Promise((res) => setTimeout(res, ms));
const waitForElement = async (document, selector) => {
console.warn(`Waiting for: ${selector}`);
return new Promise((resolve) => {
if (document.querySelector(selector)) {
console.warn(`waitForElement: found ${selector} immediately`);
return resolve(document.querySelector(selector));
}
const observer = new MutationObserver((mutations) => {
if (document.querySelector(selector)) {
console.warn(`waitForElement: found ${selector} after DOM changed`);
resolve(document.querySelector(selector));
observer.disconnect();
}
});
observer.observe(document.body, {
childList: true,
subtree: true,
});
// Resolve promise after 10 seconds if element is not found
setTimeout(() => {
console.warn(`waitForElement: ${selector} not found after 10 seconds`);
observer.disconnect();
resolve(null);
}, 10000);
});
};
const iterateOverTasks = async (document) => {
const dontResolve = ["connect wallet", "invite 10 friends", "boost paws channel", "follow channel"];
const questsListSelector =
"#next-app > div.main-page-con > div.main-content-container.is-show > div.main-content-wrapper > div.quests-tab-con.is-show > div > div.section-items-con.quests";
const questsList = await waitForElement(document, questsListSelector);
const elements = questsList.querySelectorAll(".invite-item");
for (const quest of elements) {
const text = quest.querySelector(".wallet");
const shouldntProcess = dontResolve.find((code) => code === text.textContent.trim().toLowerCase());
if (!shouldntProcess) {
const button = quest.querySelector(".start-btn");
if (button) {
await delay(2000);
button.click();
}
}
}
};
const resolveEarn = async (document) => {
console.log("Resolving earn");
const earnTabSelector =
"#next-app > div.main-page-con > div.main-content-container.is-show > div.nav-bar-con > div:nth-child(4)";
const earnTab = await waitForElement(document, earnTabSelector);
earnTab.click();
await iterateOverTasks(document); // Start
await iterateOverTasks(document); // Check
await iterateOverTasks(document); // Claim
const inGameTabSelector =
"#next-app > div.main-page-con > div.main-content-container.is-show > div.main-content-wrapper > div.quests-tab-con.is-show > div > div.type-select > div:nth-child(2)";
const inGameTab = await waitForElement(document, inGameTabSelector);
inGameTab.click();
await iterateOverTasks(document); // Start
await iterateOverTasks(document); // Check
await iterateOverTasks(document); // Claim
const partnersTabSelector =
"#next-app > div.main-page-con > div.main-content-container.is-show > div.main-content-wrapper > div.quests-tab-con.is-show > div > div.type-select > div:nth-child(3)";
const partnersTab = await waitForElement(document, partnersTabSelector);
partnersTab.click();
await iterateOverTasks(document); // Start
await iterateOverTasks(document); // Check
await iterateOverTasks(document); // Claim
};
const init = async () => {
await delay(10000);
await resolveEarn(document);
};
init();