forked from kkuchar2/leetcode_session_creator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (35 loc) · 1.14 KB
/
index.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
26
27
28
29
30
31
32
33
34
35
36
37
38
const LEETCODE_SESSION = "MY_LEETCODE_SESSION"
const CSRF_TOKEN = "MY_CSRF_TOKEN"
const NEW_SESSION_NAME = "MyNewSession1";
const fetchWithRetry = async (url, options, retries) => {
for (let i = 0; i < retries; i++) {
try {
const response = await fetch(url, options);
if (response.ok) {
console.log('Request succeeded:', response);
return response;
} else {
console.log('Request failed');
}
} catch (error) {
console.log('Fetch error:', error);
}
}
console.log(`All ${retries} attempts failed.`);
};
const url = "https://leetcode.com/session/";
const options = {
headers: {
"content-type": "application/json",
"x-csrftoken": CSRF_TOKEN,
"x-requested-with": "XMLHttpRequest",
"cookie": `LEETCODE_SESSION=${LEETCODE_SESSION};`
},
body: JSON.stringify({
func: "create",
name: NEW_SESSION_NAME
}),
method: "PUT"
};
const maxRetries = 50; // Set the maximum number of retries you are welcome to change this value
fetchWithRetry(url, options, maxRetries);