Last active
September 26, 2019 16:32
-
-
Save cdzombak/ac36376c195006d886e76fdc2241c822 to your computer and use it in GitHub Desktop.
Bookmarklet which builds a Markdown link to the current page
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(){var%20e=window.getSelection().toString(),t=document.title.replace(%22%20-%20Jira%22,%22%22),n=e%3Fe:t,o=%22[%22+n+%22](%22+location.href+%22)%22;(function(e){var%20t=document.createElement(%22textarea%22),n=document.getSelection();t.textContent=e,document.body.appendChild(t),n.removeAllRanges(),t.select(),document.execCommand(%22copy%22),n.removeAllRanges(),document.body.removeChild(t)})(o)}(); |
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
| var selection = window.getSelection().toString(); | |
| var cleanTitle = document.title.replace(" - Jira", ""); | |
| var anchor = selection ? selection : cleanTitle; | |
| var result = '[' + anchor + '](' + location.href + ')'; | |
| (function (text) { | |
| // https://gist.github.com/stefanmaric/2abf96c740191cda3bc7a8b0fc905a7d | |
| var node = document.createElement('textarea'); | |
| var selection = document.getSelection(); | |
| node.textContent = text; | |
| document.body.appendChild(node); | |
| selection.removeAllRanges(); | |
| node.select(); | |
| document.execCommand('copy'); | |
| selection.removeAllRanges(); | |
| document.body.removeChild(node); | |
| })(result); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This bookmarklet builds a Markdown link to the current page, using the selected text (if any) or the page title as the link title.
Caveats
This works in Chrome. I have not tested it in any other browser.
Installation
Build Notes
I'm using http://chriszarate.github.io/bookmarkleter/ to convert the script to a bookmarklet.