Skip to content

Instantly share code, notes, and snippets.

@naffiq
Last active May 13, 2016 09:38
Show Gist options
  • Save naffiq/210e47f324f08d6b78e60df87fec1ff0 to your computer and use it in GitHub Desktop.
Save naffiq/210e47f324f08d6b78e60df87fec1ff0 to your computer and use it in GitHub Desktop.
Adds text to copied content from website
function addLink() {
//Get the selected text and append the extra info
var selection = window.getSelection(),
pagelink = '<br /><br /> Подробнее: ' + document.location.href
+ '. Любое использование материалов допускается только при наличии гиперссылки на azan.kz',
copytext = selection + pagelink,
newdiv = document.createElement('div');
//hide the newly created container
newdiv.style.position = 'absolute';
newdiv.style.left = '-99999px';
//insert the container, fill it with the extended text, and define the new selection
document.body.appendChild(newdiv);
newdiv.innerHTML = copytext;
selection.selectAllChildren(newdiv);
window.setTimeout(function () {
document.body.removeChild(newdiv);
}, 100);
}
document.addEventListener('copy', addLink);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment