TM_request

Tampermonkey http request 库

目前為 2020-12-11 提交的版本,檢視 最新版本

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.cn-greasyfork.org/scripts/418102/879419/TM_request.js

"use strict";function asyncGeneratorStep(t,e,n,r,o,u,a){try{var i=t[u](a);var s=i.value}catch(t){n(t);return}if(i.done){e(s)}else{Promise.resolve(s).then(r,o)}}function _asyncToGenerator(i){return function(){var t=this,a=arguments;return new Promise(function(e,n){var r=i.apply(t,a);function o(t){asyncGeneratorStep(r,e,n,o,u,"next",t)}function u(t){asyncGeneratorStep(r,e,n,o,u,"throw",t)}o(undefined)})}}window.TM_request=function r(o){var t;var u=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;o.retry=(t=o.retry)!==null&&t!==void 0?t:0;return new Promise(function(e,t){o.onload=o.onload||function(t){t.requestOptions=o;t.tmStatusText="Load";e(t)};o.ontimeout=o.ontimeout||function(t){t.requestOptions=o;t.tmStatusText="Timeout";e(t)};o.onerror=o.onerror||function(t){t.requestOptions=o;t.tmStatusText="Error";e(t)};o.onabort=o.onabort||function(t){t.requestOptions=o;t.tmStatusText="Abort";e(t)};GM_xmlhttpRequest(o)}).then(function(t){return t})["catch"](function(){var e=_asyncToGenerator(regeneratorRuntime.mark(function t(n){return regeneratorRuntime.wrap(function t(e){while(1){switch(e.prev=e.next){case 0:if(!(u>=o.retry)){e.next=5;break}console.error(n);throw n;case 5:e.next=7;return r(o,++u);case 7:return e.abrupt("return",e.sent);case 8:case"end":return e.stop()}}},t)}));return function(t){return e.apply(this,arguments)}}())};