-
-
Save iethree/9e39fd79e3d2e7f55aed39643066be59 to your computer and use it in GitHub Desktop.
Github PR/Issue copy bookmarklet
This file contains hidden or 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
| javascript: (function copyLink() { | |
| const url = location.href; | |
| const m = url.match( | |
| /https:\/\/github.com\/metabase\/[a-zA-Z0-9_.-]+\/(issues|pull)\/(\d+)/, | |
| ); | |
| 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); | |
| } | |
| if (m) { | |
| let [_, type, id] = m; | |
| const title = document.querySelector(".markdown-title").textContent; | |
| const isDraft = !!document.querySelector( | |
| 'span[data-status="draft"]', | |
| ); | |
| const isMerged = !!document.querySelector( | |
| 'span[data-status="pullMerged"]', | |
| ); | |
| const emoji = { | |
| issues: ":github-issue:", | |
| pull: ":pull-request:", | |
| draft: ":draft-pull-request:", | |
| merged: ":merged:", | |
| }; | |
| if (isDraft) type = "draft"; | |
| if (isMerged) type = "merged"; | |
| const link = `${emoji[type]} <a href="${url}" target="_blank">${title}</a>`; | |
| copyToClip(link); | |
| } else { | |
| copyToClip(url); | |
| } | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I can't get copyToClip to work in Brave, either (even when I select the text first. It copies the whole script instead of the contents of the title.
What does work is:
navigator.clipboard.writeText(link)