Skip to content

Instantly share code, notes, and snippets.

/sellhack.js Secret

Created April 1, 2014 02:02
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/b15b1e3f6cfb8497e8f0 to your computer and use it in GitHub Desktop.
Save anonymous/b15b1e3f6cfb8497e8f0 to your computer and use it in GitHub Desktop.
(function () {
var e, t = function (e, t) {
return function () {
return e.apply(t, arguments)
}
};
e = function () {
function e() {
this.log = t(this.log, this), this.companyCallback = t(this.companyCallback, this), this.loadCompanyProfile = t(this.loadCompanyProfile, this), this.hackIn = t(this.hackIn, this), this.renderFrame = t(this.renderFrame, this), this.renderButton = t(this.renderButton, this), this.parseContent = t(this.parseContent, this), this.initialized = !1, this.wrapperId = "SELLHACK-WRAPPER", this.frameId = "SELLHACK-FRAME", this.btnId = "SELLHACK-BTN", this.parentUrl = window.document.location.href, this.domain = "app.sellhack.com", this.loadUrl = "https://" + this.domain + "/widget/load/linked-in", this.baseUrl = "https://" + this.domain + "/widget/load/hackin?parent=" + encodeURIComponent(this.parentUrl), this.re = /(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))/g, this.profile_data = {
linkedin_id: "",
name: "",
title: "",
emails: [],
company: {
linkedin_id: 0,
linkedin_url: "",
url: "",
industry: "",
img: "",
name: ""
},
location: "",
sites: [],
twitter: ""
}, this.debug = this.parseQuery(this.parentUrl).hasOwnProperty("sh_debug") || "dev" === this.domain.substr(-3), this.renderButton(), this.parseContent()
}
return e.prototype.parseContent = function () {
var e, t, i, a, n, s, l, r, o, d, h, m, p, g, c, f, y, u, b, x, E, k, C, w, _, T, N, $, B, v, I, L, O;
try {
try {
this.profile_data.linkedin_id = window.LI.TREASURY_CONF.memberId, this.log(this.profile_data.linkedin_id)
} catch (U) {
s = U, this.log(s)
}
if (null != this.$("name") && this.$("name").getElementsByClassName("full-name").length && (this.profile_data.name = this.getText(this.$("name").getElementsByClassName("full-name")[0])), null != this.$("headline") && this.$("headline").getElementsByClassName("title").length && (this.profile_data.title = this.getText(this.$("headline").getElementsByClassName("title")[0])), null != this.$("location") && this.$("location").getElementsByClassName("locality").length && (this.profile_data.location = this.getText(this.$("location").getElementsByClassName("locality")[0])), null != this.$("relationship-emails-view") && this.$("relationship-emails-view").getElementsByTagName("li").length)
for (t = this.$("relationship-emails-view").getElementsByTagName("a"), x = 0, w = t.length; w > x; x++) e = t[x], s = -1 !== e.href.indexOf("mailto") ? e.href.substr(e.href.indexOf("mailto:") + 7) : this.getText(e), this.profile_data.emails.push(s);
else null != this.$("email-view") && this.$("email-view").getElementsByTagName("a").length > 0 && this.profile_data.emails.push(this.getText(this.$("email-view").getElementsByTagName("a")[0]));
try {
for (f = [this.$("background-summary-container"), this.$("background-additional-info-container")], E = 0, _ = f.length; _ > E; E++)
if (c = f[E], null != c && (i = c.innerHTML.match(this.re), null != i && i.length))
for (k = 0, T = i.length; T > k; k++) l = i[k], -1 === this.profile_data.emails.indexOf(l) && this.profile_data.emails.push(l)
} catch (U) {
s = U, this.log(s)
}
if (null != this.$("website-view") && (y = this.$("website-view").getElementsByTagName("a"), null != y && y.length > 0))
for (C = 0, N = y.length; N > C; C++) g = y[C], b = decodeURIComponent(g.href.substr(g.href.indexOf("?url=") + 5)), this.profile_data.sites.push(b.substring(b.indexOf("http"), b.indexOf("&")));
if (null != this.$("twitter-view") && this.$("twitter-view").getElementsByTagName("a").length && (this.profile_data.twitter = this.getText(this.$("twitter-view").getElementsByTagName("a")[0])), null != this.$("background-experience") && this.$("background-experience").getElementsByClassName("section-item").length) {
for (t = this.$("background-experience").getElementsByClassName("section-item")[0].getElementsByTagName("a"), u = !1, I = 0, $ = t.length; $ > I; I++)
if (e = t[I], -1 !== e.href.indexOf("linkedin.com/company")) {
u = e;
break
}
u && (this.profile_data.company.linkedin_url = u.href.substring(0, u.href.indexOf("?")), p = this.getPath(this.profile_data.company.linkedin_url), this.profile_data.company.linkedin_id = p.segments[1], m = this.profile_data.company.linkedin_url.replace("company", "companies") + "?miniprofile=", this.loadCompanyProfile(m, !1))
}
if ("" === this.profile_data.company.name) try {
for (h = this.$("background-experience").getElementsByTagName("header")[0].getElementsByTagName("h5"), L = 0, B = h.length; B > L; L++)
if (d = h[L], -1 === d.className.indexOf("experience-logo")) {
this.profile_data.company.name = this.getText(d);
break
}
} catch (U) {
r = U, this.log(r);
try {
for (n = this.$("overview-summary-current").getElementsByTagName("a"), O = 0, v = n.length; v > O; O++) a = n[O], "company" === a.name && (p = this.parseQuery(a.href), this.profile_data.company.name = p.company)
} catch (U) {
o = U, this.log(o)
}
}
} catch (U) {
r = U, this.log(r)
}
return this.baseUrl += "&data=" + encodeURIComponent(JSON.stringify(this.profile_data)) + "&memberId=" + this.profile_data.linkedin_id, this.log(this.profile_data), this.renderFrame()
}, e.prototype.renderButton = function () {
var e;
return e = document.createElement("div"), e.style.styleFloat = "right", e.style.cssFloat = "right", e.innerHTML = '<a id="' + this.btnId + '" href="javascript:SELLHACK.hackIn();" style="font-size: 13px; color: #444; text-shadow: 0 1px 1px rgba(255,255,255,0.75); box-sizing: border-box; font-weight:bold; line-height:29px; display:block; padding:0 8px; border:1px solid #a7a7a7; margin-top:6px; background: #f2f2f2; background: -moz-linear-gradient(top, #f2f2f2 0%, #e9e9e9 32%, #d8d8d8 74%, #e9e9e9 100%, #d1d1d1 100%); background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f2f2f2), color-stop(32%,#e9e9e9), color-stop(74%,#d8d8d8), color-stop(100%,#e9e9e9), color-stop(100%,#d1d1d1)); background: -webkit-linear-gradient(top, #f2f2f2 0%,#e9e9e9 32%,#d8d8d8 74%,#e9e9e9 100%,#d1d1d1 100%); background: -o-linear-gradient(top, #f2f2f2 0%,#e9e9e9 32%,#d8d8d8 74%,#e9e9e9 100%,#d1d1d1 100%); background: -ms-linear-gradient(top, #f2f2f2 0%,#e9e9e9 32%,#d8d8d8 74%,#e9e9e9 100%,#d1d1d1 100%); background: linear-gradient(to bottom, #f2f2f2 0%,#e9e9e9 32%,#d8d8d8 74%,#e9e9e9 100%,#d1d1d1 100%); border-radius:3px; -moz-border-radius:3px; -webkit-border-radius:3px;">Hack In</a>', document.getElementsByClassName("member-connections")[0].parentNode.appendChild(e)
}, e.prototype.renderFrame = function () {
var e, t, i;
try {
return e = this.$("top-card").getElementsByClassName("profile-card")[0], i = document.createElement("div"), i.id = this.wrapperId, i.style.width = "100%", i.style.height = "100px", i.style.display = "none", i.style.clear = "both", i.style.borderTop = "1px solid #e3e3e3", i.innerHTML = '<iframe src="' + this.loadUrl + "?data=" + encodeURIComponent(JSON.stringify(this.profile_data)) + "&memberId=" + this.profile_data.linkedin_id + '" frameborder="0" width="100%" height="100%" name="' + this.frameId + '" id="' + this.frameId + '">Your browser does not support iframes</iframe><style type="text/css">iframe:focus{ outline: none; } iframe[seamless]{ display: block; }</style>', e.appendChild(i)
} catch (a) {
return t = a, this.log(t)
}
}, e.prototype.hackIn = function () {
this.initialized || (this.initialized = !0, this.$(this.wrapperId).style.display = "block", this.$(this.frameId).src = this.baseUrl, this.$(this.btnId).style.display = "none")
}, e.prototype.loadCompanyProfile = function (e, t) {
var i, a;
return a = new XMLHttpRequest, i = this, a.onreadystatechange = function () {
return 4 === a.readyState && 200 === a.status ? (i.log(a), i.companyCallback(a.responseText)) : void 0
}, a.open("GET", e, t), a.send()
}, e.prototype.companyCallback = function (e) {
var t, i, a, n, s, l, r;
t = document.createElement("div"), t.id = "SELLHACK-COMPANY-DIV", t.style.display = "none", t.innerHTML = e, document.body.appendChild(t), s = this.$(t.id).getElementsByClassName("details")[0].getElementsByTagName("tr");
try {
null != this.$("logo-large-img") && (this.profile_data.company.img = this.$("logo-large-img").src)
} catch (o) {
i = o, this.log(i)
}
try {
this.$(t.id).getElementsByClassName("summary").length && this.$(t.id).getElementsByClassName("summary")[0].getElementsByTagName("a").length && (this.profile_data.company.name = this.getText(this.$(t.id).getElementsByClassName("summary")[0].getElementsByTagName("a")[0]))
} catch (o) {
i = o, this.log(i)
}
for (l = 0, r = s.length; r > l; l++) n = s[l], -1 !== this.getText(n.getElementsByTagName("th")[0]).indexOf("Website") && (a = this.parseQuery(n.getElementsByTagName("a")[0].href), this.profile_data.company.url = a.url), -1 !== this.getText(n.getElementsByTagName("th")[0]).indexOf("Industry") && (this.profile_data.company.industry = this.getText(n.getElementsByTagName("td")[0]))
}, e.prototype.log = function (e) {
return "undefined" != typeof console && null !== console && null != console.log && this.debug === !0 ? console.log(e) : void 0
}, e.prototype.$ = function (e) {
return document.getElementById(e)
}, e.prototype.getText = function (e) {
return e.innerText || e.textContent || ""
}, e.prototype.parseQuery = function (e) {
var t, i, a, n, s, l, r;
for (n = e.substr(e.indexOf("?") + 1), s = {}, i = n.split("&"), l = 0, r = i.length; r > l; l++) t = i[l], a = t.split("="), s[decodeURIComponent(a[0])] = decodeURIComponent(a[1]).replace(/\+/g, " ");
return s
}, e.prototype.getPath = function (e) {
var t;
return t = document.createElement("a"), t.href = e, {
path: t.pathname.replace(/^([^\/])/, "/$1"),
segments: t.pathname.replace(/^\//, "").split("/")
}
}, e
}(), window.SELLHACK = new e
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment