forked from cicere/pumpfun-comment-bot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot.js
380 lines (325 loc) · 12.5 KB
/
bot.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
const {
Builder,
By,
Key,
until,
Actions,
WebElement,
} = require("selenium-webdriver");
const chrome = require("selenium-webdriver/chrome");
const { execSync } = require("child_process"); // For accessing the clipboard
const { connect } = require("http2");
const reply = "SUPPP";
async function run() {
const driver = await new Builder()
.forBrowser("chrome")
.setChromeOptions(new chrome.Options().addArguments("--start-maximized"))
.build();
try {
// Open the website
await driver.get(
"https://pump.fun/coin/9CEbFPQG79HX7DLoDtkScsMu1uyheDg3Pfj1nQqEpump"
); // Change to the URL of your page
// Wait for the "Ready to Pump" button to be clickable before clicking
const readyToPump = await driver.wait(
until.elementIsVisible(
driver.findElement(By.css("button[data-sentry-element='Button']"))
),
10000
);
await readyToPump.click();
console.log("clicked ready to pump");
// Wait for the "Ready to Pump" button to be clickable before clicking
const rejectCookies = await driver.wait(
until.elementIsVisible(
driver.findElement(By.xpath("/html/body/div[2]/div[1]/button[3]"))
),
10000
);
rejectCookies.click();
// Step 2: Wait for the "Connect Wallet" button to be visible and clickable
const connectWalletButton = await driver.wait(
until.elementLocated(By.xpath("/html/body/div[1]/nav/div[2]/button")),
10000
);
await connectWalletButton.click();
console.log("clicked connect wallet");
// Step 3: Wait for the wallet connection options to appear
const solflare = await driver.wait(
until.elementLocated(By.xpath("//img[@alt='Solflare']")),
10000
);
await solflare.click();
console.log("clicked Solflare");
// Step 4: Wait for the outside element (to close the dialog) to be visible and
// Step 4: Click at the bottom-right of the viewport
const viewportWidth = await driver.executeScript(
"return window.innerWidth;"
);
const viewportHeight = await driver.executeScript(
"return window.innerHeight;"
);
// Calculate coordinates for the bottom-right corner
const xOffset = viewportWidth - 10; // 10px from the right edge
const yOffset = viewportHeight - 10; // 10px from the bottom edge
// Perform the click
const actions = driver.actions({ async: true });
await actions
.move({ x: xOffset, y: yOffset, origin: "viewport" })
.click()
.perform();
console.log("Simulated click at the bottom-right of the viewport");
// Step 3: Wait for the wallet connection options to appear
try {
await driver
.switchTo()
.frame(
driver.wait(
until.elementLocated(By.xpath("/html/body/div[3]/iframe"))
)
);
console.log("switched to iframe");
await driver.sleep(3000);
// Log the HTML content inside the iframe
// Perform the click
const actions = driver.actions({ async: true });
// Show where the click will happen by adding a marker
await actions
.move({ x: 600, y: 370, origin: "viewport" })
.click()
.perform();
console.log("Simulated click at the button of the viewport");
// After clicking, check for a new pop-up window (new tab or window)
const currentWindow = await driver.getWindowHandle(); // Get the current window handle
const allHandles = await driver.getAllWindowHandles(); // Get all window handles
// Switch to the new pop-up window
const newWindowHandle = allHandles.find(
(handle) => handle !== currentWindow
);
await driver.switchTo().window(newWindowHandle); // Switch to the new window
console.log("Switched to the pop-up window");
// Add a marker at the click position
// Perform actions on the pop-up window (e.g., click a button)
const newWalletButtonInPopUp = await driver.wait(
until.elementLocated(
By.xpath("/html/body/div/div/div[2]/div/div/div[2]/div/button[1]")
), // Adjust selector for pop-up
5000
);
await newWalletButtonInPopUp.click();
console.log("New wallet selected with the pop-up");
// Perform actions on the pop-up window (e.g., click a button)
const copyButtonInPopUp = await driver.wait(
until.elementLocated(
By.xpath(
"/html/body/div/div/div[2]/div/div/div[1]/div[2]/div[3]/button[2]"
)
), // Adjust selector for pop-up
5000
);
await copyButtonInPopUp.click();
console.log("Copied recovery phrase with the pop-up");
// Perform actions on the pop-up window (e.g., click a button)
const savedRecoveryPhraseBTN = await driver.wait(
until.elementLocated(
By.xpath("/html/body/div/div/div[2]/div/div/div[2]/div/button")
), // Adjust selector for pop-up
5000
);
await savedRecoveryPhraseBTN.click();
console.log("saved my recovery phrase btn clicked with the pop-up");
const clipboardData = execSync("powershell Get-Clipboard")
.toString()
.trim(); // Windows
console.log("Copied Clipboard Data:", clipboardData);
// Actions class methods to select text
// Paste the text in the second input box
const action2 = driver.actions({ async: true });
await action2
.keyDown(Key.CONTROL) // Use Key.COMMAND on Mac
.sendKeys("v")
.keyUp(Key.CONTROL)
.perform();
console.log("Text copied and pasted successfully.");
// Perform actions on the pop-up window (e.g., click a button)
const continueBtn = await driver.wait(
until.elementLocated(
By.xpath("/html/body/div/div/div[2]/div/form/div/div[2]/div/button")
), // Adjust selector for pop-up
5000
);
await continueBtn.click();
console.log("continue btn clicked with the pop-up");
const password = "Capped$1$2$3";
const newPasswordField = await driver.wait(
until.elementLocated(
By.xpath(
"/html/body/div/div/div[2]/div/form/div/div[1]/div[2]/div[1]/div/div/div/div/input"
)
), // Adjust selector for pop-up
5000
);
const confirmPasswordField = await driver.wait(
until.elementLocated(
By.xpath(
"/html/body/div/div/div[2]/div/form/div/div[1]/div[2]/div[2]/div/div/div/div/input"
)
), // Adjust selector for pop-up
5000
);
await newPasswordField.sendKeys(password);
await confirmPasswordField.sendKeys(password);
const continueBtn2 = await driver.wait(
until.elementLocated(
By.xpath("/html/body/div/div/div[2]/div/form/div/div[2]/button")
), // Adjust selector for pop-up
5000
);
await continueBtn2.click();
//new instance
// Close the pop-up window
await driver.close();
console.log("Pop-up window closed");
// Switch back to the main window
await driver.switchTo().window(currentWindow);
console.log("Switched back to the main window");
const connectWalletButton = await driver.wait(
until.elementLocated(By.xpath("/html/body/div[1]/nav/div[2]/button")),
10000
);
await connectWalletButton.click();
console.log("clicked connect wallet");
// Step 3: Wait for the wallet connection options to appear
const solflare = await driver.wait(
until.elementLocated(By.xpath("//img[@alt='Solflare']")),
10000
);
await solflare.click();
console.log("clicked Solflare");
// Step 4: Wait for the outside element (to close the dialog) to be visible and
// Step 4: Click at the bottom-right of the viewport
const viewportWidth = await driver.executeScript(
"return window.innerWidth;"
);
const viewportHeight = await driver.executeScript(
"return window.innerHeight;"
);
// Calculate coordinates for the bottom-right corner
const xOffset = viewportWidth - 10; // 10px from the right edge
const yOffset = viewportHeight - 10; // 10px from the bottom edge
// Perform the click
const action3 = driver.actions({ async: true });
await action3
.move({ x: xOffset, y: yOffset, origin: "viewport" })
.click()
.perform();
console.log("Simulated click at the bottom-right of the viewport");
// Step 3: Wait for the wallet connection options to appear
try {
await driver
.switchTo()
.frame(
driver.wait(
until.elementLocated(By.xpath("/html/body/div[3]/iframe"))
)
);
console.log("switched to iframe");
const actions = driver.actions({ async: true });
// Show where the click will happen by adding a marker
await driver.sleep(3000);
await actions
.move({ x: 600, y: 370, origin: "viewport" })
.click()
.perform();
console.log("Simulated click at the button of the viewport");
// After clicking, check for a new pop-up window (new tab or window)
const currentWindow = await driver.getWindowHandle(); // Get the current window handle
const allHandles = await driver.getAllWindowHandles(); // Get all window handles
// Switch to the new pop-up window
const newWindowHandle = allHandles.find(
(handle) => handle !== currentWindow
);
await driver.switchTo().window(newWindowHandle); // Switch to the new window
console.log("Switched to the pop-up window");
const connectBtn = await driver.wait(
until.elementLocated(
By.xpath("/html/body/div[2]/div[2]/div/div[3]/div/button[2]")
),
10000
);
await connectBtn.click();
console.log("connectBtn clicked");
const approveBtn = await driver.wait(
until.elementLocated(
By.xpath(
"/html/body/div[2]/div[2]/div/div[2]/div/div[2]/div[3]/div/button[2]"
)
),
10000
);
await approveBtn.click();
console.log("approveBtn clicked");
// await driver.close();
// console.log("Pop-up window closed");
await driver.switchTo().window(currentWindow);
console.log("Switched back to the main window");
// Locate the target element
const targetElement = await driver.findElement(
By.xpath("/html/body/div[1]/main/div[1]/div[2]/div[1]/div[5]/div")
);
// Scroll the element into view
await driver.executeScript(
"arguments[0].scrollIntoView({ behavior: 'smooth', block: 'center' });",
targetElement
);
// Wait until the element is visible and interactable
await driver.wait(
until.elementIsVisible(targetElement),
5000,
"Element not visible after waiting"
);
// Check if the element is clickable
await driver.wait(
until.elementIsEnabled(targetElement),
5000,
"Element is not enabled for interaction"
);
// Debugging: Log details about the element's state
const rect = await driver.executeScript(
`const rect = arguments[0].getBoundingClientRect();
return { left: rect.left, top: rect.top, width: rect.width, height: rect.height };`,
targetElement
);
console.log("Element dimensions and position:", rect);
// If necessary, highlight the element for debugging
await driver.executeScript(
"arguments[0].style.border='2px solid red';",
targetElement
);
// Perform the click using JavaScript (if actions don't work)
await driver.executeScript("arguments[0].click();", targetElement);
console.log("Clicked the target element using JavaScript");
const replyTextField = await driver.wait(
until.elementLocated(By.xpath("/html/body/div[4]/div[1]/textarea")),
10000
);
await replyTextField.sendKeys(reply);
const postBtn = await driver.wait(
until.elementLocated(By.xpath("/html/body/div[4]/button")),
10000
);
await postBtn.click();
} catch (error) {
console.log("failed connecting created wallet", error);
}
} catch (error) {
console.log("Failed to switch to iframe:", error);
}
} catch (error) {
console.error("Error:", error);
} finally {
// Close the driver after the actions
// await driver.quit();
}
}
run();