gmfetch

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

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.gf.qytechs.cn/scripts/422172/903521/gmfetch.js

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

QingJ © 2025

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