gmfetch

A shim for using GM.xmlHttpRequest with a fetch-like API.

目前为 2021-02-22 提交的版本。查看 最新版本

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

  1. // ==UserScript==
  2. // @name gmfetch
  3. // @namespace https://github.com/matthin
  4. // @version 1.0
  5. // @author matthin
  6. // @description A shim for using GM.xmlHttpRequest with a fetch-like API.
  7. // ==/UserScript==
  8.  
  9. function gmfetch(url) {
  10. return new Promise(resolve => {
  11. GM.xmlHttpRequest({
  12. url: url,
  13. onload: res => {
  14. const headers = new Headers();
  15. res.responseHeaders.trim().split('\n').forEach(line => {
  16. const [key, value] = line.split(': ');
  17. headers.append(key, value);
  18. });
  19. resolve(new Response(res.responseText, {
  20. status: res.status,
  21. statusText: res.statusText,
  22. headers: headers
  23. }));
  24. }
  25. });
  26. });
  27. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址