UNPKG

gm-extra

Version:
3 lines 8.03 kB
"use strict";var GmExtra=(()=>{var b=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames,S=Object.getOwnPropertySymbols,W=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable,z=Reflect.get;var v=(t,e,r)=>e in t?b(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,w=(t,e)=>{for(var r in e||(e={}))V.call(e,r)&&v(t,r,e[r]);if(S)for(var r of S(e))j.call(e,r)&&v(t,r,e[r]);return t};var B=(t,e)=>{for(var r in e)b(t,r,{get:e[r],enumerable:!0})},J=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of K(e))!V.call(t,o)&&o!==r&&b(t,o,{get:()=>e[o],enumerable:!(n=D(e,o))||n.enumerable});return t};var Q=t=>J(b({},"__esModule",{value:!0}),t);var f=(t,e,r)=>(v(t,typeof e!="symbol"?e+"":e,r),r);var R=(t,e,r)=>z(W(t),r,e);var u=(t,e,r)=>new Promise((n,o)=>{var s=d=>{try{i(r.next(d))}catch(l){o(l)}},a=d=>{try{i(r.throw(d))}catch(l){o(l)}},i=d=>d.done?n(d.value):Promise.resolve(d.value).then(s,a);i((r=r.apply(t,e)).next())});var ae={};B(ae,{UnsafeWindowInterceptorManager:()=>ne,_TODO:()=>Te,buildFetchInterceptorManager:()=>U,buildXhrInterceptorManager:()=>se,gmAxiosAdapter:()=>te,gmFetch:()=>re,querySelector:()=>Y,querySelectorAll:()=>Z});function Y(t,e,r){return u(this,null,function*(){let n=t.querySelector(e);return n||new Promise(o=>{let s,a=new MutationObserver(i=>{for(let d of i)if(d.target instanceof Element){let l=d.target.querySelector(e);if(l)return a.disconnect(),window.clearTimeout(s),o(l)}});a.observe(t,{attributes:!0,childList:!0,subtree:!0}),(r==null?void 0:r.timeout)!==void 0&&(s=window.setTimeout(()=>{a.disconnect(),o(null)},r==null?void 0:r.timeout))})})}function Z(t,e,r){return u(this,null,function*(){let n=t.querySelectorAll(e);return n.length>0?n:new Promise(o=>{let s,a=new MutationObserver(i=>{for(let d of i)if(d.target instanceof Element){let l=d.target.querySelectorAll(e);if(l.length,l.length>0)return a.disconnect(),window.clearTimeout(s),o(l)}});a.observe(t,{attributes:!0,childList:!0,subtree:!0}),(r==null?void 0:r.timeout)!==void 0&&(s=window.setTimeout(()=>{a.disconnect();let i=document.createDocumentFragment().childNodes;o(i)},r==null?void 0:r.timeout))})})}var H=(()=>typeof GM_info!="undefined"?GM_info:void 0)();var g=(()=>typeof GM_xmlhttpRequest!="undefined"?GM_xmlhttpRequest:void 0)();var x=(()=>window)();var G=(t=0)=>u(void 0,null,function*(){return new Promise(e=>{setTimeout(e,t)})}),C=t=>{let e,r={get k(){return e===void 0&&(e=t()),e}},n=$(()=>new WeakMap);return new Proxy({},{get(o,s,a){let i=Reflect.get(r.k,s,a);if(typeof i=="function"){let d=i,l=n.value.get(d);return l===void 0&&(l=d.bind(r.k),n.value.set(d,l)),l}return i},set(o,s,a,i){return Reflect.set(r.k,s,a,i)},has(o,s){return Reflect.has(r.k,s)},ownKeys(){return Reflect.ownKeys(r.k)},isExtensible(){return Reflect.isExtensible(r.k)},deleteProperty(o,s){return Reflect.deleteProperty(r.k,s)},setPrototypeOf(o,s){return Reflect.setPrototypeOf(r.k,s)},getOwnPropertyDescriptor(o,s){return Reflect.getOwnPropertyDescriptor(r.k,s)},defineProperty(o,s,a){return Reflect.defineProperty(r.k,s,a)},getPrototypeOf(){return Reflect.getPrototypeOf(r.k)},preventExtensions(){return Reflect.preventExtensions(r.k)},apply(o,s,a){return Reflect.apply(r.k,s,a)},construct(o,s,a){return Reflect.construct(r.k,s,a)}})},N={},$=t=>{let e=N;return{get value(){return e===N&&(e=t()),e}}},m=(t="")=>{let e=new Headers;return t.replace(/\r?\n[\t ]+/g," ").split("\r").map(function(n){return n.startsWith(` `)?n.substring(1):n}).forEach(function(n){var a;let o=n.split(":"),s=(a=o.shift())==null?void 0:a.trim();if(s){let i=o.join(":").trim();e.append(s,i)}}),e},I=(t="")=>{try{return t===""&&location.href?location.href:t}catch(e){return t}},T=t=>{let e={};return t.forEach((r,n)=>{e[n]=r}),e},ee=t=>{let e=new FormData,r=[];return t.forEach((n,o)=>{r.push([o,n])}),r.reverse().forEach(([n,o])=>{e.append(n,o)}),e},E=(t,e)=>(e.delete("content-type"),H.scriptHandler=="Tampermonkey"?ee(t):t);var te=t=>u(void 0,null,function*(){var o;let e=new URL((o=t.url)!=null?o:"",t.baseURL);if(t.params)for(let s in t.params){let a=t.params[s];a!==void 0&&e.searchParams.set(s,String(a))}let r=t.headers.toJSON(!0),n=yield new Promise((s,a)=>{g({method:t.method,url:e.href,headers:r,data:t.data,timeout:t.timeout,responseType:t.responseType,onload:s,onerror:a})});return{status:n.status,statusText:n.statusText,headers:T(m(n.responseHeaders)),data:n.response||n.responseText,config:t}});var re=(n,...o)=>u(void 0,[n,...o],function*(t,e={},r={}){var k;let s=new Request(t,e);if((k=s.signal)!=null&&k.aborted)throw new DOMException("Aborted","AbortError");let a=s.method.toUpperCase(),i=I(s.url),d=new Headers(s.headers);new Headers(e.headers).forEach((c,_)=>{d.set(_,c)});let l=!1,y;if(a!="GET")if(e.body)e.body instanceof FormData?y=E(e.body,d):typeof e.body=="string"||e.body instanceof URLSearchParams?y=e.body:(l=!0,y=yield s.blob());else{let c=yield s.clone().formData().catch(()=>{});c&&(y=E(c,d))}return new Promise((c,_)=>{var L;let h={method:a,url:i,headers:T(d),data:y,binary:l,responseType:"blob",onload(p){return u(this,null,function*(){var F;let M;p.response instanceof Blob&&p.response.size==0||(M=(F=p.response)!=null?F:p.responseText),yield G();let O=new Response(M,{status:p.status,statusText:p.statusText,headers:m(p.responseHeaders)});Object.defineProperty(O,"url",{value:p.finalUrl}),c(O)})},onerror(){return u(this,null,function*(){yield G(),_(new TypeError("Network request onerror failed"))})},ontimeout(){return u(this,null,function*(){yield G(),_(new TypeError("Network request ontimeout failed"))})},onabort(){return u(this,null,function*(){yield G(),_(new DOMException("Aborted","AbortError"))})},onreadystatechange(p){return u(this,null,function*(){var M;p.readyState===4&&((M=s.signal)==null||M.removeEventListener("abort",P))})}};typeof r=="function"?h=r(h):h=w(w({},h),r);let X=g(h);function P(){X.abort()}(L=s.signal)==null||L.addEventListener("abort",P)})});var Te=void 0;var A=(t,e,r,n=0)=>({request:r,proceed:(...s)=>u(void 0,[...s],function*(o=r){for(;n<e.length;){let a=e[n];if(a){let i=A(t,e,o,n+1);return yield a(i)}n++}return t(o)})}),U=t=>{let e=[];return{originalFetch:t,fakeFetch:(n,o)=>u(void 0,null,function*(){return A(t,[...e],new Request(n,o)).proceed()}),use:n=>(e.push(n),e.length-1),eject:n=>{e[n]=null},clear:()=>{for(let n=0;n<e.length;n++)e[n]=null}}},ne=C(()=>{let t=U(x.unsafeWindow.fetch);return x.unsafeWindow.fetch=t.fakeFetch,t});var oe=t=>class q extends t{constructor(){super(...arguments);f(this,"_method","GET");f(this,"_url",new URL(location.origin));f(this,"_reqHeaders",new Headers);f(this,"_onreadystatechange",null);f(this,"_onload",null)}open(n,o,s=!0,a,i){let d=new URL(o,location.pathname);return a&&(d.username=a),i&&(d.password=i),this._url=d,this._method=n,super.open(n,o,s,a,i)}setRequestHeader(n,o){this._reqHeaders.append(n,o)}send(n=null){return u(this,null,function*(){let o=n;o&&o instanceof Document&&(o=new Blob([new XMLSerializer().serializeToString(o)],{type:o.contentType}));let s=new Request(this._url,{headers:this._reqHeaders,method:this._method,body:o,credentials:this.withCredentials?"include":"omit"});return s.headers.forEach((a,i)=>{this.setRequestHeader(i,a)}),s.body?R(q.prototype,this,"send").call(this,yield s.blob()):R(q.prototype,this,"send").call(this)})}get onload(){return this._onload}set onload(n){n===null?this._onload=null:this._onload=o=>u(this,null,function*(){var i,d;let s=new Response((i=this.response)!=null?i:this.responseText,{status:this.status,statusText:this.statusText,headers:m(this.getAllResponseHeaders()||"")});Object.defineProperty(s,"url",{value:(d=this.responseURL)!=null?d:this.getResponseHeader("X-Request-URL")});let a=yield s.blob();this.responseType=="text"||this.responseType==""||this.responseType=="arraybuffer"||this.responseType=="blob"||this.responseType=="json"||this.responseType=="document",n.call(this,o)})}},se=()=>{oe.apply};return Q(ae);})(); //# sourceMappingURL=index.iife.js.map