| 13 | |
| 14 | export const requestUserscriptLegacy: requestInterface = { |
| 15 | async xhr(method, url, retry = 0): Promise<any> { |
| 16 | return new Promise((resolve, reject) => { |
| 17 | const request = { |
| 18 | method, |
| 19 | url, |
| 20 | synchronous: false, |
| 21 | headers: {}, |
| 22 | data: null, |
| 23 | onload(response) { |
| 24 | console.log(response); |
| 25 | if (response.status === 429) { |
| 26 | if (retry > 3 || utils.rateLimitExclude.test(response.finalUrl)) |
| 27 | throw 'Rate limit Timeout'; |
| 28 | con.error('RATE LIMIT'); |
| 29 | api.storage.set('rateLimit', true); |
| 30 | setTimeout(() => { |
| 31 | api.storage.set('rateLimit', false); |
| 32 | resolve(requestUserscriptLegacy.xhr(method, url, retry + 1)); |
| 33 | }, 30000); |
| 34 | return; |
| 35 | } |
| 36 | const responseObj: xhrResponseI = { |
| 37 | finalUrl: response.finalUrl, |
| 38 | responseText: response.responseText, |
| 39 | status: response.status, |
| 40 | }; |
| 41 | resolve(responseObj); |
| 42 | }, |
| 43 | }; |
| 44 | if (typeof url === 'object') { |
| 45 | request.url = url.url; |
| 46 | request.headers = url.headers; |
| 47 | request.data = url.data; |
| 48 | } |
| 49 | |
| 50 | request.url = encodeURI(request.url as string); |
| 51 | if ( |
| 52 | utils.isDomainMatching(request.url, 'malsync.moe') || |
| 53 | utils.isDomainMatching(request.url, 'simkl.com') |
| 54 | ) { |
| 55 | // @ts-ignore |
| 56 | request.headers.version = api.storage.version(); |
| 57 | // @ts-ignore |
| 58 | request.headers.type = 'userscript'; |
| 59 | } |
| 60 | GM_xmlhttpRequest(request); |
| 61 | }); |
| 62 | }, |
| 63 | notification(options) { |
| 64 | GM_notification({ |
| 65 | title: options.title, |