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();
})();
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 3 years ago · Edit 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 3 years ago · Edit answerIt 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 3 years ago ·
Edit answer