Greasy Fork is available in English.

GM_fetch

fetch pollyfill with resp.text/resp.json/resp.blob/resp.arrayBuffer support using GM_xmlhttpRequest

此脚本不应被直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://greasyfork.org/scripts/421384-gm-fetch/code/GM_fetch.js?version=898562

作者
nyarau
得分
0 0 0
版本
0.0.1.20210207152600
创建日期
2021-02-07
最近更新
2021-02-07
许可协议
不适用
应用到
所有站点

(personal uses, with no guarantee what so ever)

fetch pollyfill with resp.text/resp.json/resp.blob/resp.arrayBuffer support using GM_xmlhttpRequest, not yet 100% replication of fetch API (eg. errors)

Written for / tested with TamperMonkey, may work for GeaseMonkey or others

Don't forget to add permissions

// @grant    GM_xmlhttpRequest
// @connect  api.example.com

Example

GM_fetch("https://api.example.com/favicon.png", {
    method: 'POST',
    body: JSON.stringify({message: "hello world"}),
    headers: { 'Content-Type': 'application/json' }
}).then(resp=>resp.blob()).then(blob=>{
    open(URL.createObjectURL(blob), "_blank")
})