Simple LinkedIn Resume Generator (js)

LinkedIn recently disabled it’s third party APIs which took out an auto-resume builder service based on my public profile. I wrote some JS to try and at least generate a basic resume from my LinkedIn profile now:

From LinkedIn Profile -to- a simple clean resume! with just a little bit of effort! (done in Safari with print-to-PDF graphics enabled & headers disabled):

/* https://www.linkedin.com/public-profile/settings */
/* zoom: 99% || move: 195,75,55 */

var font = [9, 11, 13, 15, 17, 19];
var mail = ["root@fossjon.com", "jon.chiappetta@gmail.com"];
var webs = ["fossjon.com", "star.fossjon.com"];
var gits = ["github.com/fossjon", "github.com/stoops"];
var imgs = {};

function hide(objc) {
  console.log("hide:",objc);
  try { objc.parentNode.removeChild(objc); } catch(e) { /* no-op */ }
}

function tnls(idls) {
  var outp = [];
  for (var j = 0; j < idls.length; ++j) {
    var l = document.getElementsByTagName(idls[j]);
    for (var i = 0; i < l.length; ++i) {
      outp.push(l[i]);
    }
  }
  return outp;
}

function cnls(idls) {
  var outp = [];
  for (var j = 0; j < idls.length; ++j) {
    var l = document.getElementsByClassName(idls[j]);
    for (var i = 0; i < l.length; ++i) {
      outp.push(l[i]);
    }
  }
  return outp;
}

function nols(objc) {
  var outp = [];
  var l = objc.childNodes;
  for (var i = 0; i < l.length; ++i) {
    try {
      if (l[i].tagName.toLowerCase() != "") {
        outp.push(l[i]);
      }
    } catch (e) { /* no-op */ }
  }
  return outp;
}

var s = 0, q = 0;
function y() {
  if (s == 0) { window.scrollTo(0, 0); }
  if (s < document.body.scrollHeight) {
    // scroll
    window.scrollBy(0, 125); s += 125;
    setTimeout(y, 0.125 * 1000);
  } else {
    if (q == 0) { q = 1; z(); }
    else { window.scrollTo(0, 0); }
  }
}

function u() {
  var p = document.getElementsByClassName("cover-img");
  if (p.length > 0) {
    p[0].style.marginLeft = "-2px";
    p[0].style.marginRight = "-2px";
  }
}

function z() {
  document.title = "resume";
  document.body.setAttribute("style", "background-color:white !important; padding:1px !important; margin:1px !important;");

  // hide
  var l = [
    "global-nav__a11y-menu", "global-nav", "header", "li-footer", "global-footer", "right-rail",
    "msg-overlay-container", "pv-top-card__photo-wrapper", "pv-open-to-carousel", "artdeco-carousel__content",
    "profile-topcard-background-image-edit__icon", "scaffold-layout-toolbar", "scaffold-layout__aside",
    "settings-header", "pp-section activities", "pp-section recommended-content", "pp-section languages"
  ];
  for (var i = 0; i < l.length; ++i) {
    var a = document.getElementById(l[i]);
    hide(a);
    var b = document.getElementsByClassName(l[i]);
    while (b.length > 0) {
      hide(b[0]);
      b = document.getElementsByClassName(l[i]);
    }
  }
  var l = tnls(["button"]);
  for (var i = 0; i < l.length; ++i) {
    if (l[i].innerText && l[i].innerText.match(/^.*(see|show) more.*$/mig)) {
      l[i].click();
    }
  }
  var l = tnls(["button"]);
  for (var i = 0; i < l.length; ++i) {
    if (l[i].innerText && l[i].innerText.match(/^.*(see|show) less.*$/mig)) {
      l[i].setAttribute("style", "display:none !important;");
    }
  }

  // high
  var p = document.getElementsByClassName("authentication-outlet");
  if (p.length > 0) {
    p[0].setAttribute("style", "background:white !important; padding-top:1px !important; padding-bottom:256px !important;");
  }

  // wide
  var p = document.getElementById("main-content");
  if (p) {
    var w = (p.parentNode.offsetWidth * 0.95);
    p.setAttribute("style", "margin-left:3px !important; margin-right:3px !important; padding-left:3px !important; padding-right:3px !important; width:" + w + "px !important;");
  }
  var p = document.getElementsByClassName("core-rail");
  if (p.length > 0) {
    var w = (p[0].parentNode.offsetWidth * 0.95);
    p[0].setAttribute("style", "margin-left:3px !important; margin-right:3px !important; padding-left:3px !important; padding-right:3px !important; width:" + w + "px !important;");
  }

  // dots + imgs
  var f = 1;
  while (f == 1) {
    f = 0;
    var l = tnls(["p"]);
    for (var i = 0; i < l.length; ++i) {
      var h = l[i].innerHTML; if (!h) { continue; }
      var t = l[i].getElementsByClassName("mods-html");
      if (t.length > 0) { continue; }
      while (h.match(/^.*••.*$/mig)) {
        h = h.replace(/••([^<>\r\n]+)/mig, "<div style='display:inline-flex; padding-left:25px; flex:1em;'>•$1</div>");
      }
      if (h.match(/^.*[^;&]•[^;&].*$/mig)) {
        h = h.replace(/•([^<>\r\n]+)/mig, "<div style='display:inline-flex; padding-left:5px; flex:1em;'><b style='/*font-size:" + font[5] + "px;*/'>&nbsp;•&nbsp;</b><div style='display:inline-flex; padding-left:1px; flex:1em;'>$1</div></div>");
      }
      for (var k in imgs) {
        if (h.includes("["+k+"]")) {
          h = h.replace("["+k+"]", "<div><img class='mods-imgs' style='width:65%; margin-left:15px;' src='data:image/png;base64,"+imgs[k]+"' /></div>");
        }
      }
      console.log("dots:",i,l[i]);
      l[i].innerHTML = ('<span class="text-body-small main-text mods-html" style="/*font-size:' + font[1] + 'px;*/">' + h + '</span>');
      f = 1;
      break;
    }
  }

  // bugs
  var p = document.getElementsByClassName("core-rail");
  if (p.length > 0) {
    var l = nols(p[0]);
    if (l.length > 0) {
      l[0].setAttribute("style", "display:inline-block !important;");
    }
  }
  var l = document.getElementsByClassName("core-section-container");
  for (var i = 0; i < l.length; ++i) {
    l[i].style.paddingTop = "16px";
    l[i].style.paddingBottom = "16px";
  }
  var l = document.getElementsByClassName("experience-group__positions");
  for (var i = 0; i < l.length; ++i) {
    l[i].style.position = "relative";
    l[i].style.right = "10px";
  }

  // info
  var p = document.getElementsByClassName("cover-img__image");
  if (p.length > 0) {
    p[0].setAttribute("style", "height:28px !important;");
  }
  var p = document.getElementsByClassName("cover-img");
  if (p.length > 0) {
    p[0].setAttribute("style", "min-height:28px !important; height:28px !important; padding-bottom:8px !important;");
  }
  var p = document.getElementsByClassName("top-card__profile-image-container");
  if (p.length > 0) {
    hide(p[0]);
  }
  var p = document.getElementsByClassName("top-card-layout__entity-info");
  if (p.length > 1) {
    hide(p[1]);
  }
  var l = nols(p[0]);
  for (var i = (l.length - 1); i > 1; --i) {
    hide(l[i]);
  }
  if (l.length > 1) {
    var info = l[0].innerText;
    l[0].innerText = ("// " + info);
    var info = l[1].innerText.replace(/^/, "# ").replace(/ at /mig, " @ ");
    l[1].innerHTML = ("<span id='mods-info'>" + info + "</span>");
    l[1].setAttribute("style", "font-family:monospace !important; /*font-size:" + font[2] + "px !important;*/ padding-left:1px !important; padding-top:5px !important; padding-bottom:9px !important;");
    l[1].outerHTML += "<div id='mods-link'></div>";
  }
  var p = document.getElementById("mods-link");
  if (p) {
    var h = ["", "", ""];
    for (var i = 0; i < Math.max(mail.length,webs.length); ++i) {
      var a = ""; if (i < mail.length) { a = mail[i]; }
      var b = ""; if (i < webs.length) { b = webs[i]; }
      var c = ""; if (i < webs.length) { c = gits[i]; }
      if (a != "") {
        var path = '<path d="M8 1L1 4.47V11a3 3 0 003 3h8a3 3 0 003-3V4.47zm5 10a1 1 0 01-1 1H4a1 1 0 01-1-1V6.51L8 9l5-2.49z"></path>';
        a = ('<a href="mailto:'+a+'"><li-icon type="envelope-open" class="resume-builder-contact-info__email-icon" size="small" role="img" aria-label="Email"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" data-supported-dps="16x16" fill="currentColor" class="mercado-match" width="16" height="16" focusable="false">'+path+'</svg></li-icon><span style="top:-4px;position:relative;"> &nbsp; '+a+'</span></a>');
      }
      h[0] += ('<div style="padding-top:1px; padding-bottom:1px;">'+a+'</div>');
      if (b != "") {
        var path = '<path d="M11 2a3 3 0 00-2.1.87L6.87 4.94a2.93 2.93 0 00-.72 1.21 2.93 2.93 0 00-1.21.72L2.87 8.94a3 3 0 104.19 4.19l2.07-2.07a2.93 2.93 0 00.72-1.21 2.93 2.93 0 001.21-.72l2.07-2.07A3 3 0 0011 2zm-5.17 9.89a1.22 1.22 0 01-1.72-1.72l2.06-2.06A3 3 0 007.91 9.8zm6.07-6.07L9.83 7.89A3 3 0 008.09 6.2l2.07-2.07a1.22 1.22 0 011.73 1.7z"></path>';
        b = ('<a href="https://'+b+'"><li-icon type="link" class="resume-builder-contact-info__website-icon" size="small" color="true" role="img" aria-label="Website link"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" data-supported-dps="16x16" fill="currentColor" width="16" height="16" focusable="false">'+path+'</svg></li-icon><span style="top:-4px;position:relative;"> &nbsp; '+b+'</span></a>');
      }
      h[1] += ('<div style="padding-top:1px; padding-bottom:1px;">'+b+'</div>');
      if (c != "") {
        var path = '<path d="M11 2a3 3 0 00-2.1.87L6.87 4.94a2.93 2.93 0 00-.72 1.21 2.93 2.93 0 00-1.21.72L2.87 8.94a3 3 0 104.19 4.19l2.07-2.07a2.93 2.93 0 00.72-1.21 2.93 2.93 0 001.21-.72l2.07-2.07A3 3 0 0011 2zm-5.17 9.89a1.22 1.22 0 01-1.72-1.72l2.06-2.06A3 3 0 007.91 9.8zm6.07-6.07L9.83 7.89A3 3 0 008.09 6.2l2.07-2.07a1.22 1.22 0 011.73 1.7z"></path>';
        c = ('<a href="https://'+c+'"><li-icon type="link" class="resume-builder-contact-info__website-icon" size="small" color="true" role="img" aria-label="Website link"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" data-supported-dps="16x16" fill="currentColor" width="16" height="16" focusable="false">'+path+'</svg></li-icon><span style="top:-4px;position:relative;"> &nbsp; '+c+'</span></a>');
      }
      h[2] += ('<div style="padding-top:1px; padding-bottom:1px;">'+c+'</div>');
    }
    var o = ('<span><a href="/replaced/contact-info/" style="display:none;"></a></span>');
    o += ('<table style="width:100% !important; /*font-size:' + font[0] + 'px !important;*/"><tr>');
    o += ('<td style="width:30%;">'+h[0]+'</td>');
    o += ('<td style="width:30%;">'+h[1]+'</td>');
    o += ('<td style="width:30%;">'+h[2]+'</td>');
    o += ('</tr></table>');
    p.innerHTML = o;
  }

  // link
  var l = tnls("a");
  for (var i = 0; i < l.length; ++i) {
    if (l[i].innerText && l[i].innerText.match(/^.*see (project|publication).*$/mig)) {
      console.log("link",l[i].href);
      hide(l[i]);
    }
  }
  var l = tnls("p");
  for (var i = 0; i < l.length; ++i) {
    if (l[i].innerText && l[i].innerText.match(/^.*(https:..[^ <>]).*$/mig)) {
      var r = l[i].innerText.match(/^.*(https:..[^ <>]).*$/mig);
      var p = l[i].parentNode.parentNode.parentNode;
      var n = p.getElementsByTagName("*");
      n[0].innerHTML = ("<a style='color:var(--artdeco-reset-link-color-blue7);' href='" + r[0] + "'>" + n[0].innerText + "</a>");
      l[i].innerHTML = l[i].innerHTML.replace(r[0], "").replace(/(<br>)+$/mig, "");
      console.log("link",r[0]);
    }
  }
  var l = document.getElementsByTagName("a");
  for (var i = 0; i < l.length; ++i) {
    if (l[i].href && l[i].href.match(/^.*\/redir\/redirect[^=]*=.*$/)) {
      var urls = unescape(l[i].href.replace(/^.*\/redir\/redirect[^=]*=/mig, "").replace(/\&.*$/mig, ""));
      l[i].href = urls;
      l[i].setAttribute("class", "text-[18px] hover:!text-color-text active:!text-color-text");
    }
  }

  // date
  var l = cnls(["experience-item__location", "experience-group-position__location"]);
  for (var i = (l.length - 1); i > - 1; --i) {
    var p = l[i].parentNode.getElementsByTagName("p");
    if (p.length > 0) {
      p[0].innerHTML += (" &nbsp; (" + l[i].innerText.replace(/^[ \t]*/mig, "").replace(/[ \t]*$/mig, "") + ")");
      hide(l[i]);
    }
  }

  // path
  var l = document.getElementsByClassName("profile-section-card__meta");
  for (var i = 0; i < l.length; ++i) {
    var p = l[i].parentNode.parentNode;
    var c = JSON.stringify(p.classList);
    if (!c.includes("group")) {
      l[i].setAttribute("style", "padding-bottom:3px !important; margin-top:-3px !important;");
      var h = ('<ul class="experience-group__positions" style="position:relative; right:60px;">');
      h += ('<li class="experience-group-position profile-section-card" data-section="pastPositionsDetails" style="top:7px !important;">');
      h += (l[i].outerHTML);
      h += ('</li></ul>');
      l[i].outerHTML = h;
    }
  }
  var l = document.getElementsByTagName("ul");
  for (var i = 0; i < l.length; ++i) {
    var c = JSON.stringify(l[i].classList);
    if (c.includes("group")) {
      l[i].innerHTML += ('<li class="experience-group-position profile-section-card" data-section="pastPositionsDetails" style="display:none !important;"></li>');
    }
  }

  // mono
  var l = document.getElementsByClassName("mods-html");
  if (l.length > 0) {
    l[l.length-1].style.fontFamily = "monaco";
    l[l.length-1].style.fontSize = "14px";
    l[l.length-1].style.fontWeight = "bold";
    var s = l[l.length-1].innerText.split("|");
    var h = "", e = "";
    for (var i = 0; i < s.length; ++i) {
      var t = s[i].trim();
      if (t == "") { continue; }
      h += (e + t); e = " | ";
      if (((i + 1) % 7) == 0) { h += "<br/><!-- skillz -->"; e = ""; }
    }
    l[l.length-1].innerHTML = h;
  }

  // move
  var l = document.getElementsByTagName("li");
  for (var i = 0; i < l.length; ++i) {
    var p = l[i].getElementsByTagName("li");
    if (p.length < 1) {
      console.log("move:",i,l[i]);
      l[i].onclick = function() {
        var ob = this.parentNode.parentNode;
        var pb = parseInt(ob.style.paddingBottom);
        if (!pb) { pb = 0; }
        var ux = parseInt(prompt("Move", pb));
        if (!ux) { ux = 0; }
        console.log("move:",i,ob,ux);
        ob.style.paddingBottom = (ux+"px");
      };
    }
  }

  // end!
  window.scrollTo(0, 0);
  setInterval(u, 1.5 * 1000);

  return 0;

}

s = 0; y();

imgs["img0"] = "";

Leave a comment