-
Notifications
You must be signed in to change notification settings - Fork 18
/
fetch.js
25 lines (23 loc) · 829 Bytes
/
fetch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import rookie from "@rookie-rs/api";
function createHeaders() {
// Get all Github cookies from all browsers
const cookies = rookie.load(["github.com"]);
// Create cookie header
const cookie = cookies
.map((c) => decodeURIComponent(`${c.name}=${c.value}`))
.join(";");
const userAgent =
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36";
return {
"User-Agent": userAgent,
Cookie: cookie,
};
}
const headers = createHeaders();
const res = await fetch("https://github.com/settings/profile", { headers });
const html = await res.text();
// Parse username from HTML
const username =
html.match(/<a href="\/(.+)" class="btn.+>/)?.[1] ??
`Not Logged In. Response URL: ${res.url}`;
console.log(`Github username: ${username}`);