GM Fetch

A fetch API of GM_xmlhttpRequest

目前為 2023-08-02 提交的版本,檢視 最新版本

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.cn-greasyfork.org/scripts/472236/1229114/GM%20Fetch.js

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

作者
Secant
版本
0.0.5
建立日期
2023-08-02
更新日期
2023-08-02
尺寸
4.7 KB
授權條款
MIT

@sec-ant/gm-fetch

A fetch API of GM_xmlhttpRequest.

Features

  • Use responseType: stream to prevent buffering large data when possible.
  • Use Typescript.
  • Provides es module, umd module and lib mode userscript as well.

Install

If you use vite-plugin-monkey:

npm i @sec-ant/gm-fetch

or just plain userscript (change the version number as needed):

// @require   https://cdn.jsdelivr.net/npm/@sec-ant/[email protected]/dist/index.umd.js

Usage

  1. Grant necessary GM_APIs:

    vite-plugin-monkey:

    {
      plugins: [
        monkey({
          userscript: {
            grant: "GM_xmlhttpRequest",
            // whatever websites you're to make requests to
            connect: ["localhost"],
          },
        }),
      ];
    }
    

    plain userscript:

    // @grant     GM_xmlhttpRequest
    // @connect   localhost
    
  2. Use it just like fetch:

    vite-plugin-monkey:

    import gmFetch from "@sec-ant/gm-fetch";
    
    gmFetch("http://localhost:4567/100.zip");
    

    plain userscript:

    /* globals gmFetch */
    (function () {
      "use strict";
      gmFetch("http://localhost:4567/100.zip");
    })();
    

License

MIT