Skip to content

Commit 63e0d55

Browse files
authored
Update f785bub0.user.js
1 parent 88ff82b commit 63e0d55

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

userscripts/src/f785bub0.user.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ==UserScript==
22
// @name Trakt.tv | Trakt API Wrapper
33
// @description Exposes an authenticated Trakt API Wrapper. Intended to run alongside other userscripts which require (authenticated) access to the Trakt API.
4-
// @version 1.0.4
4+
// @version 1.0.6
55
// @namespace f785bub0
66
// @updateURL https://update.greasyfork.org/scripts/564750.meta.js
77
// @icon https://trakt.tv/assets/logos/logomark.square.gradient-b644b16c38ff775861b4b1f58c1230f6a097a2466ab33ae00445a505c33fcb91.svg
@@ -182,8 +182,8 @@ function sendApiRequest(req, opts) {
182182
}
183183

184184
function parseTraktHeaders(headers) {
185-
const normalizedHeaderEntries = headers.split(/\r?\n/).map((header) => header.split(':')).map(([key, val]) => [key.trim().toLowerCase(), val?.trim()]),
186-
traktHeaderKeys = normalizedHeaderEntries.find(([key]) => key === 'access-control-expose-headers')[1].toLowerCase().split(',');
185+
const normalizedHeaderEntries = headers.split(/\r?\n/).map((header) => header.split(/(?<=^[^:]+):/)).map(([key, val]) => [key.trim().toLowerCase(), val?.trim()]),
186+
traktHeaderKeys = normalizedHeaderEntries.find(([key]) => key === 'access-control-expose-headers')?.[1].toLowerCase().split(',') ?? [];
187187
return Object.fromEntries(
188188
normalizedHeaderEntries
189189
.filter(([key]) => traktHeaderKeys.includes(key))
@@ -275,8 +275,8 @@ async function fetchAuthTokens() {
275275
['commit', 'Yes'],
276276
]),
277277
});
278-
if (resp.status >= 200 && resp.status < 300) {
279-
authCode = new URL(resp.finalUrl).searchParams.get('code');
278+
authCode = new URL(resp.finalUrl).searchParams.get('code');
279+
if (authCode) {
280280
logger.success('Application successfully authorized!', { data: { code: authCode } });
281281
} else {
282282
gmStorage.app = { id: gmStorage.app.id };

0 commit comments

Comments
 (0)