-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuy.js
132 lines (112 loc) · 4.35 KB
/
Buy.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
(function() {
console.log("Script started.");
// The values you want to type (ensure they're within min/max)
const valueStr = "2000"; // For :r1: (tedad)
const priceValue = "3000"; // For :r2: (price)
// Interval delay (milliseconds)
const INTERVAL_MS = 350;
// How long to run before automatically stopping (milliseconds)
const STOP_AFTER = 7000;
// A helper to emulate typing character by character
function emulateTyping(element, text) {
element.focus();
let currentValue = "";
const nativeSetter = Object.getOwnPropertyDescriptor(
window.HTMLInputElement.prototype,
"value"
).set;
// Clear existing value
nativeSetter.call(element, "");
for (let i = 0; i < text.length; i++) {
const char = text[i];
// keydown & keypress
element.dispatchEvent(
new KeyboardEvent("keydown", { key: char, bubbles: true, cancelable: true })
);
element.dispatchEvent(
new KeyboardEvent("keypress", { key: char, bubbles: true, cancelable: true })
);
// Append the character
currentValue += char;
nativeSetter.call(element, currentValue);
// Dispatch 'input' so the framework detects the updated value
element.dispatchEvent(new InputEvent("input", { data: char, bubbles: true }));
// keyup
element.dispatchEvent(
new KeyboardEvent("keyup", { key: char, bubbles: true, cancelable: true })
);
}
// Finally, dispatch 'change', then blur
element.dispatchEvent(new Event("change", { bubbles: true }));
element.blur();
element.dispatchEvent(new Event("blur", { bubbles: true }));
}
// Checks if a proposed value is within the input's min/max range
function isWithinRange(inputEl, desiredValue) {
const minVal = parseFloat(inputEl.getAttribute("min"));
const maxVal = parseFloat(inputEl.getAttribute("max"));
// Remove commas if your desiredValue has them
const numericValue = parseFloat(desiredValue.replace(/,/g, ""));
if ((isNaN(minVal) && isNaN(maxVal)) || isNaN(numericValue)) {
return true; // No min/max set or invalid numericValue → allow
}
if (!isNaN(minVal) && numericValue < minVal) {
console.log(`Value ${numericValue} is below the minimum ${minVal}.`);
return false;
}
if (!isNaN(maxVal) && numericValue > maxVal) {
console.log(`Value ${numericValue} is above the maximum ${maxVal}.`);
return false;
}
return true;
}
// Select inputs by their IDs (with colons)
const valueInput = document.getElementById(":r1:"); // tedad
const priceInput = document.getElementById(":r2:"); // price
if (!valueInput) {
console.log("Value input (:r1:) not found.");
return;
}
if (!priceInput) {
console.log("Price input (:r2:) not found.");
return;
}
// We store our auto-stop timeout ID so we can clear it if we stop early
const autoStopId = setTimeout(() => stopAll("Script ended after time limit."), STOP_AFTER);
// Repeatedly set values & click the buy button
const intervalId = setInterval(() => {
// 1) Check valueInput range
if (!isWithinRange(valueInput, valueStr)) {
// Stop script and clear the auto-stop (so we don't see "time limit" message later)
clearTimeout(autoStopId);
stopAll("Value is out of range. Stopping script.");
return;
}
emulateTyping(valueInput, valueStr);
console.log(`Typed "${valueStr}" into input (:r1:).`);
// 2) Check priceInput range
if (!isWithinRange(priceInput, priceValue)) {
// Stop script and clear the auto-stop (so we don't see "time limit" message later)
clearTimeout(autoStopId);
stopAll("Price value is out of range. Stopping script.");
return;
}
emulateTyping(priceInput, priceValue);
console.log(`Typed "${priceValue}" into price input (:r2:).`);
// 3) Click the Buy button
const buyButton = document.querySelector("button.online-tools-13rpnxo");
if (buyButton) {
buyButton.click();
console.log("Buy button clicked.");
} else {
console.log("Buy button not found.");
}
}, INTERVAL_MS);
function stopAll(message) {
// Stop the interval
clearInterval(intervalId);
// Log/alert
console.log(message);
alert(message);
}
})();