Created
November 25, 2024 17:50
-
-
Save rauschma/af64f1224a9f5ae81c0cd63a294c28ef to your computer and use it in GitHub Desktop.
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:{ | |
const text = getSelection().toString().trim(); | |
if (text.length > 0) { | |
const urlToHighlight = new URL(location); | |
urlToHighlight.hash = '#:~:text=' + encodeURIComponent(text); | |
navigator.clipboard.writeText(urlToHighlight.href) | |
.catch((error) => { | |
alert(String(error)); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment