-
Notifications
You must be signed in to change notification settings - Fork 0
/
clayton.js
168 lines (148 loc) · 7.03 KB
/
clayton.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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// ==UserScript==
// @name Clayton Autoclicker for Stack Game
// @version 1.2
// @author xorascs
// @match https://tonclayton.fun/*
// @downloadURL https://github.com/xorascs/Clayton/raw/main/clayton.js
// @updateURL https://github.com/xorascs/Clayton/raw/main/clayton.js
// @homepage https://github.com/xorascs/Clayton
// @grant none
// ==/UserScript==
(function() {
'use strict';
var gameClicksCount = 200;
// Simulate an event
function simulateEvent(element, eventType, eventData) {
const event = new PointerEvent(eventType, {
isTrusted: true,
bubbles: true,
cancelable: true,
pointerId: eventData.pointerId || 1,
width: eventData.width || 1,
height: eventData.height || 1,
pressure: eventData.pressure || 0.5,
clientX: eventData.clientX || 0,
clientY: eventData.clientY || 0,
screenX: eventData.screenX || 0,
screenY: eventData.screenY || 0,
});
element.dispatchEvent(event);
}
// Simulate click on the canvas
async function simulateMouseClickOnCanvas() {
try {
const canvas = document.querySelector('#root > div > div.game-layout > div > div > div:nth-child(1) > div > canvas');
const gameSessionDiv = document.querySelector('div.go4109123758 > div > span');
const loadingDiv = document.querySelector('div.greeting');
const doubleReward = document.querySelector('div[class="block-reward-multiply channel"] > div:nth-child(4)');
const continueGame = document.querySelector('div.tap-to-restart');
const clicksCountElement = document.querySelector('div.game_stats > div');
const clicksCount = isNaN(Number(clicksCountElement?.innerText)) ? 0 : Number(clicksCountElement.innerText);
const attemptsCount = Number(document.querySelector('div.info-attempts').children[1].innerText ? document.querySelector('div.info-attempts').children[1].innerText : 0);
const timer = document.querySelector('p.stack_timer');
if (attemptsCount == 0 && !timer) {
console.log('You do not have enough attempts!');
return;
}
if (continueGame) {
if (doubleReward) {
doubleReward.click();
setTimeout(() => {
continueGame.click();
}, getRandomDelay(900, 1500));
console.log("Clicked on double reward.")
}
else {
continueGame.click();
}
console.log("Clicked on restart button.")
}
if (loadingDiv && !gameSessionDiv?.textContent.includes("error")) {
console.log(`Simulating first click.`);
gameClicksCount = Math.floor(Math.random() * (155 - 85) + 85);
console.log("Clicks count for this game is " + gameClicksCount);
// Define the position for the click
let eventData = {
screenX: 396,
screenY: 640,
clientX: 227,
clientY: 90,
pressure: 0.5,
pointerId: 1
};
simulateEvent(canvas, 'pointerdown', eventData);
simulateEvent(canvas, 'mousedown', eventData);
simulateEvent(canvas, 'pointermove', eventData);
simulateEvent(canvas, 'mousemove', eventData);
simulateEvent(canvas, 'pointerup', { ...eventData, pressure: 0 });
simulateEvent(canvas, 'mouseup', { ...eventData, pressure: 0 });
simulateEvent(canvas, 'click', { ...eventData, pressure: 0 });
clearInterval(autoClickerInterval);
setTimeout(() => {
autoClickerInterval = setInterval(simulateMouseClickOnCanvas, getRandomDelay(770, 800));
}, getRandomDelay(300, 500));
}
if (canvas && !gameSessionDiv?.textContent.includes("error") && !loadingDiv) {
if (gameClicksCount > clicksCount) {
console.log(`1. Simulating click. ${gameClicksCount} ${clicksCount}`);
// Define the position for the click
let eventData = {
screenX: 396,
screenY: 640,
clientX: 227,
clientY: 90,
pressure: 0.5,
pointerId: 1
};
simulateEvent(canvas, 'pointerdown', eventData);
simulateEvent(canvas, 'mousedown', eventData);
simulateEvent(canvas, 'pointermove', eventData);
simulateEvent(canvas, 'mousemove', eventData);
simulateEvent(canvas, 'pointerup', { ...eventData, pressure: 0 });
simulateEvent(canvas, 'mouseup', { ...eventData, pressure: 0 });
simulateEvent(canvas, 'click', { ...eventData, pressure: 0 });
}
else {
console.log(`2. Simulating click. ${gameClicksCount} ${clicksCount}`);
setTimeout(() => {
// Define the position for the click
let eventData = {
screenX: 396,
screenY: 640,
clientX: 227,
clientY: 90,
pressure: 0.5,
pointerId: 1
};
simulateEvent(canvas, 'pointerdown', eventData);
simulateEvent(canvas, 'mousedown', eventData);
simulateEvent(canvas, 'pointermove', eventData);
simulateEvent(canvas, 'mousemove', eventData);
simulateEvent(canvas, 'pointerup', { ...eventData, pressure: 0 });
simulateEvent(canvas, 'mouseup', { ...eventData, pressure: 0 });
simulateEvent(canvas, 'click', { ...eventData, pressure: 0 });
},1000);
}
} else if (gameSessionDiv?.textContent.includes("error")) {
console.log('Auto clicker paused for 2-3 minutes due to active game session.');
clearInterval(autoClickerInterval);
setTimeout(() => {
autoClickerInterval = setInterval(simulateMouseClickOnCanvas, getRandomDelay(770, 800));
}, getRandomDelay(120000, 180000));
}
} catch (err) {console.log(err)}
}
// Generate random delay
function getRandomDelay(min, max) {
return Math.random() * (max - min) + min;
}
// Start the autoclicker process
setInterval(() => {
if (document.querySelector('button.daily-reward-button-primary')) {
document.querySelector('button.daily-reward-button-primary').click();
location.reload();
}
},3000);
// Start the autoclicker process with the first click delay
let autoClickerInterval = setInterval(simulateMouseClickOnCanvas, getRandomDelay(770, 800));
})();