Skip to content

Commit 6170505

Browse files
authored
Update index.js
Update to add a call for question note saved by user, and update the readme accordingly
1 parent 335feea commit 6170505

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

index.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ const mdTemplate = `
55
\`\`\`{{lang}}
66
{{code}}
77
\`\`\`
8+
##Note
9+
\`\`\`
10+
{{question_note}}
11+
\`\`\`
812
`;
913
const header = '';
1014
const footer = '';
11-
const waitTime = 200;
15+
const waitTime = 300;
1216
const onlyFetchFirstPage = false;
1317
// config end
1418

@@ -34,6 +38,27 @@ async function getSubmission(page) {
3438
});
3539
}
3640

41+
async function getNoteForQuestion(questionSlug) {
42+
var url = `/graphql`;
43+
return new Promise((resolve, reject) => {
44+
$.ajax({
45+
url: url,
46+
type: "POST",
47+
contentType: "application/json",
48+
data: JSON.stringify({
49+
query: "query questionNote($titleSlug: String!) {\n question(titleSlug: $titleSlug) {\n questionId\n note\n }\n}\n",
50+
variables: { "titleSlug": questionSlug }
51+
}),
52+
success: function (data) {
53+
resolve(data);
54+
},
55+
error: function () {
56+
resolve('failed');
57+
},
58+
});
59+
});
60+
}
61+
3762
async function getSolution(url) {
3863
return new Promise((resolve) => {
3964
$.ajax({
@@ -90,12 +115,20 @@ for (let i = 0; i < accepts.length; i++) {
90115
codeObj = eval(content.slice(start, end));
91116
console.log(codeObj);
92117

118+
let note_content = await getNoteForQuestion(item.titleSlug);
119+
while (response == 'failed') {
120+
await pause(waitTime);
121+
note_content = await getNoteForQuestion(item.titleSlug);
122+
}
123+
let question_note = response.data.question.note;
124+
93125
solutions.push({
94126
title: item.title,
95127
code: codeObj.submissionCode,
96128
url: `https://leetcode.com${codeObj.editCodeUrl}description/`,
97129
questionId: codeObj.questionId,
98130
lang: item.lang,
131+
question_note: question_note
99132
});
100133
}
101134
solutions.sort((a, b) => parseInt(a.questionId) - parseInt(b.questionId))

0 commit comments

Comments
 (0)