Last active
October 2, 2023 21:20
-
-
Save thiskevinwang/3de32192ec804630f698132f44d38d08 to your computer and use it in GitHub Desktop.
Arc Boost — Click to copy GitHub PR title as richtext link to Clipboard
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
function copyToClip(str) { | |
function listener(e) { | |
e.clipboardData.setData("text/html", str); | |
e.clipboardData.setData("text/plain", str); | |
e.preventDefault(); | |
} | |
document.addEventListener("copy", listener); | |
document.execCommand("copy"); | |
document.removeEventListener("copy", listener); | |
}; | |
window.addEventListener("load", (event) => { | |
const [titleElem] = document.querySelectorAll(".gh-header-title") | |
const innerHtml = titleElem.innerHTML | |
const link = document.createElement("a") | |
link.innerHTML = innerHtml | |
link.setAttribute("href", window.location.href) | |
titleElem.replaceChildren(link) | |
link.addEventListener("click", (e) => { | |
e.preventDefault() | |
copyToClip(titleElem.innerHTML) | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tweet w/ video preview: https://x.com/thekevinwang/status/1708953097672781849?s=20