Created
December 20, 2022 23:54
-
-
Save dzharii/6f2e3627292e72af654975e05428dc62 to your computer and use it in GitHub Desktop.
This JavaScript snippet is a browser bookmarklet, which copies the active browser tab / page title and url as a markdown link into the clipboard. If some text is selected, it will copy the selection as a markdown quote. This is a hacky way to write javascript to write an entire script in one JavaScript line.
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: [ | |
(() => [ | |
'[', document.title, ']', '(', window.location.href, ')', '\n', | |
(window.getSelection().toString().trim()) | |
? window.getSelection() | |
.toString() | |
.trim() | |
.split('\n') | |
.filter((line) => line.trim() !== '') | |
.map((line) => ' > ' + line) | |
.join('\n') + '\n' | |
: undefined | |
].join('')), | |
(window.navigator.clipboard) | |
? (content) => setTimeout(() => navigator.clipboard.writeText(content)) | |
: undefined, | |
].filter((item) => typeof item !== 'undefined') | |
.reduce((accumulator, item) => | |
typeof item === 'function' | |
? item(accumulator) | |
: accumulator, 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment