Skip to content

Instantly share code, notes, and snippets.

@estasney
Forked from siumeiman/manifest.json
Created September 9, 2018 18:20
Show Gist options
  • Save estasney/a6ab344cfb419862018a16f1f3db0835 to your computer and use it in GitHub Desktop.
Save estasney/a6ab344cfb419862018a16f1f3db0835 to your computer and use it in GitHub Desktop.
Download LinkedIn
{
  "manifest_version": 2,
  "name": "LinkedIn Profile Saver",
  "version": "1.0.0",
  "content_scripts": [{
    "matches": [
      "http://*.linkedin.com/in/*",
      "https://*.linkedin.com/in/*",
      "http://*.linkedin.com/profile/*",
      "https://*.linkedin.com/profile/*"
    ],
    "js": ["profile_content.js"],
    "run_at": "document_start"
  }, {
    "matches": [
      "http://*.linkedin.com/recruiter/profile/*",
      "https://*.linkedin.com/recruiter/profile/*"
    ],
    "js": ["recruiter_profile_content.js"],
    "run_at": "document_start"
  }]
}
var link = document.createElement('a');
link.className = 'button-primary';
link.text = '📄 Save';
function parse() {
  var profile = '<!DOCTYPE html><meta charset="utf-8"><title>' + document.title + '</title>';
  [
    '[data-li-template="p2_basic_info"]',
    '.view-public-profile',
    '#contact-info-section',
    '#background',
    '#recommendations',
    '.endorsements-received'
  ].forEach(function(item) {
    var el = document.querySelector(item);
    if (!el) return;
    el = el.cloneNode(true);
    var nodes = el.querySelectorAll('a');
    for (var i = 0; i < nodes.length; i++) {
      var node = nodes[i];
      var match = /\/redirect\?url=([^&]+)/.exec(node.href);
      node.href = (match) ? unescape(match[1]) : node.href;
    }
    var nodes = el.querySelectorAll('#twitter a,#website a');
    for (var i = 0; i < nodes.length; i++) {
      var node = nodes[i];
      node.text = node.href;
    }
    var iterator = document.createNodeIterator(el, NodeFilter.SHOW_ELEMENT);
    var node;
    while (node = iterator.nextNode()) {
      node.removeAttribute('style');
      node.removeAttribute('tabindex');
      if (!node.parentNode) continue;
      if (
        node.tagName === 'SCRIPT' ||
        node.tagName === 'IMG' ||
        node.tagName === 'HR' ||
        /^javascript:/.test(node.href) ||
        /^#/.test(node.getAttribute('href')) ||
        node.classList.contains('endorsers-container') ||
        node.classList.contains('education-associated') ||
        node.classList.contains('experience-logo')
      ) {
        node.parentNode.removeChild(node);
      }
    }
    profile += el.outerHTML;
  });
  link.download = document.title + '.html';
  link.href = 'data:text/html;charset=utf-8,' + encodeURIComponent(profile);
  var parent = document.querySelector('.profile-actions');
  parent.insertBefore(link, parent.firstChild);
}
console.log('HI')
var observer = new MutationObserver(function(mutations) {
  for (var i = 0; i < mutations.length; i++) {
    var mutation = mutations[i];
    for (var j = 0; j < mutation.addedNodes.length; j++) {
      var node = mutation.addedNodes[j];
      if (node.id === 'background' || node.id === 'endorsements') {
        setTimeout(parse, 0);
      }
    }
  }
});
observer.observe(document.documentElement, {childList: true, subtree: true});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment