PDA

View Full Version : Copying text adds additional information to the clipboard



djr33
10-11-2014, 10:25 PM
I have found some websites that attach extra text (usually citation information and URL) to the end of text copied from webpages.

Two examples:
informahealthcare.com/doi/abs/10.3109/02699208808985246
ethos.bl.uk/OrderDetails.do?uin=uk.bl.ethos.376051
I've also seen this on some news (eg, newspaper) websites.

Select any text on the page, then copy it and paste it to a new document. You'll find that additional text is added to whatever you selected.


I have two questions:

Just out of curiosity:
1. How is this done? Is it Javascript?

More importantly:
2. Is there any way that I can disable this in my browser? (I use Firefox, but general answers or for other browsers are fine too.)

I find this to be incredibly annoying because, as you can see from the links I posted above, I'm trying to use these websites for bibliographic information and I want to copy and paste titles, authors' names, etc. I will even include a link to those pages where appropriate. But the websites insist on informing me every time where the data is from (I know that, of course), and then I need to remove it.

I really don't see the point in this because it's not like someone is going to copy and paste text, ignore the additional information, then post it somewhere for the world to see so they can click on the link.

jscheuer1
10-11-2014, 10:48 PM
Yes.

Disable javascript.

There might also be some counter javascript code that you can run to unbind the event. But I would want to see the uncompressed version of the code used to create it in the first place. This could conceivably vary from site to site as well. And the countermanding code - if any, would probably vary from browser to browser too.

jscheuer1
10-11-2014, 10:59 PM
I'm looking at the minimized code used by your first example. It looks like it attaches the event in multiple ways, using whatever javascript libraries might be available on the page as well as the standard javascript addEventListener method. Turning off one or two of these might not be enough to stop the code from executing.

How big of a deal is this? You can always paste your selection and then cut/delete the added byline.

djr33
10-16-2014, 04:51 AM
Not that big of a deal. I've been busy and haven't thought of it for a couple days, but I'm just interested in it conceptually. I can certainly fix it manually, but that gets tiresome (to where I sometimes just type out the line of text by hand rather than cutting and pasting).

I suspected it might be a layered approach that would be intentionally difficult to circumvent. Really absurd in my opinion, given that it doesn't stop anything or help anything. It's just like placing a sticker on everyone as they walk out of a store-- they'll take them off and be less inclined to return.

Thanks for looking into it! I am glad at least to know that this is in fact Javascript. It seems like something browsers should reject, as they often do with no-right-click scripts. (I'd like to add such things to a browser plugin at some point...)

molendijk
10-16-2014, 11:38 AM
It's done with javascript alright.
informahealthcare.com/doi/abs/10.3109/02699208808985246 achieves it via a js-file oncopy.js, which has the following:


(function(){var r=function(w,k){var j=document,g=j.body,l=j.documentElement,i=window,s=function(){var a=i.OnCopy||{};a.SEPARATOR=a.SEPARATOR||"<br/></br/>";a.READ_MORE=a.READ_MORE||"Read More: ";a.URL=a.URL||i.location.href;a.TITLE=a.TITLE||(j.title||i.location.hostname).toString().replace(RegExp(i.location.hash,"g"),"");if(a.USE_URL_AS_TITLE===k)a.USE_URL_AS_TITLE=true;if(a.USE_URL_AS_TITLE)a.TITLE=a.URL;a.SELECTOR=a.SELECTOR||"#articleContent";a.WORDS_MIN=a.WORDS_MIN||7;a.STRIP=a.STRIP||"script";
return a},h=s(),t=function(a,d){for(var b in d)if(d.hasOwnProperty(b))a.style[b]=d[b]},m=function(a,d,b){a=j.createElement(a);if(d!==k){var e=a,c;for(c in d)if(d.hasOwnProperty(c))e[c]=d[c]}b!==k&&t(a,b);return a},p=function(a){i.setTimeout(a,0)},u=function(a){var d=m("div"),b=m("span",{innerHTML:h.SEPARATOR+h.READ_MORE+'<a href="'+h.URL+'">'+h.TITLE+"</a>"});if(typeof a=="string")d.innerHTML=a;else d.appendChild(a);d.appendChild(m("br"));d.appendChild(b);a=d;if(b=h.STRIP){b=b.split(" ");for(var e=
0;e<b.length;++e){a=a.getElementsByTagName(b[e]);for(var c=a.length-1;c>=0;c--){var f=a[c];f.parentNode.removeChild(f)}}}return d},n=false,q=function(){var a=function(){var b=i.getSelection();if(b.toString()){var e=b.getRangeAt(0),c=u(e.cloneContents());if(b.setBaseAndExtent!==k){t(c,{width:1,height:1,position:"absolute",left:"-10000px",top:"-10000px"});c.appendChild(m("br"));g.insertBefore(c,g.firstChild);b.selectAllChildren(c);p(function(){c.parentNode.removeChild(c);i.getSelection().setBaseAndExtent(e.startContainer,
e.startOffset,e.endContainer,e.endOffset);n=false})}else{var f=m("div");g.appendChild(f);f.appendChild(c);var o=j.createRange();o.selectNode(c);b.removeAllRanges();b.addRange(o);p(function(){f.parentNode.removeChild(f);b.removeAllRanges();b.addRange(e);n=false})}}},d=fu nction(){var b={left:l.scrollLeft?l.scrollLeft:g.scrollLeft,top:l.scrollTop?l.scrollTop:g.scrollTop},e=m("div",{},{visibility:"hidden",overflow:"hidden",position:"absolute",left:b.left+"px",top:b.top+"px",width:"1px",height:"1px"});
g.insertBefore(e,g.firstChild);var c=j.selection.createRange(),f=u(c.htmlText);e.appendChild(f);var o=g.createTextRange();o.moveToElementText(f);o.select();p(function(){e.parentNode.removeChild(e);c.select();l.scrollLeft=b.left;g.scrollLeft=b.left;l.scrollTop= b.top;g.scrollTop=b.top;n=false})};q=i.getSelection!==k?a:d;q()},v=function(a){if(n)return false;h=s();var d=i.getSelection!==k?i.getSelection().toString():j.selection.createRange().text;if((d?d.split(/\s+/).length:0)>=h.WORDS_MIN){a=a.target||
a.srcElement;var b=true;if(h.SELECTOR&&h.SELECTOR!=""){b=false;var e=d=null;if(h.SELECTOR.charAt(0)==".")e=h.SELECTOR.substring(1);else d=h.SELECTOR.substring(1);for(;a&&!b;){if(e)a:{var c=e;if(a.className){b=a.className.split(" ");c=c.toUpperCase();for(var f=0;f<b.length;f++)if(b[f].toUpperCase()==c){b=true;break a}}b=false}else b=d==a.id;b=b;a=a.parentNode}}if(b){n=true;q()}}return true};i.addEventListener?g.addEventListener("copy",v,false):g.attachEvent("oncopy",v)};if(typeof jQuery!="undefined")jQuery(document).ready(r);
else if(typeof window.Prototype!="undefined")document.observe("dom:loaded",r);else typeof YAHOO!="undefined"&&YAHOO.util.Event.onDOMReady(r)})();

I don't know about the other site because it's inaccessible at the moment.
If both sites use the same javascript for info added oncopy, then it might be possible to write a plugin that destroys it.

jscheuer1
10-20-2014, 03:25 AM
This just happened to me as I was annotating a friend's post on FB. But, it was actually a good thing. It automatically provided a link back to my source for anyone wanting even more information.