Skip to content

Instantly share code, notes, and snippets.

@stepney141
Last active March 31, 2024 17:04
Show Gist options
  • Save stepney141/060f7e3b2e8255299d014162be3866ec to your computer and use it in GitHub Desktop.
Save stepney141/060f7e3b2e8255299d014162be3866ec to your computer and use it in GitHub Desktop.
popcat.click を無限に自動クリックする(bot検知回避済み)
import { executablePath } from "puppeteer";
import puppeteer from "puppeteer-extra";
import AdblockerPlugin from "puppeteer-extra-plugin-adblocker";
import StealthPlugin from "puppeteer-extra-plugin-stealth";
import { sleep } from "./.libs/utils";
import type { ElementHandle } from "puppeteer";
const adblockerPlugin = AdblockerPlugin();
const stealthPlugin = StealthPlugin();
/* ref:
- https://github.com/berstend/puppeteer-extra/issues/668
- https://github.com/berstend/puppeteer-extra/issues/822
*/
stealthPlugin.enabledEvasions.delete("iframe.contentWindow");
stealthPlugin.enabledEvasions.delete("navigator.plugins");
stealthPlugin.enabledEvasions.delete("media.codecs");
puppeteer.use(stealthPlugin).use(adblockerPlugin);
(async () => {
try {
const browser = await puppeteer.launch({
executablePath: executablePath(),
args: [
"--disable-blink-features=AutomationControlled" /* https://github.com/berstend/puppeteer-extra/issues/822 */,
"--mute-audio"
],
headless: false
});
const XPATH = '//*[@id="app"]/div';
let cnt = 0;
let wait = 10;
const page = await browser.newPage();
// await page.setRequestInterception(true);
// page.on("request", (interceptedRequest) => {
// (async () => {
// if (interceptedRequest.url().includes("https://leaderboard.popcat.click/") || interceptedRequest.url().endsWith("png") || interceptedRequest.url().endsWith("jpg")) {
// await interceptedRequest.abort();
// } else {
// await interceptedRequest.continue();
// }
// })();
// });
await page.goto("https://popcat.click/", {
waitUntil: ["domcontentloaded", "load"]
});
const eh = (await page.$x(XPATH)) as ElementHandle<Element>[];
for (;;) {
await eh[0].click({
clickCount: 1
});
await sleep(wait);
cnt++;
console.log(`clicked ${cnt} times`);
if (BigInt(cnt) % 1000n === 0n) {
if (Math.floor(Math.random() + 0.05)) {
wait += 0.1;
console.log("wait: + 1ms");
}
console.log("sleeping for 10s...");
console.log(`current wait: ${wait}ms`);
await sleep(10000);
}
if (BigInt(cnt) % 10000n === 0n) {
if (Math.floor(Math.random() + 0.05)) {
wait += 1;
console.log("wait: + 1ms");
}
console.log("sleeping for 20s...");
console.log(`current wait: ${wait}ms`);
await sleep(20000);
}
if (BigInt(cnt) % 100000n === 0n) {
console.log("sleeping for 20s...");
await sleep(20000);
}
}
} catch (e) {
console.log(e);
process.exit(1);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment