Greasy Fork

Async xmlhttpRequest

封装 GM_xmlhttpRequest

目前为 2021-07-11 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.greasyfork.icu/scripts/429203/949230/Async%20xmlhttpRequest.js

// ==UserScript==
// @name         Async xmlhttpRequest
// @namespace    http://tampermonkey.net/
// @version      0.1.2
// @description  封装 GM_xmlhttpRequest
// @author       LinHQ
// @match        *
// @grant        GM_xmlhttprequest
// ==/UserScript==

function req(details){
  return new Promise((res, rej) => {
    details.onload = res;
    details.ontimeout = rej;
    details.onabort = rej;
    details.onerror = rej;

    GM_xmlhttpRequest(
      details
    );
  });
}