gm_ajax

ajax

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

  1. const ajax = (url, data, opts = {}) => new Promise((resolve, reject) => {
  2. if (!url) throw new Error('xmlHttpRequest url must exists!')
  3. var GM = typeof GM === 'undefined' ? {} : GM;
  4. if (typeof GM_xmlhttpRequest === 'undefined' && typeof GM.xmlHttpRequest === 'undefined') {
  5. throw new Error('GM_xmlhttpRequest or GM.xmlHttpRequest must exists!')
  6. }
  7. if (typeof GM_xmlhttpRequest === 'function' && !GM.xmlHttpRequest) {
  8. GM.xmlHttpRequest = GM_xmlhttpRequest
  9. }
  10. var params = {
  11. url,
  12. method: opts.method=='POST'||data ? 'POST' : 'GET',
  13. synchronous: opts.sync || true,
  14. responseType: opts.dataType || 'text',
  15. headers: opts.headers||null
  16. }
  17. if(params.method=='POST') params['data']=data;
  18. //console.log(params);
  19. var gmReq = GM.xmlHttpRequest || GM_xmlhttpRequest;
  20. gmReq({
  21. ...params,
  22. onload(res) {
  23. //console.log(res)
  24. if (res.status >= 200 && res.status < 300) {
  25. resolve(res.response);
  26. } else {
  27. reject(res);
  28. }
  29. },
  30. onerror(err) {
  31. reject(err);
  32. }
  33. });
  34. });

QingJ © 2025

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