Skip to content

Instantly share code, notes, and snippets.

@ukikagi
Last active September 30, 2020 03:28
Show Gist options
  • Save ukikagi/b46508261d58f267072050c88a9424ac to your computer and use it in GitHub Desktop.
Save ukikagi/b46508261d58f267072050c88a9424ac to your computer and use it in GitHub Desktop.
const title = document.title;
const url = location.href;
function listener(e) {
e.clipboardData.setData("text/html", `<a href="${url}">${title}</a>`);
e.clipboardData.setData("text/plain", `[${title}](${url})`);
e.preventDefault();
}
document.addEventListener("copy", listener);
document.execCommand("copy");
document.removeEventListener("copy", listener);
@ukikagi
Copy link
Author

ukikagi commented Sep 30, 2020

TODO: Escape the title properly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment