|
1 | 1 | import {SimpleHandler} from './main'; |
2 | 2 | import {RequestType} from './types'; |
3 | 3 |
|
4 | | -export interface SendCookiesRequest { |
5 | | - verify_only?: boolean; |
6 | | -} |
| 4 | +export interface SendCookiesRequest {} |
7 | 5 |
|
8 | 6 | export interface SendCookiesResponse {} |
9 | 7 |
|
10 | 8 | export const SendCookies = new SimpleHandler<SendCookiesRequest, SendCookiesResponse>( |
11 | 9 | RequestType.SEND_COOKIES, |
12 | 10 | async (req) => { |
13 | | - console.log('cookies 123'); |
14 | | - // @ts-ignore MV3 returns a promise |
15 | | - const hasPermission = (await chrome.permissions.contains({ |
16 | | - permissions: ['cookies'], |
17 | | - origins: ['https://steamcommunity.com/'], |
18 | | - })) as boolean; |
19 | | - |
20 | | - console.log(hasPermission); |
21 | | - |
22 | | - if (!hasPermission) { |
23 | | - // @ts-ignore MV3 returns a promise |
24 | | - const granted = (await chrome.permissions.request({ |
25 | | - permissions: ['cookies'], |
26 | | - origins: ['https://steamcommunity.com/'], |
27 | | - })) as boolean; |
28 | | - if (!granted) { |
29 | | - throw new Error('failed to grant permission, cannot proceed'); |
30 | | - } |
31 | | - } |
32 | | - |
33 | | - if (req.verify_only) { |
34 | | - return {} as SendCookiesResponse; |
35 | | - } |
36 | | - |
37 | 11 | const cookies = await chrome.cookies.getAll({ |
38 | 12 | domain: 'steamcommunity.com', |
39 | 13 | }); |
40 | 14 |
|
41 | | - console.log(cookies); |
| 15 | + // For use in verifying trades on CSFloat, opt-in |
| 16 | + const formatted = cookies |
| 17 | + .filter((e) => { |
| 18 | + return [ |
| 19 | + 'timezoneOffset', |
| 20 | + 'Steam_Language', |
| 21 | + 'browserid', |
| 22 | + 'sessionid', |
| 23 | + 'steamCountry', |
| 24 | + 'steamLoginSecure', |
| 25 | + ].includes(e.name); |
| 26 | + }) |
| 27 | + .map((e) => { |
| 28 | + return { |
| 29 | + name: e.name, |
| 30 | + value: e.value, |
| 31 | + expiration: e.expirationDate, |
| 32 | + }; |
| 33 | + }); |
| 34 | + |
| 35 | + const resp = await fetch(`https://csfloat.com/api/v1/me/steam-cookies`, { |
| 36 | + credentials: 'include', |
| 37 | + method: 'POST', |
| 38 | + headers: { |
| 39 | + 'Content-Type': 'application/json', |
| 40 | + }, |
| 41 | + body: JSON.stringify({ |
| 42 | + cookies: formatted, |
| 43 | + }), |
| 44 | + }); |
42 | 45 |
|
43 | 46 | return {} as SendCookiesResponse; |
44 | | - // const resp = await fetch(`https://csfloat.com/api/v1/me/steam-cookies`, { |
45 | | - // credentials: 'include', |
46 | | - // method: 'POST', |
47 | | - // headers: { |
48 | | - // 'Content-Type': 'application/json', |
49 | | - // }, |
50 | | - // body: JSON.stringify(req), |
51 | | - // }); |
52 | 47 | } |
53 | 48 | ); |
0 commit comments