Skip to content

Instantly share code, notes, and snippets.

@guillaumegarcia13
Last active June 28, 2017 14:30
Show Gist options
  • Save guillaumegarcia13/9013a7a6f1863e9a437eecc9a1692d79 to your computer and use it in GitHub Desktop.
Save guillaumegarcia13/9013a7a6f1863e9a437eecc9a1692d79 to your computer and use it in GitHub Desktop.
Add stats to all of your posts in LinkedIn
// PURPOSE
//----------
// On LinkedIn, you may have your stats under the cards related to your posts but sometimes you DON'T
// This snippet is here to solve this by being run in your console on: https://www.linkedin.com/in/{{user}}/recent-activity/ page
// Limitations:
// - loading is lazy so when you have to re-run the snippet after scrolling
// - only on 'Post' activity and not on 'Like' activity
// - does not detect existing stats
//var urlPrefix = $("a[data-control-name=recent_activity_details_all]").attr("href"); // not reliable
var urlPrefix = "/in/" + window.location.href.split("/in/")[1];
var statSnippet = `<div class="content-analytics-entry-point ember-view">
<a href="{{urlPrefix}}ca/share-analytics/{{urn}}" class="analytics-entry-point ember-view"> <span class="icon-and-text-container Sans-15px-black-70%">
<span class="svg-icon-wrap"><span class="visually-hidden">Icône Statistiques</span><li-icon aria-hidden="true" type="analytics-icon"><svg viewBox="0 0 24 24" width="24px" height="24px" x="0" y="0" preserveAspectRatio="xMinYMin meet" class="artdeco-icon"><g class="large-icon" style="fill: currentColor">
<path d="M5,19H21v2H4a1,1,0,0,1-1-1V3H5V19ZM20,3.1L15,6.21l2.17,1.17L14.69,11.9l-3.26-1.75a1.2,1.2,0,0,0-1.62.48L6.69,16.37l1.65,0.9,2.78-5.21,3.28,1.79A1.2,1.2,0,0,0,16,13.37l2.76-5.11L21,9.46V3.67A0.67,0.67,0,0,0,20,3.1Z"></path>
</g></svg></li-icon></span>
<span><strong>views</strong></span>
</span>
</a>
</div>`.replace("{{urlPrefix}}", urlPrefix);
$("article[data-id]").each(function(index, element) {
$(element).append(statSnippet.replace("{{urn}}", $(element).attr("data-id")));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment