Skip to content

Instantly share code, notes, and snippets.

@nikola-wd
Created March 26, 2019 13:38
Show Gist options
  • Save nikola-wd/10c8c3af61f6dd58197347d73b4c2005 to your computer and use it in GitHub Desktop.
Save nikola-wd/10c8c3af61f6dd58197347d73b4c2005 to your computer and use it in GitHub Desktop.
Linked automated follow script
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