Skip to content

Instantly share code, notes, and snippets.

@Arty2
Created October 31, 2015 10:25
Show Gist options
  • Save Arty2/9279e00fdb07f50d0b43 to your computer and use it in GitHub Desktop.
Save Arty2/9279e00fdb07f50d0b43 to your computer and use it in GitHub Desktop.
Copy & paste hijacking for forcing credit with "Read more" and URL. Antilogue: http://daringfireball.net/2010/05/tynt_copy_paste_jerks
/*
copy & paste hijacking for forcing credit with "Read more" and URL
antilogue: http://daringfireball.net/2010/05/tynt_copy_paste_jerks
*/
function copypasta() {
var body_element = document.body;
var pagelink = ' Read more: '+window.location.href.split('#')[0]+'';
if (window.getSelection) {
var selection = window.getSelection();
var copytext = selection.toString().replace(/\n/g, '<br />') + '<br /><br /><br />' + pagelink;
var newdiv = document.createElement('div');
newdiv.style.position = 'absolute';
newdiv.style.left = '-99999px';
body_element.appendChild(newdiv);
newdiv.innerHTML = copytext;
selection.selectAllChildren(newdiv);
window.setTimeout(function() { body_element.removeChild(newdiv); },0);
}
else { //IE stuff
var selection = document.selection.createRange();
var copytext = selection.text + "\r\n\r\n\r\n" + pagelink;
//alert(window.clipboardData.setData("Text", copytext));
var copied = window.clipboardData.setData("Text", copytext);
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment