-
Notifications
You must be signed in to change notification settings - Fork 7
/
ig.js
171 lines (157 loc) · 8.31 KB
/
ig.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
require('dotenv').config();
const fs = require('fs');
const puppeteer = require('puppeteer-extra');
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
puppeteer.use(StealthPlugin());
const { r, log, logD, device, badAccounts, r15, r23, win } = require('./src/helpers');
const { memeAccounts } = require('./src/accountList.js');
(async () => {
try {
//----initialize
const browser = await puppeteer.launch({ headless: false, args: ['--window-size=1920,1047', '--window-position=0,0', '--start-in-incognito'] });
const page = await browser.newPage();
await page.emulate(device);
//----login
await page.goto('https://www.instagram.com/accounts/login/?source=auth_switcher', { waitUntil: 'networkidle2' });
await page.waitForSelector("input[name='username']");
await page.tap("input[name='username']");
await page.type("input[name='username']", process.env.DKS, { delay: r(50, 100) });
await page.type("input[name='password']", process.env.PW, { delay: r(50, 100) });
await Promise.all([page.waitForNavigation({ waitUntil: 'networkidle2' }), page.tap("[type='submit']")]);
await page.waitForTimeout(r15);
// //----click no notifications
// const notifyBtn = await page.$x('//*[contains(text(), "Not Now")]');
// if (notifyBtn) {
// await Promise.all([page.waitForNavigation({ waitUntil: 'networkidle2' }), notifyBtn[0].tap()]);
// await page.waitForTimeout(r15);
// }
// //----click no to homescreen
// const cancelBtn = await page.$x('//*[contains(text(), "Cancel")]');
// if (cancelBtn) {
// await cancelBtn[0].tap();
// await page.waitForTimeout(r15);
// }
//----- Close the 'use the App' button
// const closeBtn = await page.$x('//*[@aria-label="Close"]');
// if (closeBtn) {
// await closeBtn[0].tap();
// await page.waitForTimeout(r15);
// }
//---- got to home and screenshot the follower count
await page.goto('https://www.instagram.com/' + process.env.DKS, { waitUntil: 'networkidle2' });
await page.waitForTimeout(r15);
const user = await page.$eval('h1', use => use.innerText);
const flws = await page.$$eval('a[href$="/followers/"]', flw => flw.map(fl => fl.children[0].innerText.replace(`\nfollowers`, ``)));
const flwg = await page.$$eval('a[href$="/following/"]', flg => flg.map(fg => fg.children[0].innerText.replace(`\nfollowing`, ``)));
log(`\n${user} Followers: ${flws} Following: ${flwg}`);
//----go to one of the target accounts
let farmAccount = await memeAccounts[r(0, memeAccounts.length)];
await page.goto(farmAccount, { waitUntil: 'networkidle2' });
log(`Farming this Acct: ${farmAccount}`);
await page.waitForTimeout(r15);
// await page.keyboard.press('PageDown');
// await page.waitForTimeout(r15);
// await page.keyboard.press('PageDown');
// await page.waitForTimeout(r15);
//----goto one random post
// let postHrefs = await page.$$eval('a[href^="/p/"]', href => href.map(hre => hre.getAttribute('href')));
// if (postHrefs) {
// let rPost = r(1, postHrefs.length);
// await page.goto('https://www.instagram.com' + postHrefs[rPost], { waitUntil: 'networkidle2' });
// log(`Getting Likers of photo #${rPost} href: ` + (await page.url()));
// await page.waitForTimeout(r15);
// }
//----click the Likes number on the photo
let followersBtn = await page.$('[href$="followers/"]'); // $x('//*[contains(@href, "/liked_by/")]')
if (followersBtn) {
await Promise.all([page.waitForNavigation({ waitUntil: 'networkidle2' }), page.tap('a[href$="followers/"]')]);
await page.waitForTimeout(r15);
}
//---- get all them likers
let followersH1 = await page.$x('//h1[contains(text(), "Followers")]');
if (followersH1) {
//----pagedown 20 times = 90 followers
for (let i = 0; i < 30; i++) {
await page.keyboard.press('PageDown');
await page.waitForTimeout(r(111, 333));
}
}
// ---- get only public likers posts -----///// 'div.RR-M-.h5uC0' or '$x('//*[@aria-disabled="false"]')
let publicHrefs = await page.$$eval('div[aria-disabled="false"]', pub => pub.map(pu => pu.parentNode.parentNode.nextSibling.children[0].children[0].children[0].children[0].getAttribute('href')));
log(`Array of ${publicHrefs.toString()}`);
log(`Array of ${publicHrefs.length} active users created`);
await page.waitForTimeout(r15);
//--- loop over each profile [y]-timeslet rNum = r();
let rNum = r(19, 21);// ♻♻♻♻♻♻♻♻♻♻♻♻♻♻♻♻♻♻♻♻♻♻♻♻♻
log(`Engaging ${rNum} users this round`);
if (publicHrefs) {
for (let x = 0; x < rNum; x++) {
await page.goto('https://www.instagram.com' + publicHrefs[x], { waitUntil: 'networkidle0' }); //>>>>>>>> USER WITH ZERO POSTS >>>>>'https://www.instagram.com/jasminee.hampton/'
await page.waitForTimeout(r15);
await page.waitForSelector('h1', { visible: true });
let currentURL = await page.url();
let searchBool = badAccounts.includes(currentURL);
let postCount = await page.$x('//*[contains(text(), "No Posts Yet")]');
if (postCount.length === 0) {
if (!searchBool) {
// view their story
let viewStoryBtn = await page.$('[aria-disabled="false"]');
if (viewStoryBtn) {
await Promise.all([page.waitForNavigation({ waitUntil: 'networkidle2' }), page.tap('[aria-disabled="false"]')]);
await page.waitForTimeout(r(3000, 5000));
log(` ★ ${x} viewing this story ` + await page.url());
let closeBtn = await page.$('[aria-label="Close"]');
if (closeBtn.length === 1) {
await Promise.all([page.waitForNavigation({ waitUntil: 'networkidle2' }), page.tap('[aria-label="Close"]')]);
await page.waitForTimeout(r15);
} else {
await page.goBack({ waitUntil: 'networkidle2' }); // >>>>>>>> USER WITH ZERO POSTS >>>>>'https://www.instagram.com/jasminee.hampton/'
await page.waitForTimeout(r15);
}
//----- get top 24 posts
let posts = await page.$$eval('a[href^="/p/"]', hrefs => hrefs.map(ref => ref.getAttribute('href')));// let posts = await page.$x('//*[@class="FFVAD"]');
if (posts) {
//---- pick a post to like
let p = r(0, posts.length);
//----click One random Public post to like
await page.goto('https://www.instagram.com' + posts[p], { waitUntil: 'networkidle2' });
await page.waitForTimeout(r15);
await page.waitForSelector('svg[aria-label="More options"]');
//----the Like button to hit // await Promise.all([page.waitForNavigation({ waitUntil: 'networkidle2' }), posts[p].tap()]);
let likeBtn = await page.$x('//*[@aria-label="Like"]');
if (likeBtn) {
//----Smash that Like btn
log(` ♥ Liked post number ${p} ` + (await page.url()));
await page.waitForTimeout(r(500, 1000));
await likeBtn[1].tap();
await page.waitForTimeout(r(500, 1000));
//add comment method one
// const commentURL = (await page.url()) + 'comments/';
// await page.goto(commentURL, { waitUntil: 'networkidle2' });
// await page.waitForTimeout(r15);
// await page.tap('textarea.Ypffh');
// await page.waitForTimeout(r15);
// const thisComment = memeComments[r(0, memeComments.length)];
// logD(` ✎ Comment: ${thisComment}\n`);
// await page.type('textarea.Ypffh', thisComment);
// await page.waitForTimeout(r15);
// const postBTN = await page.$x('//button[contains(text(), "Post")]');
// if (postBTN) {
// await postBTN[0].tap();
// await page.waitForTimeout(r15);
// }
}
}
}
}
}
}
}
//BACK AND CLOSE BROWSER
await browser.close();
//process.exit(1);
} catch (e) {
console.log(`--ERROR--ERROR--ERROR--ERROR\n${e}\nERROR--ERROR--ERROR--ERROR`);
//process.exit(1);
}
})();