( function ( ) { class Xhr { static catches : [ string , any ] [ ] = [ ] ; static log = ( ) => this . catches ; param details returns static xhr ( details ) { details . method == "POST" && ( details . headers = details . headers || { } , ! details . headers [ "Content-Type" ] && Reflect . set ( details . headers , "Content-Type" , "application/x-www-form-urlencoded" ) ) ; if ( details . hasOwnProperty ( "async" ) && Boolean ( details . async ) === false ) { let xhr = new XMLHttpRequest ( ) ; xhr . open ( details . method || 'GET' , details . url , false ) ; details . responseType && ( xhr . responseType = details . responseType ) ; details . credentials && ( xhr . withCredentials = true ) ; details . headers && ( Object . entries ( details . headers ) . forEach ( d => xhr . setRequestHeader ( d [ 0 ] , d [ 1 ] ) ) ) ; details . timeout && ( xhr . timeout = details . timeout ) ; xhr . send ( details . data ) ; return xhr . response ; } return new Promise ( ( resolve , reject ) => { let xhr = new XMLHttpRequest ( ) ; xhr . open ( details . method || 'GET' , details . url ) ; details . responseType && ( xhr . responseType = details . responseType ) ; details . headers && ( Object . entries ( details . headers ) . forEach ( d => xhr . setRequestHeader ( d [ 0 ] , d [ 1 ] ) ) ) ; details . credentials && ( xhr . withCredentials = true ) ; details . timeout && ( xhr . timeout = details . timeout ) ; xhr . onabort = details . onabort || ( ( ev ) => reject ( ev ) ) ; xhr . onerror = details . onerror || ( ( ev ) => reject ( ev ) ) ; details . onloadstart && ( xhr . onloadstart = details . onloadstart ) ; details . onprogress && ( xhr . onprogress = details . onprogress ) ; details . onreadystatechange && ( xhr . onreadystatechange = details . onreadystatechange ) ; xhr . ontimeout = details . ontimeout || ( ( ev ) => reject ( ev ) ) ; xhr . onload = details . onload || ( ( ) => resolve ( xhr . response ) ) ; xhr . send ( details . data ) ; } ) ; } param details returns static GM ( details ) { return new Promise ( ( resolve , reject ) => { details . method = details . method || 'GET' ; details . onload = details . onload || ( ( xhr ) => { this . catches . push ( [ details . url , xhr . response ] ) ; resolve ( xhr . response ) ; } ) ; details . onerror = details . onerror || ( ( xhr ) => { this . catches . push ( [ details . url , xhr . response ] ) ; reject ( xhr . response ) ; } ) ; GM . xmlHttpRequest ( details ) ; } ) ; } param url param details returns static get ( url , details = { } ) { ! Reflect . has ( details , "credentials" ) && ( details . credentials = true ) ; return this . xhr ( { url : url , ... details } ) ; } param url param data param contentType param details returns static post ( url , data , contentType = "application/x-www-form-urlencoded" , details = { } ) { ! Reflect . has ( details , "credentials" ) && ( details . credentials = true ) ; details . headers = { "Content-Type" : contentType , ... details . headers } ; return this . xhr ( { url : url , method : "POST" , data : data , ... details } ) ; } } API . xhr = new Proxy ( Xhr . xhr , { get : ( t , p ) => Xhr [ p ] } ) ; } ) ( ) ; declare const xhr ; /**
* `GM_xmlhttpRequest`的返回值
*/ interface GMxhrResponse { /**
     * the final URL after all redirects from where the data was loaded
     */ finalUrl : string ; /**
     * the ready state
     */ readyState : number ; /**
     * the request status
     */ status : number ; /**
     * the request status text
     */ statusText : string ; /**
     * the request response headers
     */ responseHeaders : any ; /**
     * the response data as object if details.responseType was set: ArrayBuffer | Blob | JSON | string
     */ response : any ; /**
     * the response data as XML document
     */ responseXML : Document ; /**
     * the response data as plain string
     */ responseText : string ; } /**
 * `API.xhr`的传参，用于配置`XMLHttpRequest`
 */ interface xhrDetails { /**
     * one of GET, HEAD, POST
     */ method ? : "GET" | "HEAD" | "POST" ; /**
     * the destination URL
     */ url : string ; /**
     * most headers are not supported by Safari and Android browsers
     */ headers ? : { [ name ] : string ; } ; /**
     * some string to send via a POST request
     */ data ? : string ; /**
     * a timeout in ms
     */ timeout ? : number ; /**
     * one of arraybuffer, blob, json
     */ responseType ? : "arraybuffer" | "blob" | "json" ; /**
     * send cookies of CROS request
     */ credentials ? : boolean ; /**
     * callback to be executed if the request was aborted
     */ onabort ? : ( ( this : XMLHttpRequest , ev : ProgressEvent ) => any ) | null ; /**
     * callback to be executed if the request ended up with an error
     */ onerror ? : ( ( this : XMLHttpRequest , ev : ProgressEvent ) => any ) | null ; /**
     * callback to be executed if the request started to load
     */ onloadstart ? : ( ( this : XMLHttpRequest , ev : ProgressEvent ) => any ) | null ; /**
     * callback to be executed if the request made some progress
     */ onprogress ? : ( ( this : XMLHttpRequest , ev : ProgressEvent ) => any ) | null ; /**
     * callback to be executed if the request's ready state changed
     */ onreadystatechange ? : ( ( this : XMLHttpRequest , ev : Event ) => any ) | null ; /**
     * callback to be executed if the request failed due to a timeout
     */ ontimeout ? : ( ( this : XMLHttpRequest , ev : ProgressEvent ) => any ) | null ; /**
     * callback to be executed if the request was loaded
     */ onload ? : ( ( this : XMLHttpRequest , ev : ProgressEvent ) => any ) | null ; } /**
 * `API.xhr.GM`的传参，用于配置`GM_xmlhttpRequest`
 */ interface GMxhrDetails { /**
     * one of GET, HEAD, POST
     */ method ? : "GET" | "HEAD" | "POST" ; /**
     * the destination URL
     */ url : string ; /**
     * ie. user-agent, referer, ... (some special headers are not supported by Safari and Android browsers)
     */ headers ? : { [ name ] : string ; } ; /**
     * some string to send via a POST request
     */ data ? : string ; /**
     * a cookie to be patched into the sent cookie set
     */ cookie ? : string ; /**
     * send the data string in binary mode
     */ binary ? : boolean ; /**
     * don't cache the resource
     */ nocache ? : boolean ; /**
     * revalidate maybe cached content
     */ revalidate ? : boolean ; /**
     * a timeout in ms
     */ timeout ? : number ; /**
     * a property which will be added to the response object
     */ context ? : any ; /**
     * one of arraybuffer, blob, json
     */ responseType ? : "arraybuffer" | "blob" | "json" ; /**
     * a MIME type for the request
     */ overrideMimeType ? : String ; /**
     * don't send cookies with the requests (please see the fetch notes)
     */ anonymous ? : boolean ; /**
     * (beta) use a fetch instead of a xhr request
     * (at Chrome this causes xhr.abort, details.timeout and xhr.onprogress to not work and makes xhr.onreadystatechange receive only readyState 4 events)
     */ fetch ? : boolean ; /**
     * a user name for authentication
     */ user ? : string ; /**
     * a password
     */ password ? : string ; /**
     * callback to be executed if the request was aborted
     */ onabort ? : ( response : GMxhrResponse ) => void ; /**
     * callback to be executed if the request ended up with an error
     */ onerror ? : ( response : GMxhrResponse ) => void ; /**
     * callback to be executed if the request started to load
     */ onloadstart ? : ( response : GMxhrResponse ) => void ; /**
     * callback to be executed if the request made some progress
     */ onprogress ? : ( response : GMxhrResponse ) => void ; /**
     * callback to be executed if the request's ready state changed
     */ onreadystatechange ? : ( response : GMxhrResponse ) => void ; /**
     * callback to be executed if the request failed due to a timeout
     */ ontimeout ? : ( response : GMxhrResponse ) => void ; /**
     * callback to be executed if the request was loaded
     */ onload ? : ( response : GMxhrResponse ) => void ; }