Skip to content

Instantly share code, notes, and snippets.

@joelcarranza
Created March 24, 2013 23:05
Show Gist options
  • Save joelcarranza/cfd44a7a72442bb734eb to your computer and use it in GitHub Desktop.
Save joelcarranza/cfd44a7a72442bb734eb to your computer and use it in GitHub Desktop.
javascript:(function(){var e=false;var t=null;var r=false;var n={javascript:"javascript",js:"javascript",python:"python",ios:"ios",youtube:"video",vimeo:"video",video:"video",books:"book",book:"book"};var o={"github.com":".entry-title .js-current-repository"};var i={"www.kickstarter.com":".short-blurb"};var a=1e3;var u=function(e){return e.toLowerCase()};var c=function(e){return e?e.textContent.trim().replace(/\s+/g," "):null};var l=u(document.title);var f=function(e){if(e){return l.indexOf(u(e))!==-1}else{return false}};var s=function(e,t,r){r=r||window;var n=e.length;var o;for(var i=0;i<n;++i){o=t.call(r,e[i]);if(o!==null){return o}}return null};var v=function(){var e=location.href;var t=location.hostname;var r;if(t in o){r=document.querySelector(o[t]);if(r){return c(r)}}var n=document.title;r=document.querySelector("meta[property='og:title']");if(r){n=r.content.trim().replace(/\s+/g," ")}if(s(document.getElementsByClassName("hentry"),function(){return true})){var i=document.querySelector(".hentry .entry-title");if(i){return c(i)}}var a=s(document.getElementsByTagName("A"),function(t){if(t.href===e){a=c(t);if(f(a)){return a}}return null});if(a){return a}var u=["h1","h2","h3","h4","h5","h6"];var l;for(var v=0;v<u.length;++v){s(document.getElementsByTagName(u[v]),function(e){var t=c(e);if(f(t)&&(!l||t.length>l.length)){l=t}return null})}if(l){return l}return n};var m=function(e){e=u(e);var t=[];var r;for(var o in n){r=o instanceof RegExp?o:new RegExp("\\b"+o+"\\b","i");if(r.test(e)){t.push(n[o])}}return t};var d=function(){var e;e=document.querySelector("meta[name='description']");if(e){return e.content.trim().replace(/\s+/g," ")}e=document.querySelector("meta[property='og:description']");if(e){return e.content.trim().replace(/\s+/g," ")}return""};var p=function(){var e;if(""!==(e=String(document.getSelection()))){if(r){e=e.trim().split("\n").map(function(e){return"> "+e}).join("\n")}}var t=location.hostname;var n;if(t in i){n=document.querySelector(i[t]);if(n){return c(n)}}if(!e){e=d()}return e};var h=location.href;var g=v();var y=p();var b=y.indexOf(g);if(b===0){y=y.substring(g.length).trim()}else if(b===y.length-g.length){y=y.substring(0,b).trim()}var j=m(document.title+" "+y+" "+d());if(a>0){g=g.substring(0,a);y=y.substring(0,a)}var w=["url=",encodeURIComponent(h),"&title=",encodeURIComponent(g),"&description=",encodeURIComponent(y),"&tags=",encodeURIComponent(j.join(" "))];if(e){w=w.concat(["&later=","yes","&jump=","close"])}if(t){w=w.concat(["&x-source=Safari","&x-success=",encodeURIComponent(location.href),"&x-cancel=",encodeURIComponent(location.href)]);window.location=t+w.join("")}else{var C=open("http://pinboard.in/add?"+w.join(""),"Pinboard","toolbar=no,width=610,height=350");if(e){C.blur()}}})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment