(function(n){var a,v,b,y,f,r,h,g,e,st,nt,u,c,tt,i,it,p,s,o,rt,ut,k,ht,l,d,ft,et,w,ot,t,ct,lt=[].indexOf||function(n){for(var t=0,i=this.length;t<i;t++)if(t in this&&this[t]===n)return t;return-1};i=null;i=typeof WorkerGlobalScope!="undefined"&&self instanceof WorkerGlobalScope?self:typeof global!="undefined"?global:window;k=i.document;v="before";a="after";c="readyState";u="addEventListener";nt="removeEventListener";r="dispatchEvent";o="XMLHttpRequest";f="fetch";h="FormData";tt=["load","loadend","loadstart"];b=["progress","abort","error","timeout"];ot=typeof navigator!="undefined"&&navigator.useragent?navigator.userAgent:"";d=parseInt((/msie (\d+)/.exec(ot.toLowerCase())||[])[1]);isNaN(d)&&(d=parseInt((/trident\/.*; rv:(\d+)/.exec(ot.toLowerCase())||[])[1]));(ct=Array.prototype).indexOf||(ct.indexOf=function(n){for(var r,i,t=i=0,u=this.length;i<u;t=++i)if(r=this[t],r===n)return t;return-1});w=function(n,t){return Array.prototype.slice.call(n,t)};ut=function(n){return n==="returnValue"||n==="totalSize"||n==="position"};l=function(n,t){var i,r;for(i in n)if(r=n[i],!ut(i))try{t[i]=n[i]}catch(u){}return t};ft=function(n){return n===void 0?null:n};et=function(n,t,i){var u,e,f,o;for(e=function(n){return function(u){var e,f,o;e={};for(f in u)ut(f)||(o=u[f],e[f]=o===t?i:o);return i[r](n,e)}},f=0,o=n.length;f<o;f++)u=n[f],i._has(u)&&(t["on"+u]=e(u))};ht=function(n){var t;if(k&&k.createEventObject!=null)return t=k.createEventObject(),t.type=n,t;try{return new Event(n)}catch(i){return{type:n}}};y=function(t){var i,f,e;return f={},e=function(n){return f[n]||[]},i={},i[u]=function(t,i,r){(f[t]=e(t),f[t].indexOf(i)>=0)||(r=r===n?f[t].length:r,f[t].splice(r,0,i))},i[nt]=function(t,i){var r;if(t===n){f={};return}(i===n&&(f[t]=[]),r=e(t).indexOf(i),r!==-1)&&e(t).splice(r,1)},i[r]=function(){var n,r,u,f,h,o,c,s;for(n=w(arguments),r=n.shift(),t||(n[0]=l(n[0],ht(r))),f=i["on"+r],f&&f.apply(i,n),s=e(r).concat(e("*")),u=o=0,c=s.length;o<c;u=++o)h=s[u],h.apply(i,n)},i._has=function(n){return!!(f[n]||i["on"+n])},t&&(i.listeners=function(n){return w(e(n))},i.on=i[u],i.off=i[nt],i.fire=i[r],i.once=function(n,t){var r=function(){return i.off(n,r),t.apply(null,arguments)};return i.on(n,r)},i.destroy=function(){return f={}}),i};t=y(!0);t.EventEmitter=y;t[v]=function(n,i){if(n.length<1||n.length>2)throw"invalid hook";return t[u](v,n,i)};t[a]=function(n,i){if(n.length<2||n.length>3)throw"invalid hook";return t[u](a,n,i)};t.enable=function(){i[o]=s;typeof it=="function"&&(i[f]=it);e&&(i[h]=p)};t.disable=function(){i[o]=t[o];i[f]=t[f];e&&(i[h]=e)};rt=t.headers=function(n,t){var e,i,f,r,o,s,u,h,c;t==null&&(t={});switch(typeof n){case"object":i=[];for(f in n)o=n[f],r=f.toLowerCase(),i.push(""+r+":\t"+o);return i.join("\n")+"\n";case"string":for(i=n.split("\n"),u=0,h=i.length;u<h;u++)e=i[u],/([^:]+):\s*(.+)/.test(e)&&(r=(c=RegExp.$1)!=null?c.toLowerCase():void 0,s=RegExp.$2,t[r]==null&&(t[r]=s));return t}};e=i[h];p=function(n){var t;this.fd=n?new e(n):new e;this.form=n;t=[];Object.defineProperty(this,"entries",{get:function(){var i;return i=n?w(n.querySelectorAll("input,select")).filter(function(n){var t;return(t=n.type)!=="checkbox"&&t!=="radio"||n.checked}).map(function(n){return[n.name,n.type==="file"?n.files:n.value]}):[],i.concat(t)}});this.append=function(n){return function(){var i;return i=w(arguments),t.push(i),n.fd.append.apply(n.fd,i)}}(this)};e&&(t[h]=e,i[h]=p);st=i[o];t[o]=st;s=i[o]=function(){var nt,s,ot,st,vt,n,w,it,yt,ht,i,f,h,k,g,pt,ct,e,ut,wt,at;for(nt=-1,e=new t[o],i={},k=null,w=void 0,g=void 0,f=void 0,ht=function(){var n,i,r,t;if(f.status=k||e.status,k===nt&&d<10||(f.statusText=e.statusText),k!==nt){t=rt(e.getAllResponseHeaders());for(n in t)r=t[n],f.headers[n]||(i=n.toLowerCase(),f.headers[i]=r)}},yt=function(){if(e.responseType&&e.responseType!=="text")e.responseType==="document"?(f.xml=e.responseXML,f.data=e.responseXML):f.data=e.response;else{f.text=e.responseText;f.data=e.responseText;try{f.xml=e.responseXML}catch(n){}}"responseURL"in e&&(f.finalUrl=e.responseURL)},ct=function(){n.status=f.status;n.statusText=f.statusText},pt=function(){"text"in f&&(n.responseText=f.text);"xml"in f&&(n.responseXML=f.xml);"data"in f&&(n.response=f.data);"finalUrl"in f&&(n.responseURL=f.finalUrl)},st=function(t){while(t>s&&s<4)n[c]=++s,s===1&&n[r]("loadstart",{}),s===2&&ct(),s===4&&(ct(),pt()),n[r]("readystatechange",{}),s===4&&(i.async===!1?ot():setTimeout(ot,0))},ot=function(){w||n[r]("load",{});n[r]("loadend",{});w&&(n[c]=0)},s=0,h=function(n){var u,r;if(n!==4){st(n);return}u=t.listeners(a);r=function(){var n;return u.length?(n=u.shift(),n.length===2?(n(i,f),r()):n.length===3&&i.async?n(i,f,r):r()):st(4)};r()},n=i.xhr=y(),e.onreadystatechange=function(){try{e[c]===2&&ht()}catch(n){}e[c]===4&&(g=!1,ht(),yt());h(e[c])},it=function(){w=!0},n[u]("error",it),n[u]("timeout",it),n[u]("abort",it),n[u]("progress",function(){s<3?h(3):n[r]("readystatechange",{})}),("withCredentials"in e||t.addWithCredentials)&&(n.withCredentials=!1),n.status=0,at=b.concat(tt),ut=0,wt=at.length;ut<wt;ut++)vt=at[ut],n["on"+vt]=null;return n.open=function(n,t,r,u,e){s=0;w=!1;g=!1;i.headers={};i.headerNames={};i.status=0;f={};f.headers={};i.method=n;i.url=t;i.async=r!==!1;i.user=u;i.pass=e;h(1)},n.send=function(r){var c,u,o,a,w,s,k,y;for(y=["type","timeout","withCredentials"],s=0,k=y.length;s<k;s++)u=y[s],o=u==="type"?"responseType":u,o in n&&(i[u]=n[o]);i.body=r;w=function(){var t,h,r,c,f,s;for(et(b,e,n),n.upload&&et(b.concat(tt),e.upload,n.upload),g=!0,e.open(i.method,i.url,i.async,i.user,i.pass),f=["type","timeout","withCredentials"],r=0,c=f.length;r<c;r++)u=f[r],o=u==="type"?"responseType":u,u in i&&(e[o]=i[u]);s=i.headers;for(t in s)h=s[t],t&&e.setRequestHeader(t,h);i.body instanceof p&&(i.body=i.body.fd);e.send(i.body)};c=t.listeners(v);a=function(){var n,t;return c.length?(n=function(n){if(typeof n=="object"&&(typeof n.status=="number"||typeof f.status=="number")){l(n,f);lt.call(n,"data")<0&&(n.data=n.response||n.text);h(4);return}a()},n.head=function(n){return l(n,f),h(2)},n.progress=function(n){return l(n,f),h(3)},t=c.shift(),t.length===1?n(t(i)):t.length===2&&i.async?t(i,n):n()):w()};a()},n.abort=function(){k=nt;g?e.abort():n[r]("abort",{})},n.setRequestHeader=function(n,t){var u,r;u=n!=null?n.toLowerCase():void 0;r=i.headerNames[u]=i.headerNames[u]||n;i.headers[r]&&(t=i.headers[r]+", "+t);i.headers[r]=t},n.getResponseHeader=function(n){var t;return t=n!=null?n.toLowerCase():void 0,ft(f.headers[t])},n.getAllResponseHeaders=function(){return ft(rt(f.headers))},e.overrideMimeType&&(n.overrideMimeType=function(){return e.overrideMimeType.apply(e,arguments)}),e.upload&&(n.upload=i.upload=y()),n.UNSENT=0,n.OPENED=1,n.HEADERS_RECEIVED=2,n.LOADING=3,n.DONE=4,n.response="",n.responseText="",n.responseXML=null,n.readyState=0,n.statusText="",n};typeof i[f]=="function"&&(g=i[f],t[f]=g,it=i[f]=function(n,i){var u,f,r;return i==null&&(i={headers:{}}),i.url=n,r=null,f=t.listeners(v),u=t.listeners(a),new Promise(function(n,t){var s,o,e,h,c;o=function(){return i.body instanceof p&&(i.body=i.body.fd),i.headers&&(i.headers=new Headers(i.headers)),r||(r=new Request(i.url,i)),l(i,r)};e=function(t){var i;return u.length?(i=u.shift(),i.length===2?(i(o(),t),e(t)):i.length===3?i(o(),t,e):e(t)):n(t)};s=function(t){var i;if(t!==void 0){i=new Response(t.body||t.text,t);n(i);e(i);return}h()};h=function(){var n;if(!f.length){c();return}return(n=f.shift(),n.length===1)?s(n(i)):n.length===2?n(o(),s):void 0};c=function(){return g(o()).then(function(n){return e(n)})["catch"](function(n){return e(n),t(n)})};h()})});s.UNSENT=0;s.OPENED=1;s.HEADERS_RECEIVED=2;s.LOADING=3;s.DONE=4;typeof define=="function"&&define.amd?define("xhook",[],function(){return t}):typeof module=="object"&&module.exports?module.exports={xhook:t}:i&&(i.xhook=t)}).call(this)