Skip to content

Instantly share code, notes, and snippets.

@rxwx
Created August 25, 2017 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rxwx/3d5aa1b416654f315468669fabcf7786 to your computer and use it in GitHub Desktop.
Save rxwx/3d5aa1b416654f315468669fabcf7786 to your computer and use it in GitHub Desktop.
JS to grab a linkedin memberID from a profile
// paste this in the chrome console and call findMemberID() when on a profile page
// need to be logged in
function decodeHtml(html) {
var txt = document.createElement("textarea");
txt.innerHTML = html;
return txt.value;
}
function httpGet(){
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", location.href, false );
xmlHttp.send( null );
return xmlHttp.responseText;
}
const gregex = /li:member:[0-9]+/g;
function findMemberId(){
// we can't simply grab from the DOM due to the values getting clobbered :(
// so we grab the profile HTML as a string and regex the member ID out
var html = decodeHtml(httpGet());
results= [];
while ((m = gregex.exec(html)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === gregex.lastIndex) {
gregex.lastIndex++;
}
results.push(m);
}
return results[results.length-1][0].split(':')[2]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment