A bookmarklet to copy the page title & URL in a Markdown link format for Obsidian notes.
If any text is copied on the page when clicking the bookmarklet, the selected bit is copied as a blockquote above the link.
(() => {
const copy = (title, url, selection) => {
const textArea = document.createElement("textarea");
let text = "";
if (selection && selection != "") {
text = `> ${selection}\n`;
}
text += `[${title}](${url})`;
textArea.value = text;
textArea.style.top = "0";
textArea.style.left = "0";
textArea.style.position = "fixed";
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
document.execCommand("copy");
} catch (err) {
console.error("Copying err", err);
}
document.body.removeChild(textArea);
};
copy(document.title, window.location.href, window.getSelection());
})();
To minify into a bookmarklet, use Bookmarklet Maker.
Credits
Original idea from Rude Goldberg machine of quickly copying data from browser to notes by Joona Keskitalo