Skip to content

Instantly share code, notes, and snippets.

@wemakeweb
Forked from dbox/copy paste append
Created January 30, 2013 13:36
Show Gist options
  • Save wemakeweb/4673349 to your computer and use it in GitHub Desktop.
Save wemakeweb/4673349 to your computer and use it in GitHub Desktop.
var radium=[];
if("undefined"==typeof radium.init){var readatURL="",ctrl;(function(){var f=function(){var d=document.body,j=document.documentElement,l=function(b,a){for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c])},k=function(b,a,c){b=document.createElement(b);l(a,b);l(c,b.style);return b},f=function(){var b,a=function(){window.removeEventListener("blur",a,!1);m(b);return!0};return function(c){b=c.target||c.srcElement;window.removeEventListener("blur",a,!1);"IMG"==b.nodeName&&"A"!=b.parentNode.nodeName&&(window.addEventListener("blur",
a,!1),setTimeout(function(){document.removeEventListener("blur",a,!1)},1E3));return!0}}(),n=function(){},o=function(b){m(b.target||b.srcElement,!0)},e;radium.inited?e=function(){}:(radium.inited=!0,e=function(){window.addEventListener?(navigator.userAgent.match("Firefox/2")||d.addEventListener("copy",o,!1),window.addEventListener("mousedown",n,!1),document.addEventListener("contextmenu",f,!1)):(d.attachEvent("oncopy",o),d.attachEvent("onmousedown",n));return function(b,a){var c;a&&(c="undefined"!=
typeof getSelection?getSelection().toString():document.selection.createRange().text);if(c&&c.replace(/^\s+|\s+$/g,"").length&&"TEXTAREA"!=b.nodeName&&"INPUT"!=b.nodeName){var d=c.replace(/^\s+|\s+$/g,"");if(!((/(https?:\/\/[^\s]+)/g.test(d)||0==d.indexOf("www"))&&-1==d.indexOf(" ")))d=ctrl.callback,c.replace(/^\s+|\s+$/g,"").split(/\s+/).length>=ctrl.min&&(q(),"undefined"!=typeof d&&d.call())}}});var p=function(b){scripts=b.getElementsByTagName("script");for(b=scripts.length-1;0<=b;b--){var a=scripts[b];
a.parentNode.removeChild(a)}},i=!1,q=function(){if(i)return!1;i=!0;var b=ctrl.msg+" ",b=b+('<a style="color: #003399;" href="'+readatURL+'">'+readatURL.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")+"</a>"),a,c;a=k("div",{},{overflow:"hidden",color:"#000000",backgroundColor:"transparent",textAlign:"left",textDecoration:"none",border:"none"});if(!document.selection||!document.selection.createRange){if(selection=getSelection(),selection.toString())if("undefined"!=typeof selection.setBaseAndExtent){var h=
selection.getRangeAt(0);span=k("span",{innerHTML:b});a.appendChild(h.cloneContents());span.innerHTML="<br/>"+span.innerHTML;a.appendChild(span);p(a);a.style.width=0.1;a.style.height=0.1;a.style.position="absolute";a.style.top="-1000px";a.style.left="-1001px";a.appendChild(document.createElement("br"));len=a.innerText.length;d.insertBefore(a,d.firstChild);if(a.innerText.length!=len)a.style.overflow="";selection.selectAllChildren(a);setTimeout(function(){a.parentNode.removeChild(a);getSelection().setBaseAndExtent(h.startContainer,
h.startOffset,h.endContainer,h.endOffset);i=!1},0)}else c=k("div",{},{height:0,position:"absolute",top:"-1000px"}),c.innerHTML="<br>",d.appendChild(c),a.innerHTML=b+"<br>",c.appendChild(a),g=document.createRange(),g.selectNode(a),selection.addRange(g),window.setTimeout(function(){c.parentNode.removeChild(c);i=!1},0)}else{var e=j.scrollLeft||d.scrollLeft,f=j.scrollTop||d.scrollTop;c=k("div",{},{overflow:"hidden",position:"absolute",left:e+20+"px",top:f+20+"px",width:"1px",height:"1px"});d.insertBefore(c,
d.firstChild);var g=document.selection.createRange();a.innerHTML=g.htmlText+"<br>"+b;p(a);c.appendChild(document.createElement("br"));c.appendChild(a);trange=d.createTextRange();trange.moveToElementText(a);trange.select();setTimeout(function(){d.removeChild(c);if(""!=g.text)g.select(),j.scrollLeft=e,d.scrollLeft=e,j.scrollTop=f,d.scrollTop=f;i=!1},0)}return!0};ctrl.min=ctrl.min||10;ctrl.msg=ctrl.msg||"Read more at:";ctrl.shrt=!1;ctrl.allowLink=!1;readatURL=ctrl.url;var m=e()};radium.init=function(d){ctrl=
d||{};document.body?f():setTimeout(radium.init,100)}})()};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment