|
1 | 1 | // ==UserScript== |
2 | 2 | // @name Trakt.tv | Trakt API Wrapper |
3 | 3 | // @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 |
5 | 5 | // @namespace f785bub0 |
6 | 6 | // @updateURL https://update.greasyfork.org/scripts/564750.meta.js |
7 | 7 | // @icon https://trakt.tv/assets/logos/logomark.square.gradient-b644b16c38ff775861b4b1f58c1230f6a097a2466ab33ae00445a505c33fcb91.svg |
@@ -182,8 +182,8 @@ function sendApiRequest(req, opts) { |
182 | 182 | } |
183 | 183 |
|
184 | 184 | 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(',') ?? []; |
187 | 187 | return Object.fromEntries( |
188 | 188 | normalizedHeaderEntries |
189 | 189 | .filter(([key]) => traktHeaderKeys.includes(key)) |
@@ -275,8 +275,8 @@ async function fetchAuthTokens() { |
275 | 275 | ['commit', 'Yes'], |
276 | 276 | ]), |
277 | 277 | }); |
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) { |
280 | 280 | logger.success('Application successfully authorized!', { data: { code: authCode } }); |
281 | 281 | } else { |
282 | 282 | gmStorage.app = { id: gmStorage.app.id }; |
|
0 commit comments