12/10/2024, 8:45:56 AM
// ==UserScript==
// @name xFetch
// @description 12/10/2024, 8:45:56 AM
// @namespace Violentmonkey Scripts
// @match *://*.*/*
// @grant GM_xmlhttpRequest
// @grant unsafeWindow
// @run-at document-idle
// @version 0.0.1
// @author me
// @license MIT
// ==/UserScript==
function xFetch(url,option) {
return new Promise((rs,rj)=>{
const detail={url:url,method:'GET'};
if (option?.headers) detail.headers=option.headers;
if (option?.method) detail.method=option.method;
if (option?.body) detail.data=option.body;
if (option?.responseType) detail.responseType=option.responseType; //'text', 'json', 'blob', 'arraybuffer', 'document'
detail.onload=rs
detail.onerror=rj
let control = GM_xmlhttpRequest(detail)
})
}
(function (){
unsafeWindow.xhr=GM_xmlhttpRequest
unsafeWindow.xFetch=xFetch
})()