Created
August 25, 2017 15:43
-
-
Save rxwx/3d5aa1b416654f315468669fabcf7786 to your computer and use it in GitHub Desktop.
JS to grab a linkedin memberID from a profile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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