Created
March 26, 2019 13:38
-
-
Save nikola-wd/10c8c3af61f6dd58197347d73b4c2005 to your computer and use it in GitHub Desktop.
Linked automated follow script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let pageNumber = 2; | |
const MAX_PAGES_TO_GO_THROUGH = 10; | |
function scrollToBottom() { | |
window.scrollTo(0,document.body.scrollHeight); | |
} | |
function goToNextPage() { | |
document.querySelector('[aria-label="Page '+ pageNumber +'"]').click(); | |
setTimeout(() => { | |
pageNumber++; | |
if (pageNumber <= MAX_PAGES_TO_GO_THROUGH + 1) { | |
// recursive call to same fn | |
addPeople(); | |
} else { | |
alert('Finished adding all the people :D'); | |
} | |
}, 2000); | |
} | |
function addPeople() { | |
// Initial timeout just in case to leave some time for stuff to load | |
setTimeout(() => { | |
// First scroll to open buttons and pagination links | |
scrollToBottom(); | |
setTimeout(function() { | |
// scroll again just in case | |
scrollToBottom(); | |
}, 1200); | |
if (document.querySelectorAll('button[aria-label*="Connect"]').length) { | |
let buttonsNumber = document.querySelectorAll('button[aria-label*="Connect"]').length; | |
let buttonIndex = 0; | |
console.log('Buttons number: ',buttonsNumber); | |
const buttonsInterval = setInterval(function() { | |
console.log(buttonIndex); | |
document.querySelectorAll('button[aria-label*="Connect"]')[0].click(); | |
buttonIndex++; | |
// click btn if modal opens | |
setTimeout(function() { | |
if (document.querySelector('.send-invite__actions .button-primary-large')) { | |
document.querySelector('.send-invite__actions .button-primary-large').click(); | |
} | |
}, 2200); | |
if (buttonIndex === buttonsNumber) { | |
console.log('Finished all buttons!!!'); | |
clearInterval(buttonsInterval); | |
goToNextPage(); | |
} | |
}, 4000); // end buttonsInterval | |
} else { | |
// if no connect buttons on first page go to next one and repeat | |
goToNextPage(); | |
} | |
}, 3000); // End // Initial timeout | |
} // end addPeople fn | |
// initial call | |
addPeople(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment