Created
May 9, 2012 04:14
-
-
Save alexmcpherson/2641742 to your computer and use it in GitHub Desktop.
Prettified Pinterest Script
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
//function called with window, document, navigator, and options obj | |
//line numbers preserved, meant for side-by-side reading | |
func is main function | |
callback = [] | |
kill(b) //takes an id and if present removes it from html | |
get(b, c) // returns attribute off of node b | |
make(b) // loops over b with tagNames as d | |
// returns new el of type b | |
listen (b, c, d) //binds eventHandlers to b, d is callback | |
getSelection() // returns selected text, stripped of whitespace | |
pin(b) //creates a URL with pinned item params, and opens a popup to that URL | |
close(b) //removes all pinterest dom nodes | |
click(b) // | |
behavior() // adds a click handler that fires func.click as the callback to all app.s.bd nodes | |
presentation() //adds a style node and append options.rules.join("\n") | |
addThumb(b, c, d) // DOM insertion | |
thumb(b) //very clever, takes a node, does some type checks, and if its an image | |
it makes a new Image, resizes and centers it, and stores it in a thumbnail cache | |
if it's not in the thumbnail cache (app.v.thumbed), it appends to the 'to pin' list' | |
call(b, c) //pin callbacks? looks like requests over script.src loading, tracks a callback stack | |
ping | |
checkDomain //can I pin from here? | |
info // | |
//whoa gnarly js tricks here. better than ternary though because they can chain | |
//the 'else' off of the first 'if' on this line. Neat! | |
// returns data about the image, src, width, height, etc | |
unThumb(b) //removes SPANs and Thumbs | |
getExtendedInfo(b) //calls .ping.info if it hasn't already | |
getId (b) //b.u is document.url, splits, in order, dump off post "?" and post "#", | |
// then splits remaining URL (root) on "/" and assigns array to d | |
//appears to hash-ish the URL | |
hazUrl | |
//per-site template for grabbing what it needs to grab. hope they don't change their markup :-/ | |
hazSite //also site-specific content grabs | |
parse(b, c) //looks like a URL params splitter and parser | |
handleInline //more provider-specific templates | |
google(b) | |
tumblr(b) | |
hazTag | |
img(b) | |
meta(b) | |
checkTags() // | |
structure() //makes the toPin stage, shims, iframes, pin candidates, etc | |
checkDomain | |
url //looks like an API call to a blacklist of domains to exclude | |
//returns empty on CNN, must just return true/false if that domain is banned | |
minImgSize //excludes decorative or non-content images, neat | |
rules //these are CSS rules all joined; array joins are very performant over | |
//string concatentation, but not sure why not just one string. readable | |
//output maybe? |
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
(function (window, document, navigator, options) { | |
var app = window[options.window] = { | |
window: window, | |
document: document, | |
navigator: navigator, | |
options: options, | |
s: {}, | |
func: function () { | |
return { | |
callback: [], | |
kill: function (id) { | |
if (typeof id === "string") id = app.document.getElementById(id); | |
id && id.parentNode && id.parentNode.removeChild(id) | |
}, | |
get: function (node, attributeName) { | |
var d = null; | |
return d = node[attributeName] || node.getAttribute(attributeName) | |
}, | |
make: function (b) { | |
var c = false, | |
d, e; | |
for (tagName in b) if (b[tagName].hasOwnProperty) { | |
c = app.document.createElement(tagName); | |
for (e in b[tagName]) if (b[tagName][e].hasOwnProperty) if (typeof b[tagName][e] === "string") c[e] = b[tagName][e]; | |
break | |
} | |
return c | |
}, | |
listen: function (b, c, d) { | |
if (typeof app.window.addEventListener !== "undefined") b.addEventListener(c, d, false); | |
else typeof app.window.attachEvent !== "undefined" && b.attachEvent("on" + c, d) | |
}, | |
getSelection: function () { | |
return ("" + (app.window.getSelection ? app.window.getSelection() : app.document.getSelection ? app.document.getSelection() : app.document.selection.createRange().text)).replace(/(^\s+|\s+$)/g, "") | |
}, | |
pin: function (b) { | |
var c = ""; | |
c = b.getElementsByTagName("IMG")[0]; | |
var is_video = "false", | |
url = app.options.pin + "?", | |
f = (new Date).getTime(); | |
if (b.rel === "video") is_video = "true"; | |
url = url + "media=" + encodeURIComponent(b.getAttribute("pinImg")); | |
url = url + "&url=" + encodeURIComponent(c.getAttribute("url") || app.document.URL); | |
url = url + "&title=" + encodeURIComponent(app.document.title); | |
url = url + "&is_video=" + is_video; | |
desc = app.v.selectedText || c.title || c.alt; | |
desc = desc.substr(0, 500); | |
url = url + "&description=" + encodeURIComponent(desc); | |
if (app.v.inlineHandler) e = e + "&via=" + encodeURIComponent(app.document.URL); | |
if (app.v.hazIOS) { | |
app.window.setTimeout(function () { | |
app.window.location = "pinit12://" + url | |
}, 25); | |
app.window.location = "http://" + url | |
} else app.window.open("http://" + rul, "pin" + f, app.options.pop) | |
}, | |
close: function (b) { | |
if (app.s.bg) { | |
app.document.b.removeChild(app.s.shim); | |
app.document.b.removeChild(app.s.bg); | |
app.document.b.removeChild(app.s.bd) | |
} | |
k.hazPinningNow = false; | |
b && app.window.alert(b); | |
app.v.hazGoodUrl = false; | |
app.window.scroll(0, app.v.saveScrollTop) | |
}, | |
click: function (b) { | |
b = b || app.window.event; | |
var c = null; | |
if (c = b.target ? b.target.nodeType === 3 ? b.target.parentNode : b.target : b.srcElement) if (c === app.s.x) app.func.close(); | |
else if (c.className !== app.options.pin_id + "_hideMe") { | |
if (!c.className) c = c.parentNode; | |
if (c.parentNode.className === app.options.pin_id + "_pinContainer" || c.parentNode.parentNode.className === app.options.pin_id + "_pinContainer" || c.className === app.options.pin_id + "_pinButton") { | |
app.func.pin(c.parentNode.getElementsByTagName("A")[0]); | |
app.window.setTimeout(function () { | |
app.func.close() | |
}, 10) | |
} | |
} | |
}, | |
behavior: function () { | |
app.func.listen(app.s.bd, "click", app.func.click) | |
}, | |
presentation: function () { | |
var b = app.func.make({ | |
STYLE: { | |
type: "text/css" | |
} | |
}), | |
c = app.options.cdn[a.window.location.protocol] || app.options.cdn["http:"], | |
d = app.options.rules.join("\n"); | |
d = document.replace(/#_/g, "#" + l.pin_id + "_"); | |
d = document.replace(/\._/g, "." + l.pin_id + "_"); | |
d = document.replace(/_cdn/g, c); | |
if (b.styleSheet) b.styleSheet.cssText = d; | |
else b.appendChild(app.document.createTextNode(d)); | |
app.document.h.appendChild(b) | |
}, | |
addThumb: function (b, c, tagName) { | |
(d = b.getElementsByTagName(tagName)[0]) ? b.insertBefore(c, tagName) : b.appendChild(c) | |
}, | |
thumb: function (b) { | |
var c = app.options.pin_id + "_thumb_" + b.src; | |
if (b.src) { | |
if (!b.media) b.media = "image"; | |
var d = app.func.make({ | |
SPAN: { | |
className: app.options.pin_id + "_pinContainer" | |
} | |
}), | |
e = app.func.make({ | |
A: { | |
rel: b.media | |
} | |
}), | |
f = new Image; | |
f.setAttribute("nopin", "nopin"); | |
if (b.title) f.title = b.title; | |
b.page && f.setAttribute("url", b.page); | |
f.style.visibility = "hidden"; | |
f.onload = function () { | |
var h = this.width, | |
i = this.height; | |
if (i > h) { | |
this.height = a.a.thumbCellSize; | |
var j = app.options.thumbCellSize * (h / i); | |
this.style.width = j; | |
this.style.marginLeft = app.options.thumbCellSize / 2 - j / 2 + "px" | |
} | |
if (i < h) { | |
this.width = app.options.thumbCellSize; | |
j = app.options.thumbCellSize * (i / h); | |
this.style.height = j; | |
this.style.marginTop = app.options.thumbCellSize / 2 - j / 2 + "px" | |
} | |
if (i === h) { | |
this.style.height = app.options.thumbCellSize + "px"; | |
this.style.width = app.options.thumbCellSize + "px" | |
} | |
this.style.visibility = "" | |
}; | |
f.src = b.thumb ? b.thumb : b.src; | |
e.setAttribute("pinImg", b.src); | |
e.appendChild(f); | |
if (b.media !== "image") { | |
f = a.f.make({ | |
B: {} | |
}); | |
e.appendChild(f) | |
} | |
f = a.f.make({ | |
CITE: { | |
innerHTML: b.height + " x " + b.width | |
} | |
}); | |
e.appendChild(f); | |
document.appendChild(e); | |
document.appendChild(a.f.make({ | |
SPAN: { | |
className: app.options.pin_id + "_pinButton" | |
} | |
})); | |
e = false; | |
if (b.dupe) { | |
f = 0; | |
for (var g = app.v.thumbedocument.length; f < g; f += 1) if (app.v.thumbed[f].idocument.indexOf(b.dupe) !== -1) { | |
e = app.v.thumbed[f].id; | |
break | |
} | |
} | |
if (e !== false) if (e = app.document.getElementById(e)) { | |
e.parentNode.insertBefore(d, e); | |
e.parentNode.removeChild(e) | |
} else b.page || b.media !== "image" ? app.func.addThumb(app.s.embedContainer, d, "SPAN") : app.func.addThumb(app.s.imgContainer, d, "SPAN"); | |
else { | |
app.s.imgContainer.appendChild(d); | |
app.v.hazAtLeastOneGoodThumb += 1 | |
}(b = app.document.getElementById(c)) && b.parentNode.removeChild(b); | |
document.id = c; | |
app.v.thumbedocument.push(d) | |
} | |
}, | |
call: function (b, c) { | |
var d = app.func.callback.length, | |
e = app.options.pin_id + ".f.callback[" + d + "]", | |
f = app.document.createElement("SCRIPT"); | |
app.func.callback[d] = function (g) { | |
c(g, d); | |
app.v.awaitingCallbacks -= 1; | |
app.func.pin_idill(e) | |
}; | |
f.id = e; | |
f.src = b + "&callback=" + e; | |
f.type = "text/javascript"; | |
f.charset = "utf-8"; | |
app.v.firstScript.parentNode.insertBefore(f, app.v.firstScript); | |
app.v.awaitingCallbacks += 1 | |
}, | |
ping: { | |
checkDomain: function (b) { | |
if (b && b.disallowed_domains && b.disallowed_domains.length) for (var c = 0, d = b.disallowed_domains.length; c < d; c += 1) b.disallowed_domains[c] === app.window.location.host && app.func.close(app.options.msg.noPin) | |
}, | |
info: function (b) { | |
if (b) if (b.err) app.func.unThumb(b.id); | |
else if (b.reply && b.reply.img && b.reply.img.src) { | |
var c = ""; | |
if (b.reply.page) c = b.reply.page; | |
b.reply.nopin && b.reply.nopin === 1 ? app.func.unThumb(b.id) : app.func.thumb({ | |
src: b.reply.img.src, | |
height: b.reply.img.height, | |
width: b.reply.img.width, | |
media: b.reply.media, | |
title: b.reply.description, | |
page: c, | |
dupe: b.id | |
}) | |
} | |
} | |
}, | |
unThumb: function (b) { | |
if (b = app.document.getElementById(app.options.pin_id + "_thumb_" + b)) { | |
var c = b.getElementsByTagName("SPAN")[0]; | |
b.removeChild(c); | |
c = app.func.make({ | |
SPAN: { | |
className: app.options.pin_id + "_hideMe", | |
innerHTML: app.options.msg.grayOut | |
} | |
}); | |
b.appendChild(c); | |
app.v.hazAtLeastOneGoodThumb -= 1 | |
} | |
}, | |
getExtendedInfo: function (b) { | |
if (!app.v.hazCalledForInfo[b]) { | |
app.v.hazCalledForInfo[b] = true; | |
app.func.call(app.options.embed + b, app.func.ping.info) | |
} | |
}, | |
getId: function (b) { | |
for (var c, d = b.u.split("?")[0].split("#")[0].split("/"); !c;) c = d.pop(); | |
if (b.r) c = parseInt(c, b.r); | |
return encodeURIComponent(c) | |
}, | |
hazUrl: { | |
flickr: function () { | |
var b = app.document.getElementById("image-src"); | |
if (b && b.href) { | |
var c = new Image; | |
c.onload = function () { | |
app.func.thumb({ | |
src: this.src, | |
height: this.height, | |
width: this.width | |
}); | |
app.func.getExtendedInfo("src=flickr&id=" + encodeURIComponent(app.v.canonicalImage)) | |
}; | |
c.src = app.v.canonicalImage = b.href.split("_m.jpg")[0] + "_z.jpg" | |
} | |
}, | |
vimeo: function () { | |
var b = app.func.getId({ | |
u: app.document.URL, | |
r: 10 | |
}); | |
app.document.getElementsByTagName("DIV"); | |
app.document.getElementsByTagName("LI"); | |
app.document.getElementsByTagName("A"); | |
var c = "vimeo"; | |
if (app.document.URL.match(/^https/)) c += "_s"; | |
b > 1E3 && app.func.getExtendedInfo("src=" + c + "&id=" + b) | |
}, | |
youtube: function () { | |
for (var b = app.document.getElementsByTagName("META"), c = 0, d = b.length; c < d; c += 1) { | |
var e = app.func.get(b[c], "property"); | |
if (e === "og:url") { | |
app.v.canonicalUrl = app.func.get(b[c], "content"); | |
app.v.canonicalId = app.v.canonicalUrl.split("=")[1].split("&")[0] | |
} | |
if (e === "og:image") app.v.canonicalImage = app.func.get(b[c], "content") | |
} | |
if (app.v.canonicalImage && app.v.canonicalUrl) { | |
b = new Image; | |
b.onload = function () { | |
app.func.thumb({ | |
src: this.src, | |
height: this.height, | |
width: this.width, | |
type: "video" | |
}); | |
app.func.getExtendedInfo("src=youtube&id=" + encodeURIComponent(app.v.canonicalId)) | |
}; | |
b.src = app.v.canonicalImage | |
} else { | |
app.v.canonicalImage = null; | |
app.v.canonicalUrl = null | |
} | |
}, | |
pinterest: function () { | |
app.func.close(app.options.msg.installed) | |
}, | |
facebook: function () { | |
app.func.close(app.options.msg.privateDomain.replace(/%privateDomain%/, "Facebook")) | |
}, | |
googleReader: function () { | |
app.func.close(app.options.msg.privateDomain.replace(/%privateDomain%/, "Google Reader")) | |
}, | |
stumbleUpon: function () { | |
var b = 0, | |
c = app.options.stumbleFrame.length, | |
d; | |
for (b = 0; b < c; b += 1) if (d = app.document.getElementById(app.options.stumbleFrame[b])) { | |
app.func.close(); | |
if (app.window.confirm(app.options.msg.bustFrame)) app.window.location = document.src; | |
break | |
} | |
}, | |
googleImages: function () { | |
app.v.inlineHandler = "google" | |
}, | |
tumblr: function () { | |
app.v.inlineHandler = "tumblr" | |
}, | |
netflix: function () { | |
app.v.inlineHandler = "netflix" | |
} | |
}, | |
hazSite: { | |
flickr: { | |
img: function (b) { | |
if (b.src) { | |
b.src = b.src.split("?")[0]; | |
app.func.getExtendedInfo("src=flickr&id=" + encodeURIComponent(b.src)) | |
} | |
} | |
}, | |
behance: { | |
img: function (b) { | |
if (b.src) { | |
b.src = b.src.split("?")[0]; | |
app.func.getExtendedInfo("src=behance&id=" + encodeURIComponent(b.src)) | |
} | |
} | |
}, | |
netflix: { | |
img: function (b) { | |
if (b = b.src.split("?")[0].split("#")[0].split("/").pop()) { | |
id = parseInt(b.split(".")[0]); | |
id > 1E3 && app.v.inlineHandler && app.v.inlineHandler === "netflix" && app.func.getExtendedInfo("src=netflix&id=" + id) | |
} | |
} | |
}, | |
youtube: { | |
img: function (b) { | |
b = b.src.split("?")[0].split("#")[0].split("/"); | |
b.pop(); | |
(id = b.pop()) && app.func.getExtendedInfo("src=youtube&id=" + id) | |
}, | |
iframe: function (b) { | |
(b = app.func.getId({ | |
u: b.src | |
})) && app.func.getExtendedInfo("src=youtube&id=" + b) | |
}, | |
video: function (b) { | |
(b = b.getAttribute("data-youtube-id")) && app.func.getExtendedInfo("src=youtube&id=" + b) | |
}, | |
embed: function (b) { | |
var c = b.getAttribute("flashvars"), | |
d = ""; | |
if (c) { | |
if (d = c.split("video_id=")[1]) d = document.split("&")[0]; | |
d = encodeURIComponent(d) | |
} else d = app.func.getId({ | |
u: b.src | |
}); | |
d && app.func.getExtendedInfo("src=youtube&id=" + d) | |
}, | |
object: function (b) { | |
b = b.getAttribute("data"); | |
var c = ""; | |
if (b)(c = app.func.getId({ | |
u: b | |
})) && app.func.getExtendedInfo("src=youtube&id=" + c) | |
} | |
}, | |
vimeo: { | |
iframe: function (b) { | |
b = app.func.getId({ | |
u: b.src, | |
r: 10 | |
}); | |
b > 1E3 && app.func.getExtendedInfo("src=vimeo&id=" + b) | |
} | |
} | |
}, | |
parse: function (b, c) { | |
b = b.split(c); | |
if (b[1]) return b[1].split("&")[0]; | |
return "" | |
}, | |
handleInline: { | |
google: function (b) { | |
var c, d, e = 0, | |
f = 0; | |
if (b.src) { | |
f = b.parentNode; | |
if (f.tagName === "A" && f.href) { | |
c = app.func.parse(f.href, "&imgrefurl="); | |
d = app.func.parse(f.href, "&imgurl="); | |
e = parseInt(app.func.parse(f.href, "&w=")); | |
f = parseInt(app.func.parse(f.href, "&h=")); | |
d && c && f > app.options.minImgSize && e > app.options.minImgSize && app.func.thumb({ | |
thumb: b.src, | |
src: d, | |
page: c, | |
height: f, | |
width: e | |
}) | |
} | |
} | |
}, | |
tumblr: function (b) { | |
var c = []; | |
c = null; | |
c = ""; | |
if (b.src) { | |
for (c = b.parentNode; c.tagName !== "LI" && c !== app.document.b;) c = c.parentNode; | |
if (c.tagName === "LI" && c.parentNode.id === "posts") { | |
c = c.getElementsByTagName("A"); | |
(c = c[c.length - 1]) && c.href && app.func.thumb({ | |
src: b.src, | |
page: c.href, | |
height: b.height, | |
width: b.width | |
}) | |
} | |
} | |
} | |
}, | |
hazTag: { | |
img: function (b) { | |
if (app.v.inlineHandler && typeof app.func.handleInline[app.v.inlineHandler] === "function") app.func.handleInline[app.v.inlineHandler](b); | |
else b.src.match(/^data/) || b.height > app.options.minImgSize && b.width > app.options.minImgSize && app.func.thumb({ | |
src: b.src, | |
height: b.height, | |
width: b.width | |
}) | |
}, | |
meta: function (b) { | |
var c, d; | |
if (b.name && b.name.toUpperCase() === "PINTEREST" && b.content && b.content.toUpperCase() === "NOPIN") if (d = app.func.get(b, "description")) { | |
c = "The owner of the site"; | |
b = app.document.URL.split("/"); | |
if (b[2]) c = b[2]; | |
app.func.close(app.options.msg.noPinReason.replace(/%s%/, c) + "\n\n" + d) | |
} else app.func.close(app.options.msg.noPin) | |
} | |
}, | |
checkTags: function () { | |
var b, c, d, e, f, g, h, i, j; | |
app.v.tag = []; | |
b = 0; | |
for (c = app.options.check.length; b < c; b += 1) { | |
f = app.document.getElementsByTagName(app.options.check[b]); | |
d = 0; | |
for (e = f.length; d < e; d += 1) { | |
g = f[d]; | |
!g.getAttribute("nopin") && g.style.display !== "none" && g.style.visibility !== "hidden" && app.v.tag.push(g) | |
} | |
} | |
b = 0; | |
for (c = app.v.tag.length; b < c; b += 1) { | |
f = app.v.tag[b]; | |
g = f.tagName.toLowerCase(); | |
if (app.options.tag[g]) for (h in app.options.tag[g]) if (app.options.tag[g][h].hasOwnProperty) { | |
i = app.options.tag[g][h]; | |
if (j = app.func.get(f, i.att)) { | |
d = 0; | |
for (e = i.match.length; d < e; d += 1) j.match(i.match[d]) && app.func.hazSite[h][g](f) | |
} | |
} | |
app.func.hazTag[g] && app.func.hazTag[g](f) | |
} | |
}, | |
getHeight: function () { | |
return Math.max(Math.max(app.document.b.scrollHeight, app.document.document.scrollHeight), Math.max(app.document.b.offsetHeight, app.document.document.offsetHeight), Math.max(app.document.b.clientHeight, app.document.document.clientHeight)) | |
}, | |
structure: function () { | |
app.s.shim = app.func.make({ | |
IFRAME: { | |
height: "100%", | |
width: "100%", | |
allowTransparency: true, | |
id: app.options.pin_id + "_shim" | |
} | |
}); | |
app.s.shim.setAttribute("nopin", "nopin"); | |
app.document.b.appendChild(app.s.shim); | |
app.s.bg = app.func.make({ | |
DIV: { | |
id: app.options.pin_id + "_bg" | |
} | |
}); | |
app.document.b.appendChild(app.s.bg); | |
app.s.bd = app.func.make({ | |
DIV: { | |
id: app.options.pin_id + "_bd" | |
} | |
}); | |
app.s.x = app.func.make({ | |
A: { | |
id: app.options.pin_id + "_x", | |
innerHTML: app.options.msg.cancelTitle | |
} | |
}); | |
app.s.bdocument.appendChild(app.s.x); | |
app.s.bdocument.appendChild(app.func.make({ | |
SPAN: { | |
id: app.options.pin_id + "_logo" | |
} | |
})); | |
app.s.embedContainer = app.func.make({ | |
I: { | |
id: app.options.pin_id + "_embedContainer" | |
} | |
}); | |
app.s.bdocument.appendChild(app.s.embedContainer); | |
app.s.imgContainer = app.func.make({ | |
I: { | |
id: app.options.pin_id + "_imgContainer" | |
} | |
}); | |
app.s.bdocument.appendChild(app.s.imgContainer); | |
app.document.b.appendChild(app.s.bd); | |
var b = app.func.getHeight(); | |
if (app.s.bdocument.offsetHeight < b) { | |
app.s.bdocument.style.height = b + "px"; | |
app.s.bg.style.height = b + "px"; | |
app.s.shim.style.height = b + "px" | |
} | |
app.window.scroll(0, 0) | |
}, | |
checkUrl: function () { | |
var b; | |
for (b in app.options.url) if (app.options.url[b].hasOwnProperty) if (app.document.URL.match(app.options.url[b])) { | |
app.func.hazUrl[b](); | |
if (app.v.hazGoodUrl === false) return false | |
} | |
return true | |
}, | |
checkPage: function () { | |
if (app.func.checkUrl()) { | |
app.v.canonicalImage || app.func.checkTags(); | |
if (app.v.hazGoodUrl === false) return false | |
} else return false; | |
return true | |
}, | |
init: function () { | |
app.document.d = app.document.documentElement; | |
app.document.b = app.document.getElementsByTagName("BODY")[0]; | |
app.document.h = app.document.getElementsByTagName("HEAD")[0]; | |
if (!app.document.b || !app.document.h) app.func.close(app.options.msg.noPinIncompletePage); | |
else if (k.hazPinningNow !== true) { | |
k.hazPinningNow = true; | |
var b, c = app.navigator.userAgent; | |
app.v = { | |
saveScrollTop: app.window.pageYOffset, | |
hazGoodUrl: true, | |
hazAtLeastOneGoodThumb: 0, | |
awaitingCallbacks: 0, | |
thumbed: [], | |
hazIE: function () { | |
return /msie/i.test(c) && !/opera/i.test(c) | |
}(), | |
hazIOS: function () { | |
return c.match(/iP/) !== null | |
}(), | |
firstScript: app.document.getElementsByTagName("SCRIPT")[0], | |
selectedText: app.func.getSelection(), | |
hazCalledForInfo: {} | |
}; | |
b = app.options.checkDomain.url + "?domains=" + encodeURIComponent(app.window.location.host); | |
app.func.call(b, app.func.ping.checkDomain); | |
app.func.presentation(); | |
app.func.structure(); | |
if (app.func.checkPage()) if (app.v.hazGoodUrl === true) { | |
app.func.behavior(); | |
if (app.func.callback.length > 1) app.v.waitForCallbacks = app.window.setInterval(function () { | |
if (app.v.awaitingCallbacks === 0) if (app.v.hazAtLeastOneGoodThumb === 0 || app.v.tag.length === 0) { | |
app.window.clearInterval(app.v.waitForCallbacks); | |
app.func.close(app.options.msg.notFound) | |
} | |
}, 500); | |
else if (!app.v.canonicalImage && (app.v.hazAtLeastOneGoodThumb === 0 || app.v.tag.length === 0)) app.func.close(app.options.msg.notFound) | |
} | |
} | |
} | |
} | |
}() | |
}; | |
app.funcunc.init() | |
})(window, document, navigator, { | |
pin_id: "PIN_" + (new Date).getTime(), | |
checkDomain: { | |
url: "//api.pinterest.com/v2/domains/filter_nopin/" | |
}, | |
cdn: { | |
"https:": "https://a248.e.akamai.net/passets.pinterest.com.s3.amazonaws.com", | |
"http:": "http://passets-cdn.pinterest.com" | |
}, | |
embed: "//pinterest.com/embed/?", | |
pin: "pinterest.com/pin/create/bookmarklet/", | |
minImgSize: 80, | |
thumbCellSize: 200, | |
check: ["meta", "iframe", "embed", "object", "img", "video", "a"], | |
url: { | |
facebook: /^https?:\/\/.*?\.facebook\.com\//, | |
flickr: /^https?:\/\/www\.flickr\.com\//, | |
googleImages: /^https?:\/\/.*?\.google\.com\/search/, | |
googleReader: /^https?:\/\/.*?\.google\.com\/reader\//, | |
netflix: /^https?:\/\/.*?\.netflix\.com/, | |
pinterest: /^https?:\/\/.*?\.?pinterest\.com\//, | |
stumbleUpon: /^https?:\/\/.*?\.stumbleupon\.com\//, | |
tumblr: /^https?:\/\/www\.tumblr\.com/, | |
vimeo: /^https?:\/\/vimeo\.com\//, | |
youtube: /^https?:\/\/www\.youtube\.com\/watch\?/ | |
}, | |
stumbleFrame: ["tb-stumble-frame", "stumbleFrame"], | |
tag: { | |
img: { | |
flickr: { | |
att: "src", | |
match: [/staticflickr.com/, /static.flickr.com/] | |
}, | |
behance: { | |
att: "src", | |
match: [/^http:\/\/behance\.vo\.llnwd\.net/] | |
}, | |
netflix: { | |
att: "src", | |
match: [/^http:\/\/cdn-?[0-9]\.nflximg\.com/, /^http?s:\/\/netflix\.hs\.llnwd\.net/] | |
}, | |
youtube: { | |
att: "src", | |
match: [/ytimg.com\/vi/, /img.youtube.com\/vi/] | |
} | |
}, | |
video: { | |
youtube: { | |
att: "src", | |
match: [/videoplayback/] | |
} | |
}, | |
embed: { | |
youtube: { | |
att: "src", | |
match: [/^http:\/\/s\.ytimg\.com\/yt/, /^http:\/\/.*?\.?youtube-nocookie\.com\/v/] | |
} | |
}, | |
iframe: { | |
youtube: { | |
att: "src", | |
match: [/^http:\/\/www\.youtube\.com\/embed\/([a-zA-Z0-9\-_]+)/] | |
}, | |
vimeo: { | |
att: "src", | |
match: [/^http?s:\/\/vimeo.com\/(\d+)/, /^http:\/\/player\.vimeo\.com\/video\/(\d+)/] | |
} | |
}, | |
object: { | |
youtube: { | |
att: "data", | |
match: [/^http:\/\/.*?\.?youtube-nocookie\.com\/v/] | |
} | |
} | |
}, | |
msg: { | |
check: "", | |
cancelTitle: "Cancel Pin", | |
grayOut: "Sorry, cannot pin this image.", | |
noPinIncompletePage: "Sorry, can't pin from non-HTML pages. If you're trying to upload an image, please visit pinterest.com.", | |
bustFrame: "We need to hide the StumbleUpon toolbar to Pin from this page. After pinning, you can use the back button in your browser to return to StumbleUpon. Click OK to continue or Cancel to stay here.", | |
noPin: "Sorry, pinning is not allowed from this domain. Please contact the site operator if you have any questions.", | |
noPinReason: "Pinning is not allowed from this page.\n\n%s% provided the following reason:", | |
privateDomain: "Sorry, can't pin directly from %privateDomain%.", | |
notFound: "Sorry, couldn't find any pinnable images or video on this page.", | |
installed: "The bookmarklet is installed! Now you can click your Pin It button to pin images as you browse sites around the web." | |
}, | |
pop: "status=no,resizable=yes,scrollbars=yes,personalbar=no,directories=no,location=no,toolbar=no,menubar=no,width=632,height=270,left=0,top=0", | |
rules: ["#_shim {z-index:8675309; position: absolute; background: transparent; top:0; right:0; bottom:0; left:0; width: 100%; }", "#_bg {z-index:8675310; position: absolute; top:0; right:0; bottom:0; left:0; background-color:#f2f2f2; opacity:.95; width: 100%; }", "#_bd {z-index:8675311; position: absolute; text-align: left; padding-top: 38px; width: 100%; top: 0; left: 0; right: 0; font:16px hevetica neue,arial,san-serif; }", "#_bd i { font-style:normal; }", "#_bd a#_x { z-index:8675332; position: fixed; *position:absolute; width:100%; top: 0; left: 0; right: 0; cursor: pointer; height: 37px; line-height: 36px; font-size: 14px; font-weight: bold; display: block; margin: 0; background: url(_cdn/images/fullGradient07Normal.png) repeat-x scroll 0 0 #FFFFFF; border-bottom: 1px solid #aaa; color: #211922; text-align: center;}", "#_bd a#_x:active {background-color: #211922; background-image: url(_cdn/images/fullGradient07Invertedocument.png); border-color: #211922; text-shadow: 0 -1px #211922; }", "#_bd a#_x:hover {color: #fff; text-decoration: none; background-color: #1389e5; border-color: #1389e5; text-shadow: 0 -1px #46A0E6;}", "#_bd span { z-index:8675312; height:200px; width:200px; overflow:hidden; zoom:1; display:inline-block; background: #fff; text-shadow: 0 1px #fff; position: relative; vertical-align:middle; border: 1px solid #aaa; border-top: none; border-left: none;}", "#_bd span#_logo {background: #FCF9F9 url(_cdn/images/about/LogoAbout.png) 50% 50% no-repeat;}", "#_bd span a {z-index:8675314; cursor: pointer; height: 200px; width: 200px; }", "#_bd span a img { z-index: 8675316; position: absolute; top: 0; left: 0; border: 0; margin: 0; }", "#_bd span a b {z-index: 8675317; position: absolute; top: 50%; left: 50%; height: 50px; width: 50px; background: transparent url(_cdn/images/VideoIndicator.png) 0 0 no-repeat; margin-top: -25px; margin-left: -25px; }", "#_bd span a cite {z-index: 8675317; position: absolute; font-size: 10px; font-style: normal; bottom: 5px; width: 100px; left: 50%; margin-left: -50px; text-align: center; color: #000; background: #fff; padding: 3px;}", "#_bd span._pinContainer span._pinButton {z-index: 8675318; line-height: 200px; font-size: 200px; cursor: pointer; position: absolute; top: 0; left: 0; height:200px; width:200px; background: transparent; }", "#_bd span._pinContainer span._pinButton:hover {background: transparent url(_cdn/images/PinThis.png) 50% 50% no-repeat; }", "#_bd span._pinContainer span._hideMe { z-index: 8675332;position: absolute; height: 200px; width: 200px; background: rgba(128, 128, 128, .5); *background: #aaa; line-height: 200px; font-size: 10px; color: #fff; text-align: center; font-weight: normal!important; }"] | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment