Skip to content

Instantly share code, notes, and snippets.

@warthurton
Last active January 19, 2017 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save warthurton/aa0d23d869fb3de2245fd78a37699201 to your computer and use it in GitHub Desktop.
Save warthurton/aa0d23d869fb3de2245fd78a37699201 to your computer and use it in GitHub Desktop.
javascript:(function(){var e=false;var r=null;var t=true;var n={javascript:"javascript",js:"javascript",python:"python",ios:"ios",youtube:"video",vimeo:"video",video:"video",books:"book",book:"book",game:"games",games:"games",recipe:"recipe",recipes:"recipe",food:"recipe",ingredients:"recipe",meal:"recipe"};var o={"github.com":".entry-title .js-current-repository"};var i={"www.kickstarter.com":".short-blurb"};var a=1e3;var c=function(e){return e.toLowerCase()};var u=function(e){return e?e.textContent.trim().replace(/\s+/g," ").substring(0,a):null};var l=c(document.title);var s=function(e){if(e){return l.indexOf(c(e))!==-1}else{return false}};var f=function(e,r,t){t=t||window;var n=e.length;var o;for(var i=0;i<n;++i){o=r.call(t,e[i]);if(o!==null){return o}}return null};var v=function(){var e=location.href;var r=location.hostname;var t;if(r in o){t=document.querySelector(o[r]);if(t){return u(t)}}var n=document.title;t=document.querySelector("meta[property='og:title']");if(t){n=t.content.trim().replace(/\s+/g," ")}if(f(document.getElementsByClassName("hentry"),function(){return true})){var i=document.querySelector(".hentry .entry-title");if(i){return u(i)}}var a=f(document.getElementsByTagName("A"),function(r){if(r.href===e){a=u(r);if(s(a)){return a}}return null});if(a){return a}var c=["h1","h2","h3","h4","h5","h6"];var l;for(var v=0;v<c.length;++v){f(document.getElementsByTagName(c[v]),function(e){var r=u(e);if(s(r)&&(!l||r.length>l.length)){l=r}return null})}if(l){return l}return n};var m=function(e){e=c(e);var r=[];var t;for(var o in n){t=o instanceof RegExp?o:new RegExp("\\b"+o+"\\b","i");if(t.test(e)){r.push(n[o])}}return r};var p=function(){var e;e=document.querySelector("meta[name='description']");if(e){return e.content.trim().replace(/\s+/g," ").substring(0,a)}e=document.querySelector("meta[property='og:description']");if(e){return e.content.trim().replace(/\s+/g," ").substring(0,a)}return""};var d=function(){var e;if(""!==(e=String(document.getSelection()))){if(t){e=e.trim().split("\n").map(function(e){return"<blockquote>"+e+"</blockquote>"}).join("\n")}}var r=location.hostname;var n;if(r in i){n=document.querySelector(i[r]);if(n){return u(n)}}if(!e){e=p()}return e};var g=location.href;var h=v();var b=d();var y=b.indexOf(h);if(y===0){b=b.substring(h.length).trim()}else if(y===b.length-h.length){b=b.substring(0,y).trim()}var j=m(document.title+" "+b+" "+p());if(a>0){h=h.substring(0,a);b=b.substring(0,a)}var w=["url=",encodeURIComponent(g),"&title=",encodeURIComponent(h),"&description=",encodeURIComponent(b),"&tags=",encodeURIComponent(j.join(" "))];if(e){w=w.concat(["&later=","yes","&jump=","close"])}if(r){w=w.concat(["&x-source=Safari","&x-success=",encodeURIComponent(location.href),"&x-cancel=",encodeURIComponent(location.href)]);window.location=r+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