instauto 7.2.1 → 7.2.2
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/index.js +24 -8
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -799,7 +799,7 @@ const Instauto = async (db, browser, options) => {
|
|
|
799
799
|
|
|
800
800
|
if (enableCookies) await tryLoadCookies();
|
|
801
801
|
|
|
802
|
-
const goHome = async () => page.goto(`${instagramBaseUrl}
|
|
802
|
+
const goHome = async () => page.goto(`${instagramBaseUrl}/?hl=en`);
|
|
803
803
|
|
|
804
804
|
// https://github.com/mifi/SimpleInstaBot/issues/28
|
|
805
805
|
async function setLang(short, long) {
|
|
@@ -829,15 +829,22 @@ const Instauto = async (db, browser, options) => {
|
|
|
829
829
|
logger.log('Found language selector');
|
|
830
830
|
|
|
831
831
|
// https://stackoverflow.com/questions/45864516/how-to-select-an-option-from-dropdown-select
|
|
832
|
-
await page.evaluate((selectElem, short2) => {
|
|
832
|
+
const alreadyEnglish = await page.evaluate((selectElem, short2) => {
|
|
833
833
|
const optionElem = selectElem.querySelector(`option[value='${short2}']`);
|
|
834
|
+
if (optionElem.selected) return true; // already selected?
|
|
834
835
|
optionElem.selected = true;
|
|
835
836
|
// eslint-disable-next-line no-undef
|
|
836
837
|
const event = new Event('change', { bubbles: true });
|
|
837
838
|
selectElem.dispatchEvent(event);
|
|
839
|
+
return false;
|
|
838
840
|
}, elementHandles[0], short);
|
|
839
|
-
logger.log('Selected language');
|
|
840
841
|
|
|
842
|
+
if (alreadyEnglish) {
|
|
843
|
+
logger.log('Already English language');
|
|
844
|
+
return;
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
logger.log('Selected language');
|
|
841
848
|
await sleep(3000);
|
|
842
849
|
await goHome();
|
|
843
850
|
await sleep(1000);
|
|
@@ -850,12 +857,12 @@ const Instauto = async (db, browser, options) => {
|
|
|
850
857
|
const setEnglishLang = async () => setLang('en', 'English');
|
|
851
858
|
// const setEnglishLang = async () => setLang('de', 'Deutsch');
|
|
852
859
|
|
|
853
|
-
async function tryPressButton(elementHandles, name) {
|
|
860
|
+
async function tryPressButton(elementHandles, name, sleepMs = 3000) {
|
|
854
861
|
try {
|
|
855
862
|
if (elementHandles.length === 1) {
|
|
856
863
|
logger.log(`Pressing button: ${name}`);
|
|
857
864
|
elementHandles[0].click();
|
|
858
|
-
await sleep(
|
|
865
|
+
await sleep(sleepMs);
|
|
859
866
|
}
|
|
860
867
|
} catch (err) {
|
|
861
868
|
logger.warn(`Failed to press button: ${name}`);
|
|
@@ -865,6 +872,8 @@ const Instauto = async (db, browser, options) => {
|
|
|
865
872
|
await setEnglishLang();
|
|
866
873
|
|
|
867
874
|
await tryPressButton(await page.$x('//button[contains(text(), "Accept")]'), 'Accept cookies dialog');
|
|
875
|
+
await tryPressButton(await page.$x('//button[contains(text(), "Only allow essential cookies")]'), 'Accept cookies dialog 2 button 1', 10000);
|
|
876
|
+
await tryPressButton(await page.$x('//button[contains(text(), "Allow essential and optional cookies")]'), 'Accept cookies dialog 2 button 2', 10000);
|
|
868
877
|
|
|
869
878
|
if (!(await isLoggedIn())) {
|
|
870
879
|
if (!myUsername || !password) {
|
|
@@ -876,7 +885,7 @@ const Instauto = async (db, browser, options) => {
|
|
|
876
885
|
await page.click('a[href="/accounts/login/?source=auth_switcher"]');
|
|
877
886
|
await sleep(1000);
|
|
878
887
|
} catch (err) {
|
|
879
|
-
logger.
|
|
888
|
+
logger.info('No login page button, assuming we are on login form');
|
|
880
889
|
}
|
|
881
890
|
|
|
882
891
|
// Mobile version https://github.com/mifi/SimpleInstaBot/issues/7
|
|
@@ -887,8 +896,15 @@ const Instauto = async (db, browser, options) => {
|
|
|
887
896
|
await page.type('input[name="password"]', password, { delay: 50 });
|
|
888
897
|
await sleep(1000);
|
|
889
898
|
|
|
890
|
-
|
|
891
|
-
|
|
899
|
+
for (;;) {
|
|
900
|
+
const loginButton = (await page.$x("//button[.//text() = 'Log In']"))[0];
|
|
901
|
+
if (loginButton) {
|
|
902
|
+
await loginButton.click();
|
|
903
|
+
break;
|
|
904
|
+
}
|
|
905
|
+
logger.warn('Login button not found. Maybe you can help me click it? And also report an issue on github with a screenshot of what you\'re seeing :)');
|
|
906
|
+
await sleep(6000);
|
|
907
|
+
}
|
|
892
908
|
|
|
893
909
|
await sleep(6000);
|
|
894
910
|
|