Skip to content

Instantly share code, notes, and snippets.

@LaptopHeaven
Created June 21, 2019 15:00
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 LaptopHeaven/afea7741bf891d2d31f74efcd96cd1ca to your computer and use it in GitHub Desktop.
Save LaptopHeaven/afea7741bf891d2d31f74efcd96cd1ca to your computer and use it in GitHub Desktop.
Save To Pinboard Bookmarket
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",arduino:"arduino",recipe: "recipe"};var o={"github.com":".entry-title .js-current-repository"};var i={"www.kickstarter.com":".short-blurb"};var a=function(e){return e.toLowerCase()};var c=function(e){return e?e.textContent.trim().replace(/\s+/g," "):null};var u=a(document.title);var l=function(e){if(e){return u.indexOf(a(e))!=-1}else{return false}};var f=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.item(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;var r=document.querySelector("meta[property='og:title']");if(r){n=r.content.trim().replace(/\s+/g," ")}var i,a;if(f(document.getElementsByClassName("hentry"),function(e){return true})){var u=document.querySelector(".hentry .entry-title");if(u){return c(u)}}var v=f(document.getElementsByTagName("A"),function(t){if(t.href==e){v=c(t);if(l(v)){return v}}return null});if(v){return v}var s=["h1","h2","h3","h4","h5","h6"];var m;var d;for(var h=0;h<s.length;++h){f(document.getElementsByTagName(s[h]),function(e){h_text=c(e);if(l(h_text)&&(!d||h_text.length>d.length)){d=h_text}return null})}if(d){return d}return n};var s=function(e){e=a(e);var t=[];var r;for(keyword in n){r=keyword instanceof RegExp?keyword:new RegExp("\\b"+keyword+"\\b","i");if(r.test(e)){t.push(n[keyword])}}return t};var m=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 d=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=m()}return e};var h=location.href;var p=v();var g=d();var y=g.indexOf(p);if(y==0){g=g.substring(p.length).trim()}else if(y==g.length-p.length){g=g.substring(0,y).trim()}var b=["url=",encodeURIComponent(location.href),"&title=",encodeURIComponent(p),"&description=",encodeURIComponent(g),"&tags=",encodeURIComponent(s(document.title+" "+g+" "+m()).join(" "))];if(e){b=b.concat(["&later=","yes","&jump=","close"])}if(t){b=b.concat(["&x-source=Safari","&x-success=",encodeURIComponent(location.href),"&x-cancel=",encodeURIComponent(location.href)]);window.location=t+b.join("")}else{var w=open("https://pinboard.in/add?"+b.join(""),"Pinboard","toolbar=no,width=850,height=600");if(e){w.blur()}}})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment