Skip to content

Instantly share code, notes, and snippets.

@matthew-muscat
Created November 16, 2014 01:14
Show Gist options
  • Save matthew-muscat/d80030ec03e8e2b281a8 to your computer and use it in GitHub Desktop.
Save matthew-muscat/d80030ec03e8e2b281a8 to your computer and use it in GitHub Desktop.
linkedin-withdraw.js
/**
* Withdraw all not yet accepted invitations on Linkedin. What is specially nice
* if you accidentally invited all your contacts from another sources.
* @usage
* 1) Enter in https://www.linkedin.com/inbox/invitations/sent
* 2) Paste this code on Chrome's JavaScript console
* 3) Execute LW.init();
* 4) Wait :P
* @author <a href="http://brunosouza.org">Bruno Souza</a>
* Contribute on https://github.com/brunomvsouza/LinkedinMassInviteWithdrawal ;)
*/
var LW = (function(){
var
// last windows processed
__LAST_FATHER_WINDOW = window
// number of runs (initializations)
, __RUNS = 0
// maximum number of list pages opened sequentialy
, __SAFE_LIMIT = 2
, __USED_LIMIT = 0
// processes invitation page
, _proccessInvitation = function($win) {
var $windowElements = $win.document.querySelectorAll('.btn-quaternary')
, wElementsLength = $windowElements.length
, j
, archiveIndex
, canWithdraw = false;
for (j = 0; j < wElementsLength; j++) {
if ($windowElements[j].text == "Withdraw") {
canWithdraw = true;
$windowElements[j].click();
break;
} else if ($windowElements[j].text == "Archive"){
archiveIndex = j;
}
}
if (!canWithdraw) {
console.log('WITHDRAW UNAVAILABLE, ARCHIVING!');
$windowElements[archiveIndex].click();
} else {
console.log('WITHDRAW AVAILABLE, WITHDRAWING!');
}
setTimeout(function() {
$win.close();
}, 20000);
},
// initialize invitation lists page handling
_initList = function($fatherWin) {
var $elements = $fatherWin.document.querySelectorAll('.detail-link')
, eLength = $elements.length
, i;
for (i = 0; i < eLength; i++) {
(function() {
var $win = window.open($elements[i].href, "_blank", "width=600,height=600,menubar=yes,toolbar=yes");
$win.LW = LW;
$win.addEventListener('load', function() {
_proccessInvitation($win);
}, false);
}());
}
$fatherWin.close();
},
// initialize
_init = function() {
__RUNS++;
_initList(__LAST_FATHER_WINDOW);
var $win = window.open("https://www.linkedin.com/inbox/#sent?startRow="+(__RUNS*10)+"&subFilter=invitation&keywords=&sortBy=", "_blank", "width=600,height=600,menubar=no,toolbar=no");
$win.LW = LW;
$win.addEventListener('load', function() {
$win.LW.init();
}, false);
__LAST_FATHER_WINDOW = $win;
};
return {
// initialize
init: function() {
__USED_LIMIT++;
if (__USED_LIMIT > __SAFE_LIMIT) {
setTimeout(function() {
__USED_LIMIT = 1;
_init();
}, 90000);
} else {
_init();
}
}
};
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment