Last active
May 30, 2017 04:13
-
-
Save rvgpl/04e8cd3e693ce7ce9cd326a1a7d02812 to your computer and use it in GitHub Desktop.
Replaces copied text with a link to the page it is copied from, limits chars to 100
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
<script> | |
document.addEventListener('copy', function(e) { | |
var pageLink = '\n\n Read more at: ' + document.location.href; | |
var modifiedText = window.getSelection().toString().length > 100 ? window.getSelection().toString().substring(0,100) + pageLink : window.getSelection().toString() + pageLink; | |
if (e.clipboardData) { | |
e.clipboardData.setData('Text', modifiedText); | |
} | |
e.preventDefault(); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment