()
| 52 | } |
| 53 | |
| 54 | async function checkToken(): Promise<void> { |
| 55 | const token = await getToken(); |
| 56 | if (!token) { |
| 57 | addTokenNotice('missing'); |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | try { |
| 62 | await baseApiFetch({apiBase: 'https://api.github.com/', path: 'user', token}); |
| 63 | } catch (error) { |
| 64 | if (!navigator.onLine || (error as any)!.message === 'Failed to fetch') { |
| 65 | return; |
| 66 | } |
| 67 | |
| 68 | addTokenNotice('invalid or expired'); |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | // Thank you for following the instructions. I'll save you a click. |
| 73 | const checkbox = $(isSetTheTokenSelector); |
| 74 | if (!checkbox.checked) { |
| 75 | checkbox.click(); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | async function setVersion(): Promise<void> { |
| 80 | // Wait for GitHub's listener to be attached #9293 |
no test coverage detected