Log in Sign up

A bookmarklet to help with link blogging

How the tool works:

navigate to a website, click the bookmarklet, enter your caption and recieve a text-file.

For example, let's say you visit example.com and press the bookmarklet. You'll recieve a text file called Example.txt containing the following:

[Example](http://example.com)

Your caption here

How to install this bookmarklet

Make a new bookmark in your browser (right-click on the bookmarks bar and click Add Page...)

  • For the "Name" you might put "Save link".
  • Copy the code block below, paste this into the "URL" or "Location" of the new bookmark.
javascript:(function () {
  var caption = window.prompt("Would you like to add a caption?");
  if (caption === null) return;
  var textToSave = `[${document.title}](${window.location.href})\n\n${caption}`;
  var textToSaveAsBlob = new Blob([textToSave], { type: "text/plain" });
  var textToSaveAsURL = window.URL.createObjectURL(textToSaveAsBlob);
  var fileNameToSaveAs = document.title + ".txt";

  var downloadLink = document.createElement("a");
  downloadLink.download = fileNameToSaveAs;
  downloadLink.innerHTML = "Download File";
  downloadLink.href = textToSaveAsURL;
  downloadLink.onclick = (e) => document.body.removeChild(e.target);
  downloadLink.style.display = "none";
  document.body.appendChild(downloadLink);
  downloadLink.click();
})();

6 replies Asked Feb 16 '22 at 16:04 · Improve this question

Thank you for this!

Answered Feb 18 '22 at 14:12 · Improve this answer

David,

This is great. Thank you. I have a further request.

Would it be possible to post only the highlighted text? For instance, I'm reading an article and I want to post a couple of paragraphs, within blockquotes and citing the source, with a comment on top.

Here's what it could look like:

The most interesting argument the author makes is the following. Worth reading carefully:

The quick brown fox jumps over the lazy dog. It has always done so since time immemorial. [Source](Link)
Answered Feb 23 '22 at 4:37 · Improve this answer

In terms of retrieving currently highlighted text when the bookmark is clicked, you'd want to replace textToSave with something like this:

var textToSave = `${caption}\n\n> ${window.getSelection().toString()} [Source](${window.location.href})`;

Does that help?

Answered Feb 23 '22 at 13:08 · Improve this answer

It does help a lot thank you (catching up on this thread.)

I've slightly tweaked it to make it look like more a ready-to-post Blot entry:

javascript:(function () {
  var caption = window.prompt("Add a comment");
  if (caption === null) return;
  var textToSave = `Tags:\nDate:\n\n# BLOG POST TITLE HERE\n\n[${document.title}](${window.location.href})\n\n> ${window.getSelection().toString()}\n\n${caption}\n\n`;
  var textToSaveAsBlob = new Blob([textToSave], { type: "text/plain" });
  var textToSaveAsURL = window.URL.createObjectURL(textToSaveAsBlob);
  var fileNameToSaveAs = document.title + ".txt";

  var downloadLink = document.createElement("a");
  downloadLink.download = fileNameToSaveAs;
  downloadLink.innerHTML = "Download File";
  downloadLink.href = textToSaveAsURL;
  downloadLink.onclick = (e) => document.body.removeChild(e.target);
  downloadLink.style.display = "none";
  document.body.appendChild(downloadLink);
  downloadLink.click();
})();
Answered May 1 '22 at 6:03 · Improve this answer

Thanks for this! Very useful.

Ray

Answered Jul 31 '22 at 2:06 · Improve this answer

Great, thanks!

Answered Oct 11 '22 at 17:58 · Improve this answer

Markdown allowed