copytitle.js
OGP で使われている画像もコピーして、html, plain 両方の MIME でクリップボードに乗せる。
こうすることでリッチなエディタに貼り付けるとリンクはテキストリンクになり画像も付く。普通のテキストエディタに貼り付けるとスペース区切りのプレインなテキストになる。
code:copytitle.js
javascript:(async () => {
if (window.self !== window.top) return;
const a = document.createElement("a");
a.href = location.href;
a.innerText = document.title;
const text = ${document.title} ${location.href};
const container = document.createElement("div");
container.appendChild(a);
const data = [new ClipboardItem({
"text/plain": new Blob(text, { type: "text/plain" }), })];
await navigator.clipboard.write(data);
alert("コピーした");
})()