fetch pollyfill using GM_xmlhttpRequest
目前為
此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.gf.qytechs.cn/scripts/421384/898562/GM_fetch.js
(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")
})