📑 Copying all Pocket highlights with a bookmarklet

Bookmarked Copying all Pocket highlights with a bookmarklet (philnewton.net)
I do not use Highlights with Pocket as I was not sure how they would fit with my workflow. However, after finding this bookmarklet from Phil Newton, I am thinking that maybe I could.

to_clipboard = "#+TITLE: " + document.getElementsByTagName('h1')[0].innerHTML + "\n\n";
all_highlights = document.getElementsByClassName('highlight');
for (highlight in all_highlights) {
highlight_text = all_highlights[highlight].innerHTML;
if (typeof highlight_text !== 'undefined' && highlight_text.trim() != '') {
to_clipboard += "#+begin_quote\n";
to_clipboard += highlight_text.trim() + "\n";
to_clipboard += "#+end_quote\n\n";
}
}
to_clipboard += "*Source*: " + document.getElementById('reader.external-link.view-original').href;
navigator.clipboard.writeText(to_clipboard);

I worked with CoPilot to change the structure to how I wanted it:

javascript:(function(){
for(i in o="",h=document.getElementsByClassName("highlight"),h){
t=h[i].innerHTML,
"undefined"!=typeof t&&""!=t.trim()&&(o+="> "+t.trim().replace(/\n/g, "\n> ")+"\n\n");
}
var url = document.getElementById("reader.external-link.view-original").href;
url = url.replace("?utm_source=pocket_saves", "");
o+="Source: ["+document.getElementsByTagName("h1")[0].innerHTML+"]("+url+")"
+document.getElementsByClassName("css-1ba1zfw")[0].innerText;
navigator.clipboard.writeText(o);
})()

It was an interesting process where I tried some things and was corrected. This was much quicker than learning it from scratch.

Leave a Reply

Your email address will not be published. Required fields are marked *