Skip to content

Instantly share code, notes, and snippets.

@shov
Last active April 13, 2017 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shov/964e86a4df40ec07fa4ef7fc76017e82 to your computer and use it in GitHub Desktop.
Save shov/964e86a4df40ec07fa4ef7fc76017e82 to your computer and use it in GitHub Desktop.
Inviter script for linkedin.com
(function () {
function FriendInviteBot() {
const netUrl = "https://www.linkedin.com/mynetwork/";
var silent = false;
var buttonsList;
var alreadyCollectedUsers = [];
function timeOutDecorator(method, intervalSrc) {
return function () {
var interval = intervalSrc;
if (typeof interval === 'function') interval = intervalSrc();
method();
var timeout = setTimeout(tick, interval);
function tick() {
method();
if (typeof intervalSrc === 'function') interval = intervalSrc(interval);
timeout = setTimeout(tick, interval);
}
};
}
function recalcButtons() {
buttonsList = document.querySelectorAll('.mn-person-card__card-actions>button[data-control-name="invite"]');
buttonsList.inviteCounter = 0;
var len = buttonsList.length;
if (!silent) console.log("Have recalculated buttons, now have " + len);
return len;
}
function scrollPage() {
window.scrollBy(0, 500); //just 500px down
if (!silent) console.log("Have scrolled bit down");
}
function scrollPageInterval(interval) {
var minInterval = 500; // 500ms, check it
var minUsersToAddOnPage = 30; //just for check
if (typeof interval === 'undefined') interval = minInterval;
if (recalcButtons() > minUsersToAddOnPage) {
interval *= 2;
if (!silent) console.log("Increase interval of scroll X2, now interval = " + interval);
} else {
interval /= 2;
if (interval < minInterval) interval = minInterval;
if (!silent) console.log("Decrease interval of scroll /2, was trying, now interval = " + interval);
}
return Math.floor(interval);
}
function clickButtons() {
var index = buttonsList.inviteCounter;
if (index < buttonsList.length) {
if(!isCollected(index)) {
buttonsList[index].click();
if (!silent) console.log(getNameFromButton(index) + " have added!");
}
buttonsList.inviteCounter++;
}
}
function isCollected(index) {
var bt = buttonsList[index];
var id = bt.attributes[3].nodeValue;
if (alreadyCollectedUsers.indexOf(id) === -1) {
alreadyCollectedUsers.push(id);
return false;
}
return true;
}
function getNameFromButton(index) {
var bt = buttonsList[index];
return bt.parentNode.parentNode.querySelector('.mn-person-info__name').innerText.trim();
}
this.run = function (onSilent) {
if (window.location.href != netUrl) {
console.log("Wrong url, go to " + netUrl);
return;
}
if (typeof onSilent !== 'undefined' && true === onSilent) silent = true;
var scrolling = timeOutDecorator(scrollPage, scrollPageInterval);
scrolling();
var inviting = timeOutDecorator(clickButtons, 2000); //click per 2 seconds
inviting();
};
}
var badGuy = new FriendInviteBot();
badGuy.run();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment