Greasy Fork

GM_fetch

fetch pollyfill using GM_xmlhttpRequest

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

作者
nyarau
版本
0.0.1.20230104124032
创建于
2021-02-07
更新于
2023-01-04
大小
792 字节
许可证
暂无

fetch pollyfill using GM_xmlhttpRequest, not yet 100% replication of fetch API (eg. errors)

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")
})