>>106983569
More if you’re a Markdown enjoyer:
javascript: (function () {
const activeEl = document.activeElement;
let selectedText = "";
if (
activeEl &&
(activeEl.tagName === "TEXTAREA" ||
(activeEl.tagName === "INPUT" && activeEl.type === "text"))
) {
selectedText = activeEl.value.substring(
activeEl.selectionStart,
activeEl.selectionEnd
);
} else {
selectedText = window.getSelection().toString();
}
if (!selectedText) {
return;
}
const title = document.title;
const url = window.location.href;
const mdLink = `[${title}](${url})`;
const quotedText = selectedText
.split("\n")
.map((line) => "> " + line)
.join("\n");
const result = `${mdLink}\n\n${quotedText}`;
navigator.clipboard.writeText(result).then(
() => {},
(err) => {
console.error("Clipboard copy failed:", err);
alert("Failed to copy: " + err);
}
);
})();
I keep this in a .js file
I thought I’d have to manually tack on the javascript: part but then I remembered that labels in JavaScript are a thing