Skip to content

Instantly share code, notes, and snippets.

@prafulfillment
Last active May 31, 2023 21:58
Show Gist options
  • Save prafulfillment/73fd70f399d6cae8a361 to your computer and use it in GitHub Desktop.
Save prafulfillment/73fd70f399d6cae8a361 to your computer and use it in GitHub Desktop.
LinkedIn Scripts
/*
Autosend Invites to anyone that shares X number of connections with you.
Way to use this script:
1. Save it as a bookmarklet
2. Go to 'People you may know'
3. Click on this bookmarklet.
4. Enter number of overlapping connections
5. Check your console
Tested on Google Chrome 37.0.2062.122
*/
cards = num_connections = prompt("How many connections?");
num_connections = parseInt(num_connections);
$('.card').filter(function(index){
common_connections = this.querySelector('.bt-incommon .glyph-text');
return common_connections && common_connections.innerText > num_connections
}).map(function(){return this.querySelector('button[data-act=request]').click()})
/*
Pull all your LinkedIn Messages.
Way to use this script:
1. Save it as a bookmarklet
2. Go to your messages select which type: Messages, Sent, Invite, Archive, ...
3. Click on this bookmarklet.
4. Enter number of pages you want to pull starting from current page
5. Check your console
Tested on Google Chrome 37.0.2062.122
*/
var page_text = $('.page').text();
var num_pages_pattern = /Page \d+ of (\d+)/;
var num_pages_match = page_text.match(num_pages_pattern);
var num_pages_str = num_pages_match[1];
var ask_num_pages = prompt("How many pages do you want to pull? (Max: " + num_pages_str + ")");
var num_pages = parseInt(ask_num_pages);
var messages = [];
var i = 0;
function getMessages(){
var message_list = $('.message-item');
Array.prototype.push.apply(messages, message_list);
i = i + 1;
if (i < num_pages){
$('.next a')[0].click();
setTimeout(getMessages, 2000);
}
else if (i == num_pages) {
parsed_messages = $.map(messages, parseElement);
console.log(JSON.stringify(parsed_messages));
}
}
function extractText(domElement, querySelector){
var elementFromQuerySelector = domElement.querySelector(querySelector);
var elementText = '';
if (elementFromQuerySelector) {
elementText = elementFromQuerySelector.innerText;
if (elementText) {
elementText = elementText.trim();
elementText = elementText.replace(/\s+/, ' ');
}
}
return elementText;
}
function parseElement(domElement){
parsedElement = {};
parsedElement['participants'] = extractText(domElement, '.participants');
parsedElement['subject'] = extractText(domElement, '.subject');
parsedElement['preview'] = extractText(domElement, '.preview');
parsedElement['status'] = extractText(domElement, '.item-status');
parsedElement['date'] = extractText(domElement, '.date');
parsedElement['link'] = domElement.querySelector('.subject a').href;
return parsedElement;
}
getMessages();
@prafulfillment
Copy link
Author

Minified for bookmarklets:

Get Messages:

javascript:function getMessages(){var e=$(".message-item");Array.prototype.push.apply(messages,e);i=i+1;if(i<num_pages){$(".next a")[0].click();setTimeout(getMessages,2e3)}else if(i==num_pages){parsed_messages=$.map(messages,parseElement);console.log(JSON.stringify(parsed_messages))}}function extractText(e,t){var n=e.querySelector(t);var r="";if(n){r=n.innerText;if(r){r=r.trim();r=r.replace(/\s+/," ")}}return r}function parseElement(e){parsedElement={};parsedElement["participants"]=extractText(e,".participants");parsedElement["subject"]=extractText(e,".subject");parsedElement["status"]=extractText(e,".item-status");parsedElement["date"]=extractText(e,".date");parsedElement["link"]=e.querySelector(".subject a").href;return parsedElement}var page_text=$(".page").text();var num_pages_pattern=/Page \d+ of (\d+)/;var num_pages_match=page_text.match(num_pages_pattern);var num_pages_str=num_pages_match[1];var ask_num_pages=prompt("How many pages do you want to pull? (Max: "+num_pages_str+")");var num_pages=parseInt(ask_num_pages);var messages=[];var i=0;getMessages()

Mass LinkedIn Connect:

cards = num_connections = prompt("How many connections?"); num_connections = parseInt(num_connections); $('.card').filter(function(index){ common_connections = this.querySelector('.bt-incommon .glyph-text'); return common_connections && common_connections.innerText > num_connections } ).map(function(){return this.querySelector('button[data-act=request]').click()})

@prafulfillment
Copy link
Author

I know there's an API. Though LinkedIn documentation is poor and there are numerous problems. I think the messages endpoint works but this is much easier to setup and work with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment