|
| 1 | +import config from "./config" |
| 2 | +const url = "https://leetcode.com/graphql"; |
| 3 | +const body2 = `{"operationName":"getContestRankingData","variables":{"username":"aditi"},"query":"query getContestRankingData($username: String!) {\ |
| 4 | + userContestRanking(username: aditi) {\ |
| 5 | + attendedContestsCount\ |
| 6 | + rating\ |
| 7 | + globalRanking\ |
| 8 | + }\ |
| 9 | + }\ |
| 10 | + "}`; |
| 11 | +const test = () => { |
| 12 | + fetch(url, { |
| 13 | + method: "POST", |
| 14 | + headers: { |
| 15 | + accept: "*/*", |
| 16 | + "accept-language": "en-GB,en-US;q=0.9,en;q=0.8,hi;q=0.7,ru;q=0.6", |
| 17 | + "cache-control": "no-cache", |
| 18 | + "content-type": "application/json", |
| 19 | + pragma: "no-cache", |
| 20 | + "sec-ch-ua-mobile": "?0", |
| 21 | + "sec-ch-ua": |
| 22 | + '" Not;A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"', |
| 23 | + "sec-fetch-dest": "empty", |
| 24 | + "sec-fetch-mode": "cors", |
| 25 | + "sec-fetch-site": "same-origin", |
| 26 | + "sec-gpc": "1", |
| 27 | + }, |
| 28 | + referrerPolicy: "strict-origin-when-cross-origin", |
| 29 | + mode: "cors", |
| 30 | + body: body2, |
| 31 | + }) |
| 32 | + .then((res) => res.json()) |
| 33 | + .then((data) => { |
| 34 | + console.table(data); |
| 35 | + }); |
| 36 | +} |
| 37 | + |
| 38 | +// Just some constants |
| 39 | +const LEETCODE_API_ENDPOINT = "https://leetcode.com/graphql"; |
| 40 | +const DAILY_CODING_CHALLENGE_QUERY = ` |
| 41 | +query questionOfToday { |
| 42 | + activeDailyCodingChallengeQuestion { |
| 43 | + date |
| 44 | + userStatus |
| 45 | + link |
| 46 | + question { |
| 47 | + acRate |
| 48 | + difficulty |
| 49 | + freqBar |
| 50 | + frontendQuestionId: questionFrontendId |
| 51 | + isFavor |
| 52 | + paidOnly: isPaidOnly |
| 53 | + status |
| 54 | + title |
| 55 | + titleSlug |
| 56 | + hasVideoSolution |
| 57 | + hasSolution |
| 58 | + topicTags { |
| 59 | + name |
| 60 | + id |
| 61 | + slug |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | +}`; |
| 66 | + |
| 67 | +// We can pass the JSON response as an object to our createTodoistTask later. |
| 68 | +const fetchDailyCodingChallenge = async () => { |
| 69 | + console.log(`Fetching daily coding challenge from LeetCode API.`); |
| 70 | + document.cookie = config.COOKIE |
| 71 | + console.log("Cookie Set"); |
| 72 | + console.table(document.cookie); |
| 73 | + const init = { |
| 74 | + method: "POST", |
| 75 | + headers: { "Content-Type": "application/json" }, |
| 76 | + body: JSON.stringify({ query: DAILY_CODING_CHALLENGE_QUERY }), |
| 77 | + referrer: "https://leetcode.com", |
| 78 | + referrerPolicy: "strict-origin-when-cross-origin", |
| 79 | + from: { |
| 80 | + csrfmiddlewaretoken:config.csrfmiddlewaretoken, |
| 81 | + login: "", |
| 82 | + password: "", |
| 83 | + }, |
| 84 | + }; |
| 85 | + |
| 86 | + const response = await fetch(LEETCODE_API_ENDPOINT, init); |
| 87 | + return response.json(); |
| 88 | +}; |
| 89 | + |
| 90 | +console.log(document.cookie); |
| 91 | +console.log(fetchDailyCodingChallenge()); |
0 commit comments