gmxhr-fetch
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -72,10 +72,13 @@ ;((global, fn) => { | ||
new Promise(res => { | ||
// defaults | ||
Object.assign(init, { | ||
method: 'GET', | ||
headers: {} | ||
}) | ||
// overrides | ||
init.url = input | ||
init.responseType = 'arrayBuffer' | ||
init = Object.assign( | ||
{ | ||
method: 'GET', | ||
headers: {} | ||
}, | ||
init, | ||
{ | ||
url: input, | ||
responseType: 'arrayBuffer' | ||
} | ||
) | ||
GM.xmlHttpRequest( | ||
@@ -82,0 +85,0 @@ Object.assign({}, init, { |
@@ -1,1 +0,1 @@ | ||
((a,b)=>{a.gmfetch=b("undefined"==typeof GM?{}:GM)})(this,a=>{if("undefined"==typeof GM_xmlhttpRequest&&"undefined"==typeof a.xmlHttpRequest)throw new Error("Either GM_xmlhttpRequest or GM.xmlHttpRequest must exists!");"function"!=typeof GM_xmlhttpRequest||a.xmlHttpRequest||(a.xmlHttpRequest=GM_xmlhttpRequest);class b{constructor(a,b){this.xhr=a,this.init=b}async arrayBuffer(){return this.xhr.response}async blob(){return new Blob([this.xhr.response])}async formData(){throw new Error("No implemented!")}async json(){return JSON.parse((await this.text()))}async text(){const a=new TextDecoder;return a.decode(this.xhr.response)}clone(){return Object.assign({},this)}redirect(){return this.clone()}get ok(){return 200<=this.xhr.status&&300>this.xhr.status}get headers(){return new Headers(this.xhr.headers)}get status(){return this.xhr.status}get statusText(){return this.xhr.statusText}get type(){return"cors"}get url(){return this.init.url}get bodyUsed(){return"GET"!==this.xhr.method.toUpperCase()}get redirected(){return!0}get useFinalURL(){return!0}}return(c,d={})=>new Promise(e=>{Object.assign(d,{method:"GET",headers:{}}),d.url=c,d.responseType="arrayBuffer",a.xmlHttpRequest(Object.assign({},d,{onload:a=>e(new b(a,d)),onerror:a=>e(new b(a,d))}))})}); | ||
((a,b)=>{a.gmfetch=b("undefined"==typeof GM?{}:GM)})(this,a=>{if("undefined"==typeof GM_xmlhttpRequest&&"undefined"==typeof a.xmlHttpRequest)throw new Error("Either GM_xmlhttpRequest or GM.xmlHttpRequest must exists!");"function"!=typeof GM_xmlhttpRequest||a.xmlHttpRequest||(a.xmlHttpRequest=GM_xmlhttpRequest);class b{constructor(a,b){this.xhr=a,this.init=b}async arrayBuffer(){return this.xhr.response}async blob(){return new Blob([this.xhr.response])}async formData(){throw new Error("No implemented!")}async json(){return JSON.parse((await this.text()))}async text(){const a=new TextDecoder;return a.decode(this.xhr.response)}clone(){return Object.assign({},this)}redirect(){return this.clone()}get ok(){return 200<=this.xhr.status&&300>this.xhr.status}get headers(){return new Headers(this.xhr.headers)}get status(){return this.xhr.status}get statusText(){return this.xhr.statusText}get type(){return"cors"}get url(){return this.init.url}get bodyUsed(){return"GET"!==this.xhr.method.toUpperCase()}get redirected(){return!0}get useFinalURL(){return!0}}return(c,d={})=>new Promise(e=>{d=Object.assign({method:"GET",headers:{}},d,{url:c,responseType:"arrayBuffer"}),a.xmlHttpRequest(Object.assign({},d,{onload:a=>e(new b(a,d)),onerror:a=>e(new b(a,d))}))})}); |
{ | ||
"name": "gmxhr-fetch", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "fetch-like wrapper for GM_xmlhttpRequest.", | ||
@@ -5,0 +5,0 @@ "main": "gmxhr-fetch.js", |
91
3518