Skip to content

Commit e5572b6

Browse files
committed
feat: add get question
1 parent 80dc9f5 commit e5572b6

File tree

3 files changed

+830
-1
lines changed

3 files changed

+830
-1
lines changed

common/question/getQuestion.js

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
const { JSDOM } = require('jsdom')
2+
const { open } = require('../scripts/open.js');
3+
4+
const fs = require('fs')
5+
6+
const root = new JSDOM(`
7+
<!DOCTYPE html>
8+
<html lang="en">
9+
<head>
10+
<meta charset="UTF-8">
11+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
12+
<title>leetcode today question</title>
13+
</head>
14+
<body>
15+
<div id="app">
16+
<code id="code"><code>
17+
</div>
18+
</body>
19+
</html>`)
20+
21+
const window = root.window
22+
const document = window.document
23+
const code = document.querySelector('#code')
24+
let questionInfo = {}
25+
26+
fetch("https://leetcode.cn/graphql/", {
27+
"headers": {
28+
"accept": "*/*",
29+
"accept-language": "zh-CN,zh;q=0.9",
30+
"authorization": "",
31+
"baggage": "sentry-environment=production,sentry-release=dc00d92c,sentry-transaction=%2Fproblemset%2F%5B%5B...slug%5D%5D,sentry-public_key=1595090ae2f831f9e65978be5851f865,sentry-trace_id=ba393efa1eea41d4969fc786e395ab6e,sentry-sample_rate=0.03",
32+
"content-type": "application/json",
33+
"random-uuid": "3ba3266f-8cdc-50f8-76a8-afb018b0800f",
34+
"sec-ch-ua": "\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\"",
35+
"sec-ch-ua-mobile": "?0",
36+
"sec-ch-ua-platform": "\"macOS\"",
37+
"sec-fetch-dest": "empty",
38+
"sec-fetch-mode": "cors",
39+
"sec-fetch-site": "same-origin",
40+
"sentry-trace": "ba393efa1eea41d4969fc786e395ab6e-8b7475c76892197e-0",
41+
"x-csrftoken": "Zms4ivZqGOCDM8rI8PE6p8uqqpYfhZeVIePkpFo8QruFlcc7cK4JxnDXZuoKdF41",
42+
"cookie": "_bl_uid=a1lz4p9q294cs4d74npj8UU4g8p1; csrftoken=Zms4ivZqGOCDM8rI8PE6p8uqqpYfhZeVIePkpFo8QruFlcc7cK4JxnDXZuoKdF41; gr_user_id=b3bd9d67-816b-478c-b4ee-f13e289fd1b8; a2873925c34ecbd2_gr_last_sent_cs1=smallteddy; _gid=GA1.2.2051268794.1704617261; _ga=GA1.1.42792980.1700208726; _ga_PDVPZYN3CW=GS1.1.1704886059.33.0.1704886061.58.0.0; messages=W1siX19qc29uX21lc3NhZ2UiLDAsMjUsIlx1NjBhOFx1NWRmMlx1N2VjZlx1NzY3Ylx1NTFmYSJdXQ:1rNWkI:1nVd_sKKmyTppZxAsssinmGIk4G90lUMosacBL3WG_A; a2873925c34ecbd2_gr_session_id=0518b7a0-93b3-40da-a75d-c2fa87dbafbf; a2873925c34ecbd2_gr_last_sent_sid_with_cs1=0518b7a0-93b3-40da-a75d-c2fa87dbafbf; a2873925c34ecbd2_gr_cs1=smallteddy; a2873925c34ecbd2_gr_session_id_sent_vst=0518b7a0-93b3-40da-a75d-c2fa87dbafbf; Hm_lvt_f0faad39bcf8471e3ab3ef70125152c3=1704421023; Hm_lpvt_f0faad39bcf8471e3ab3ef70125152c3=1704886064",
43+
"Referer": "https://leetcode.cn/problemset/",
44+
"Referrer-Policy": "strict-origin-when-cross-origin"
45+
},
46+
"body": "{\"query\":\"\\n query questionOfToday {\\n todayRecord {\\n date\\n userStatus\\n question {\\n questionId\\n frontendQuestionId: questionFrontendId\\n difficulty\\n title\\n titleCn: translatedTitle\\n titleSlug\\n paidOnly: isPaidOnly\\n freqBar\\n isFavor\\n acRate\\n status\\n solutionNum\\n hasVideoSolution\\n topicTags {\\n name\\n nameTranslated: translatedName\\n id\\n }\\n extra {\\n topCompanyTags {\\n imgUrl\\n slug\\n numSubscribed\\n }\\n }\\n }\\n lastSubmission {\\n id\\n }\\n }\\n}\\n \",\"variables\":{},\"operationName\":\"questionOfToday\"}",
47+
"method": "POST"
48+
}).then((res => res.json())).then(res => {
49+
questionInfo = res.data.todayRecord[0].question
50+
code.innerHTML = JSON.stringify(questionInfo, null, 2)
51+
fs.writeFileSync('./index.html', root.serialize())
52+
open('./index.html')
53+
});

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66
"type": "commonjs",
77
"scripts": {
88
"leet-check": "node common/scripts/check.js",
9-
"leet-create": "node common/scripts/create.js"
9+
"leet-create": "node common/scripts/create.js",
10+
"preget-question": "rm -rf index.html",
11+
"get-question": "VITE_CJS_IGNORE_WARNING=true node common/question/getQuestion.js"
1012
},
1113
"author": "EternalHeart",
1214
"license": "ISC",
1315
"dependencies": {
16+
"jsdom": "^23.2.0",
17+
"vite": "^5.0.11"
1418
}
1519
}

0 commit comments

Comments
 (0)