Thursday, 17 April 2008

Anti copy-paste feature

Jessica loves to frequent, an online community for Indonesian writers. Today she showed me a nifty feature of the website: an anti copy-paste protection. Different from other websites that just simply lock your right click button using Javascript, this website places hidden random characters interspersed with the text (basically a span with "display:none"). When you decide to copy a block of text using your browser, those hidden characters are copied as well.

See the following story as an example (nevermind the story if you don't understand Indonesian). Try copying a block of text from the story and pasting it into a word processor. The first line which should read:
Niwa pikir, setelah pindah sekolah, keadaannya akan berbeda.

turns into:
NiwaJ pik|ir,D sHe1tSe%lXa6h3 piVnd%ahZ seko0lah,U keXadKaaZnn&ya7 akanM be*rbIedEa.

This got me thinking. Of course I could write a off line script which parse and remove the span elements from copied text. But then I decided that doing it from Firefox would be more fun. I then opened my Firebug panel and started tinkering with the Javascript console. I came up with the following short scripts:

lis = document.getElementsByTagName('span');
for( i=0;i<lis.length;i++ ) {
cl = lis[i].getAttribute('class');
if( cl && cl[0]=='c' ) {

It basically loops through all span elements and finds the elements starting with 'c'. The copy protection happens to start all of the hidden classes with 'c'. Once all of the offending elements are found, it is very easy to remove the random characters inside.

How to use this hack:
1. Download Firefox
2. Install Firebug
3. Open Firebug on the offending page
4. Tick 'Large Command Line' from 'Options' drop down menu
5. Paste this script on the large console window on the left
6. And finally click 'Run'.

PS: I am not encouraging any piracy or plagiarism. I personally think that the copy protection system is very interesting, the first one I have seen on the net. I just take this as a technical challenge, kind of a hobby thing :)

1 comment:

gufo said...

I think that her solution is on the Flash, otherwise how is she replacing the text on the clipboard?