-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStreamElements-Redemptions-Fixer.user.js
More file actions
54 lines (47 loc) · 2.04 KB
/
Copy pathStreamElements-Redemptions-Fixer.user.js
File metadata and controls
54 lines (47 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// ==UserScript==
// @name StreamElements Redemptions Fixer
// @description Remove limit from StreamElements redemptions requests
// @author Lone Destroyer
// @license MIT
// @match https://streamelements.com/dashboard/account/redemptions*
// @icon https://streamelements.com/favicon.ico
// @version 1.0
// @namespace https://github.com/LoneDestroyer
// @downloadURL https://raw.githubusercontent.com/LoneDestroyer/StreamElements-Redemptions-Fixer/main/StreamElements-Redemptions-Fixer.user.js
// @updateURL https://raw.githubusercontent.com/LoneDestroyer/StreamElements-Redemptions-Fixer/main/StreamElements-Redemptions-Fixer.user.js
// @run-at document-start
// ==/UserScript==
(function() {
'use strict';
const originalFetch = unsafeWindow.fetch;
const originalXhrOpen = XMLHttpRequest.prototype.open;
function rewriteRedemptionsUrl(rawUrl) {
try {
const url = new URL(rawUrl, window.location.origin);
const isRedemptions = url.hostname === 'api.streamelements.com' && url.pathname.includes('/redemptions/me');
if (!isRedemptions) return rawUrl;
url.searchParams.delete('limit');
return url.toString();
} catch (_) {
return rawUrl;
}
}
unsafeWindow.fetch = function(...args) {
const req = args[0];
const url = typeof req === 'string' ? req : (req && req.url) || '';
const rewrittenUrl = rewriteRedemptionsUrl(url);
let fetchArgs = args;
if (rewrittenUrl !== url) {
if (typeof req === 'string') {
fetchArgs = [rewrittenUrl, args[1]];
} else if (req instanceof Request) {
fetchArgs = [new Request(rewrittenUrl, req), args[1]];
}
}
return originalFetch.apply(this, fetchArgs);
};
XMLHttpRequest.prototype.open = function(method, url, ...rest) {
const rewrittenUrl = rewriteRedemptionsUrl(url);
return originalXhrOpen.apply(this, [method, rewrittenUrl, ...rest]);
};
})();