Created
November 10, 2023 01:13
-
-
Save stcalica/3b6a12d595bcd74dea0bd7d8862ff8b4 to your computer and use it in GitHub Desktop.
Appending data to copied text when there's a copy action
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
document.addEventListener('copy', function(event) { | |
// Get the selected text | |
var selectedText = window.getSelection().toString(); | |
// Generate a nonce (unique identifier) | |
var nonce = 'my_unique_nonce'; | |
// Append the nonce to the selected text | |
var modifiedText = selectedText + ' [Nonce: ' + nonce + ']'; | |
// Copy the modified text to the clipboard | |
event.clipboardData.setData('text/plain', modifiedText); | |
// Prevent the default copy behavior | |
event.preventDefault(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment