instauto 9.1.4 → 9.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.js +21 -8
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -45,6 +45,8 @@ const Instauto = async (db, browser, options) => {
|
|
|
45
45
|
followUserMinFollowers = null,
|
|
46
46
|
followUserMinFollowing = null,
|
|
47
47
|
|
|
48
|
+
shouldFollowUser = null,
|
|
49
|
+
|
|
48
50
|
dontUnfollowUntilTimeElapsed = 3 * 24 * 60 * 60 * 1000,
|
|
49
51
|
|
|
50
52
|
excludeUsers = [],
|
|
@@ -168,11 +170,14 @@ const Instauto = async (db, browser, options) => {
|
|
|
168
170
|
return new Date().getTime() - followedUserEntry.time < dontUnfollowUntilTimeElapsed;
|
|
169
171
|
}
|
|
170
172
|
|
|
173
|
+
// See https://github.com/mifi/SimpleInstaBot/issues/140#issuecomment-1149105387
|
|
174
|
+
const gotoUrl = async (url) => page.goto(url, { waitUntil: ['load', 'domcontentloaded', 'networkidle0'] });
|
|
175
|
+
|
|
171
176
|
async function gotoWithRetry(url) {
|
|
172
177
|
const maxAttempts = 3;
|
|
173
178
|
for (let attempt = 0; ; attempt += 1) {
|
|
174
179
|
logger.log(`Goto ${url}`);
|
|
175
|
-
const response = await
|
|
180
|
+
const response = await gotoUrl(url);
|
|
176
181
|
await sleep(2000);
|
|
177
182
|
const status = response.status();
|
|
178
183
|
|
|
@@ -319,9 +324,15 @@ const Instauto = async (db, browser, options) => {
|
|
|
319
324
|
const elementHandles3 = await page.$x("//header//button[*//span[@aria-label='Following']]");
|
|
320
325
|
if (elementHandles3.length > 0) return elementHandles3[0];
|
|
321
326
|
|
|
322
|
-
const elementHandles4 = await page.$x("//header//button[
|
|
327
|
+
const elementHandles4 = await page.$x("//header//button[*//span[@aria-label='Requested']]");
|
|
323
328
|
if (elementHandles4.length > 0) return elementHandles4[0];
|
|
324
329
|
|
|
330
|
+
const elementHandles5 = await page.$x("//header//button[*//*[name()='svg'][@aria-label='Following']]");
|
|
331
|
+
if (elementHandles5.length > 0) return elementHandles5[0];
|
|
332
|
+
|
|
333
|
+
const elementHandles6 = await page.$x("//header//button[*//*[name()='svg'][@aria-label='Requested']]");
|
|
334
|
+
if (elementHandles6.length > 0) return elementHandles6[0];
|
|
335
|
+
|
|
325
336
|
return undefined;
|
|
326
337
|
}
|
|
327
338
|
|
|
@@ -551,7 +562,7 @@ const Instauto = async (db, browser, options) => {
|
|
|
551
562
|
|
|
552
563
|
await window.instautoSleep(3000);
|
|
553
564
|
|
|
554
|
-
const closeButtonChild = document.querySelector('
|
|
565
|
+
const closeButtonChild = document.querySelector('svg[aria-label="Close"]');
|
|
555
566
|
|
|
556
567
|
if (!closeButtonChild) throw new Error('Close button not found (aria-label)');
|
|
557
568
|
|
|
@@ -594,9 +605,7 @@ const Instauto = async (db, browser, options) => {
|
|
|
594
605
|
|
|
595
606
|
const graphqlUser = await navigateToUserAndGetData(username);
|
|
596
607
|
|
|
597
|
-
const followedByCount = graphqlUser
|
|
598
|
-
const followsCount = graphqlUser.edge_follow.count;
|
|
599
|
-
const isPrivate = graphqlUser.is_private;
|
|
608
|
+
const { edge_followed_by: { count: followedByCount }, edge_follow: { count: followsCount }, is_private: isPrivate, is_verified: isVerified, is_business_account: isBusinessAccount, is_professional_account: isProfessionalAccount, full_name: fullName, biography, profile_pic_url_hd: profilePicUrlHd, external_url: externalUrl, business_category_name: businessCategoryName, category_name: categoryName } = graphqlUser;
|
|
600
609
|
|
|
601
610
|
// logger.log('followedByCount:', followedByCount, 'followsCount:', followsCount);
|
|
602
611
|
|
|
@@ -622,6 +631,10 @@ const Instauto = async (db, browser, options) => {
|
|
|
622
631
|
logger.log('User has too many followers compared to follows or opposite, skipping');
|
|
623
632
|
return false;
|
|
624
633
|
}
|
|
634
|
+
if (shouldFollowUser !== null && (typeof shouldFollowUser === 'function' && !shouldFollowUser({ username, isVerified, isBusinessAccount, isProfessionalAccount, fullName, biography, profilePicUrlHd, externalUrl, businessCategoryName, categoryName }) === true)) {
|
|
635
|
+
logger.log(`Custom follow logic returned false for ${username}, skipping`);
|
|
636
|
+
return false;
|
|
637
|
+
}
|
|
625
638
|
|
|
626
639
|
await followUser(username);
|
|
627
640
|
|
|
@@ -791,7 +804,7 @@ const Instauto = async (db, browser, options) => {
|
|
|
791
804
|
|
|
792
805
|
if (enableCookies) await tryLoadCookies();
|
|
793
806
|
|
|
794
|
-
const goHome = async () =>
|
|
807
|
+
const goHome = async () => gotoUrl(`${instagramBaseUrl}/?hl=en`);
|
|
795
808
|
|
|
796
809
|
// https://github.com/mifi/SimpleInstaBot/issues/28
|
|
797
810
|
async function setLang(short, long, assumeLoggedIn = false) {
|
|
@@ -803,7 +816,7 @@ const Instauto = async (db, browser, options) => {
|
|
|
803
816
|
// when logged in, we need to go to account in order to be able to check/set language
|
|
804
817
|
// (need to see the footer)
|
|
805
818
|
if (assumeLoggedIn) {
|
|
806
|
-
await
|
|
819
|
+
await gotoUrl(`${instagramBaseUrl}/accounts/edit/`);
|
|
807
820
|
} else {
|
|
808
821
|
await goHome();
|
|
809
822
|
}
|