Here is the Javascript code that will add extra information in the copied web text. Basically it is to create an invisible DOM element and fill it with copied html code by adding the extra information.
Source
function addLink() {
//Obtem o texto selecionado e acrescenta as informações extras
var selection = window.getSelection(),
pagelink = '<br /><br /> mensagem de direitos autorais: ' + document.location.href,
copytext = selection + pagelink,
newdiv = document.createElement('div');
//esconder a div recém-criada
newdiv.style.position = 'absolute';
newdiv.style.left = '-99999px';
//insere a div, adiciona as informações extras e defina a nova seleção
document.body.appendChild(newdiv);
newdiv.innerHTML = copytext;
selection.selectAllChildren(newdiv);
window.setTimeout(function () {
document.body.removeChild(newdiv);
}, 100);
}
document.addEventListener('copy', addLink);
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam hendrerit orci vel urna tincidunt, id aliquet leo dapibus. Nunc sodales arcu auctor, aliquam augue ut, blandit lorem. Ut eleifend dui in interdum fringilla. Etiam eleifend, sem et varius ornare, massa tellus tincidunt metus, ac ultricies ex diam ac arcu. Pellentesque at scelerisque ex. Quisque lobortis lectus sit amet porttitor dapibus. Nunc eget sagittis enim. Aenean mollis rutrum ante. Etiam lacinia aliquam pellentesque. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
<br>
<textarea placeholder="Cole aqui o texto copiado" rows="12" cols="52"></textarea>
To include page title (document.title
) in the extra information:
pagelink = '<br /><br /> © '+document.title+'<br /> mensagem de direitos ..................
You can determine from which length of the selected text should display the extra information. Just add that line in the code
if (("" + selection).length < 30) return;
Complete code:
function addLink() {
//Obtem o texto selecionado e acrescenta as informações extras
var selection = window.getSelection();
//se a seleção é curta não vamos incomodar nossos usuários
if (("" + selection).length < 30) return;
var pagelink = '<br /><br /> mensagem de direitos autorais: ' + document.location.href + ' © ' +document.domain,
copytext = selection + pagelink,
newdiv = document.createElement('div');
//esconder a div recém-criada
newdiv.style.position = 'absolute';
newdiv.style.left = '-99999px';
//insere a div, adiciona as informações extras e defina a nova seleção
document.body.appendChild(newdiv);
newdiv.innerHTML = copytext;
selection.selectAllChildren(newdiv);
window.setTimeout(function () {
document.body.removeChild(newdiv);
}, 100);
}
document.addEventListener('copy', addLink);
Tip: By own experience, it is no use trying to block your code or text, anyway it is always possible to copy it, or someone will be able to do the same. Copyright is independent of registration but only protects a content in full as seen in the law: http://www.casadoautorbrasileiro.com.br/direito-autoral/nocoes-basicas
– Sveen
Putting a text with the Logo Copyright for law is merely illustrative
– Sveen