Skip to content

Instantly share code, notes, and snippets.

@thiskevinwang
Last active October 2, 2023 21:20
Show Gist options
  • Save thiskevinwang/3de32192ec804630f698132f44d38d08 to your computer and use it in GitHub Desktop.
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
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)
})
});
@thiskevinwang
Copy link
Author

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