forked from tegal1337/YOMEN
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
125 lines (112 loc) · 4.02 KB
/
main.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
const puppeteer = require("puppeteer-extra");
const StealthPlugin = require("puppeteer-extra-plugin-stealth");
const config = require("./config");
puppeteer.use(StealthPlugin());
var keyword = config.keywords;
const browserconfig = {
//defaultViewport: null,
// devtools: true,
headless: false,
executablePath: "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe",
args: ["--mute-audio"],
};
async function startApp() {
const browser = await puppeteer.launch(browserconfig);
const page = await browser.newPage();
await page.setViewport({ width: 1366, height: 768 });
await page.setUserAgent(
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"
);
await page.goto("https://accounts.google.com/");
await page.waitForSelector("#identifierId");
await page.type("#identifierId", config.usernamegoogle, { delay: 100 });
await page.waitForTimeout(1000);
await page.keyboard.press("Enter");
await page.waitForTimeout(5000);
await page.type("input", config.passwordgoogle, { delay: 100 });
await page.keyboard.press("Enter");
await page.waitForTimeout(10000);
console.log("=========== Waiting ==============")
await page.goto("https://www.youtube.com/channel/UC20YDKoLPR9OtsetXX0rnKQ");
let element = await page.$('#subscribe-button');
await page.waitForTimeout(10000);
let value = await page.evaluate(el => el.textContent, element)
console.log(value)
try {
await page.evaluate(() => {
document.querySelector("#subscribe-button > ytd-subscribe-button-renderer > tp-yt-paper-button > yt-formatted-string").click();
})
} catch (error) {
console.error(error)
}
console.log("=========== Start Commenting ==============")
await page.waitForTimeout(7000);
await page.goto("https://www.youtube.com/results?search_query=" + keyword);
await page.bringToFront();
await page.evaluate(() => {
window.scrollBy(0, 500);
});
await page.waitForTimeout(7000);
const linked = await page.$$("#video-title");
console.log(Object.keys(linked));
var link = linked.filter(function (el) {
return el != null;
});
console.log("Jumlah Link : ", link.length);
for (i in link) {
const tweet = await await (await link[i].getProperty("href")).jsonValue();
console.log(tweet);
const pages = await browser.newPage();
try {
await pages.goto(tweet);
await pages.bringToFront();
await page.waitForTimeout(4000);
await pages.evaluate(() => {
window.scrollBy(0, 650);
});
try {
await pages.waitForSelector("#message > span", { timeout: 4000 });
console.log("Gabisa Comment");
await pages.close();
} catch {
await pages.waitForSelector("#simplebox-placeholder", {
timeout: 30000,
});
await pages.evaluate(() => {
function makeid(length) {
var result = [];
var characters =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var charactersLength = characters.length;
for (var i = 0; i < length; i++) {
result.push(
characters.charAt(Math.floor(Math.random() * charactersLength))
);
}
return result.join("");
}
document.querySelector("#simplebox-placeholder").click();
document.querySelector("div[id='contenteditable-root']").innerHTML =
"Hello Subscribe my channel";
console.log(
document.querySelector("div[id='contenteditable-root']").innerHTML
);
});
pages.keyboard.press("Enter");
await pages.evaluate(() => {
document.querySelector("#submit-button").click();
});
await page.waitForTimeout(4000);
await pages.close();
console.log("Sukses Comment");
}
} catch {
await pages.close();
console.log("Gabisa Dibuka link ytnya");
}
}
console.log("Sudah Comment ke semua Video !");
await page.close();
process.exit();
}
startApp();