Creating a dependable Pinboard bookmarklet β especially for extracting structured data from sites like arXiv.org β sounds simple, but there are surprising complexities. This guide documents the key lessons and quirks uncovered while building one.
If your Pinboard URL includes later=yes
, it will silently ignore the description
field β no error, just no description saved.
β Fix:
- Do not use
later=yes
- Use a
window.open()
popup instead, which allows the description to be preserved
window.open(pinURL, "Pinboard", "toolbar=no,width=700,height=350");
Since bookmarklets are often pasted into a single-line input field (like the browser's bookmarks bar), using //
will break the code.
β Fix:
Use block comments (/* ... */
) only.
APIs like getElementsByClassName
may return unexpected results due to dynamic content or page structure.
β Fix:
- Use
document.querySelector()
ordocument.querySelectorAll()
- Always check for
null
orundefined
before accessing.textContent
Avoid parsing the title manually from page elements. document.title
is reliable and already includes the paper ID.
var title = document.title;
If any part of the Pinboard URL is unescaped, the whole request may break.
β Fix:
var esc = function (s) {
return encodeURIComponent(s);
};
Use it for every URL component: url
, title
, description
, tags
, etc.
Long descriptions are okay, but Pinboard fields should be clean:
β Tips:
- Strip the
"Abstract:"
prefix - Collapse all whitespace
trim()
the final result
var desc = abs.textContent
.replace(/^\s*Abstract:\s*/i, "")
.replace(/\s+/g, " ")
.trim();
Pinboard gives zero feedback when fields are dropped or broken. Use alert()
to confirm the final URL.
alert(pinURL);
We were able to reliably extract:
Field | Method |
---|---|
Paper ID | Regex match from location.href |
Authors | div.authors β normalized author:john_doe format |
Subjects | td.tablecell.subjects β extract arXiv tags from parentheses |
Year | div.dateline β 20XX year match |
Title | From document.title |
Abstract | From blockquote.abstract β normalized as description |
Writing Pinboard bookmarklets isnβt hard β until you care about quality:
- βοΈ Remove
later=yes
- π Donβt use
//
comments - π΅οΈ DOM is fickle β always check for nulls
- π§Ό Normalize everything
- π¨ Alert before you open
- π‘ Use the popup!
Made through trial, error, and a healthy amount of rebellion βοΈ