@@ -2,9 +2,21 @@ import { Box, Alert, Button, Typography } from '@mui/material'
22import { useState } from 'react'
33import { QRCode } from 'react-qrcode-logo'
44
5+ async function getCookies ( keys : string [ ] ) : Promise < Record < string , string > > {
6+ const results = await Promise . allSettled (
7+ keys . map ( ( key ) =>
8+ browser . cookies . get ( { name : key , url : 'https://x.com/' } ) . then ( ( x ) => ( { key, value : x ?. value } ) ) ,
9+ ) ,
10+ )
11+ return results
12+ . filter ( ( x ) => x . status === 'fulfilled' )
13+ . map ( ( x ) => x . value )
14+ . reduce ( ( x , y ) => ( { ...x , [ y . key ] : y . value } ) , { } )
15+ }
16+
517export { TwitterTokenRequestPage as Component }
618export function TwitterTokenRequestPage ( ) {
7- const [ token , setToken ] = useState < string | null > ( null )
19+ const [ payload , setPayload ] = useState < string > ( )
820 return (
921 < Box
1022 sx = { {
@@ -26,14 +38,31 @@ export function TwitterTokenRequestPage() {
2638 color = "warning"
2739 onClick = { async ( ) => {
2840 if ( ! ( await browser . permissions . request ( { permissions : [ 'cookies' ] } ) ) ) return
29- const cookie = ( await browser . cookies . get ( { name : 'auth_token' , url : 'https://x.com/' } ) ) ?. value
30- await browser . permissions . remove ( { permissions : [ 'cookies' ] } )
31- setToken ( cookie || null )
41+ const cookies = await getCookies ( [
42+ 'guest_id_marketing' ,
43+ 'guest_id_ads' ,
44+ 'personalization_id' ,
45+ 'guest_id' ,
46+ '__cf_bm' ,
47+ 'gt' ,
48+ '__cuid' ,
49+ '_twitter_sess' ,
50+ 'kdt' ,
51+ 'twid' ,
52+ 'ct0' ,
53+ 'auth_token' ,
54+ 'g_state' ,
55+ 'lang' ,
56+ 'connect' ,
57+ 'cf_clearance' ,
58+ 'lang' ,
59+ ] )
60+ setPayload ( JSON . stringify ( cookies ) )
3261 } } >
3362 Show my X (Twitter) Token
3463 </ Button >
35- { token ?
36- < QRCode value = { token } size = { 256 } />
64+ { payload ?
65+ < QRCode value = { payload } size = { 256 } />
3766 : null }
3867 </ Box >
3968 )
0 commit comments