xFetch

12/10/2024, 8:45:56 AM

Від 11.12.2024. Дивіться остання версія.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(У мене вже є менеджер скриптів, дайте мені встановити його!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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
})()