Last active
September 30, 2020 03:28
-
-
Save ukikagi/b46508261d58f267072050c88a9424ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TODO: Escape the title properly