Last active
November 26, 2021 11:13
-
-
Save ushironoko/0a396f543aa48a54ba71864c0a4f5166 to your computer and use it in GitHub Desktop.
Place a button to copy the GitHub title and URL
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
// https://chrome.google.com/webstore/detail/scriptautorunner/gpgjofmpmjjopcogjgdldidobhmjmdbm?hl=ja-jp | |
const title = document.querySelector('.js-issue-title')?.textContent.trim() | |
if(title) { | |
const url = location.href | |
const copyButton = document.createElement('button') | |
copyButton.addEventListener('click', () => navigator.clipboard.writeText(`${title}\n${url}`)) | |
copyButton.textContent = "copy" | |
copyButton.classList.add("btn", "btn-sm", "ml-1") | |
const copyButtonAsMarkdown = document.createElement('button') | |
copyButtonAsMarkdown.addEventListener('click', () => navigator.clipboard.writeText(`[${title}](${url})`)) | |
copyButtonAsMarkdown.textContent = "copy as markdown" | |
copyButtonAsMarkdown.classList.add("btn", "btn-sm", "ml-1") | |
const targetElement = document.querySelector('.gh-header-actions') | |
setTimeout(() => { | |
targetElement.appendChild(copyButton) | |
targetElement.appendChild(copyButtonAsMarkdown) | |
}, 1000) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment