Skip to content

Instantly share code, notes, and snippets.

@rvgpl
Last active May 30, 2017 04:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rvgpl/04e8cd3e693ce7ce9cd326a1a7d02812 to your computer and use it in GitHub Desktop.
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
<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