Last active
October 9, 2024 14:16
-
-
Save jsit/85bc9a1759b62bec14fb5d05f20dffe9 to your computer and use it in GitHub Desktop.
Pinboard Bookmarklet -- Use text selection for description if available, otherwise use meta description, and include referrer in description if exists.
This file contains hidden or 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
javascript: q = location.href; | |
q = q.replace(/[?&]utm_[^&]*/g, ""); | |
q = q.replace(/[?&]mc_[^&]*/g, ""); | |
q = q.replace(/[?&]src=[^&]*/g, ""); | |
q = q.replace(/[?&]ref=[^&]*/g, ""); | |
desc = ""; | |
if (document.getElementsByName("description").length > 0) { | |
desc = document.getElementsByName("description")[0].getAttribute("content") | |
"\n\n" | |
} else if (document.getElementsByName("Description").length > 0) { | |
desc = document.getElementsByName("Description")[0].getAttribute("content") | |
"\n\n" | |
} else { | |
var metas = document.getElementsByTagName("meta"); | |
for (var pcounter = 0; pcounter < metas.length; pcounter) { | |
if (metas[pcounter].getAttribute("property") == "og:description") desc = metas[pcounter].getAttribute("content") | |
"\n\n" | |
} | |
} | |
if (document.getSelection) { | |
d = document.getSelection() | |
} else { | |
d = "" | |
} | |
if (document.referrer) { | |
via = "\n\nvia: " | |
document.referrer | |
} else { | |
via = "" | |
} | |
p = document.title; | |
void open("https://pinboard.in/add?showtags=yes&url=" | |
encodeURIComponent(q) | |
"&description=" | |
encodeURIComponent(desc) | |
"\n\n" | |
encodeURIComponent(d) encodeURIComponent(via) | |
"&title=" | |
encodeURIComponent(p), "Pinboard", "toolbar=no,scrollbars=yes,width=750,height=700"); |
This file contains hidden or 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
javascript:q=location.href;q=q.replace(/%5B?&%5Dutm_%5B%5E&%5D*/g,%22%22);q=q.replace(/%5B?&%5Dmc_%5B%5E&%5D*/g,%22%22);q=q.replace(/%5B?&%5Dsrc=%5B%5E&%5D*/g,%22%22);q=q.replace(/%5B?&%5Dref=%5B%5E&%5D*/g,%22%22);desc=%22%22;if(document.getElementsByName(%22description%22).length%3E0)%7Bdesc=document.getElementsByName(%22description%22)%5B0%5D.getAttribute(%22content%22)+%22%5Cn%5Cn%22%7Delse%20if(document.getElementsByName(%22Description%22).length%3E0)%7Bdesc=document.getElementsByName(%22Description%22)%5B0%5D.getAttribute(%22content%22)+%22%5Cn%5Cn%22%7Delse%7Bvar%20metas=document.getElementsByTagName(%22meta%22);for(var%20pcounter=0;pcounter%3Cmetas.length;pcounter++)%7Bif(metas%5Bpcounter%5D.getAttribute(%22property%22)==%22og:description%22)desc=metas%5Bpcounter%5D.getAttribute(%22content%22)+%22%5Cn%5Cn%22%7D%7Dif(document.getSelection)%7Bd=document.getSelection()%7Delse%7Bd=%22%22%7Dif(document.referrer)%7Bvia=%22%5Cn%5Cnvia:%20%22+document.referrer%7Delse%7Bvia=%22%22%7Dp=document.title;void%20open(%22https://pinboard.in/add?showtags=yes&url=%22+encodeURIComponent(q)+%22&description=%22+encodeURIComponent(desc)+%22%5Cn%5Cn%22+encodeURIComponent(d)+encodeURIComponent(via)+%22&title=%22+encodeURIComponent(p),%22Pinboard%22,%22toolbar=no,scrollbars=yes,width=750,height=700%22); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment