-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
async-document-write.min.js
2 lines (2 loc) · 1.72 KB
/
async-document-write.min.js
1
2
/* @source http://purl.eligrey.com/github/async-document-write/blob/master/async-document-write.js*/
!function(){"use strict";try{0()}catch(e){var t=e}var n="fileName",r="stack",i=r+"trace";if(document.currentScript||n in t||i in t||r in t){var c,o,a,l,d=document,f=d.createElement("a"),u=!1,v=!u,p=[],s=d.write,m=function(e){return d.getElementsByTagName(e)},h=m("head")[0],E=function(){if(v){v=u;for(var e=c.to,t=0,n=p.length;n>t;t++)c.to=p[t++],c(p[t]),delete c.to;p=null,c.to=e}},y=function(e){var t,c=function(e,n){t=n};return n in e?t=e[n]:i in e?e[i].replace(/Line \d+ of .+ script (.*)/gm,c):r in e&&(e[r].replace(/at (.*)/gm,c),t=t.replace(/:\d+:\d+$/,"")),t},L=Array.prototype.slice;Object.prototype.toString;d.addEventListener&&d.removeEventListener?(o=d.addEventListener,a=d.removeEventListener,l=function(e){a.call(d,e.type,l,u),E()},o.call(d,"DOMContentLoaded",l,u),o.call(d,"load",l,u)):d.attachEvent&&d.detachEvent&&(o=d.attachEvent,a=d.detachEvent,l=function(){a.call(d,"onload",l)},o.call(d,"onload",l)),c=d.write=function(){var e=L.call(arguments).join(""),t=m("body")[0],n=c.to;if(!t)return void p.push(n,e);if(n){var r;if(n instanceof HTMLScriptElement)r=n;else{f.href=y(n);for(var i=f.href,o=m("script"),a=0,l=o.length;l>a;a++){var u=o.item(a);if(f.href=u.src,f.href===i){r=o.item(a);break}}}if(r){var v=r,E=d.createElement("template");for(E.innerHTML=e;v=v.parentNode;)if(v===h)return void t.insertBefore(E.content||E,t.firstChild);return void r.parentNode.insertBefore(E.content||E,r)}}else s.apply(d,arguments)},d.writeln=function(){c.apply(this,L.call(arguments).concat("\n"))},c.START="if(document.currentScript){document.write.to=document.currentScript}else{try{0()}catch(e){document.write.to=e}}",c.END="delete document.write.to"}}();