Skip to content

Commit f24f681

Browse files
authored
Merge pull request #1 from DGGua/everyday
feat: add everyday problem
2 parents d713ad5 + 713ccc4 commit f24f681

13 files changed

+1762
-23
lines changed

.vscode/settings.json

+9-2
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,12 @@
1010
".vscode-test": true
1111
},
1212
"tslint.autoFixOnSave": true,
13-
"tslint.ignoreDefinitionFiles": true
14-
}
13+
"tslint.ignoreDefinitionFiles": true,
14+
"editor.defaultFormatter": null,
15+
"[typescript]": {
16+
"editor.defaultFormatter": "vscode.typescript-language-features"
17+
},
18+
"[json]": {
19+
"editor.defaultFormatter": "vscode.json-language-features"
20+
}
21+
}

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ All notable changes to the "leetcode" extension will be documented in this file.
33

44
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
55

6+
## [0.19.0]
7+
8+
### Added
9+
- Add `Daily` category for current month daily problems.
10+
- Add `pickDaily` command for quickly pick daily command.
11+
612
## [0.18.0]
713
### Added
814
- Add `star` command in shortcuts [PR#601](https://github.com/LeetCode-OpenSource/vscode-leetcode/pull/601)

README.md

+23-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# 🐱🐱🐱 this repository is forked from [vscode-leetcode](https://github.com/LeetCode-OpenSource/vscode-leetcode)
2+
3+
This repository is forked for personal needs. I do not want merge it to the origin repository, for my irregular development. I made some features, if you like, please give us a ⭐Star!
4+
5+
### Features
6+
7+
- daily problems. easily use command or choose from sidebar to get problem today!
8+
9+
below are the origin README.md
10+
111
# LeetCode
212

313
> Solve LeetCode problems in VS Code
@@ -23,6 +33,7 @@
2333
- English Document | [中文文档](https://github.com/LeetCode-OpenSource/vscode-leetcode/blob/master/docs/README_zh-CN.md)
2434

2535
## ❗️ Attention ❗️- Workaround to login to LeetCode endpoint
36+
2637
> Note: If you are using `leetcode.cn`, you can just ignore this section.
2738
2839
Recently we observed that [the extension cannot login to leetcode.com endpoint anymore](https://github.com/LeetCode-OpenSource/vscode-leetcode/issues/478). The root cause of this issue is that leetcode.com changed its login mechanism and so far there is no ideal way to fix that issue.
@@ -32,9 +43,10 @@ Thanks for [@yihong0618](https://github.com/yihong0618) provided a workaround wh
3243
> Note: If you want to use third-party login(**Recommended**), please make sure your account has been connected to the third-party. If you want to use `Cookie` login, click [here](https://github.com/LeetCode-OpenSource/vscode-leetcode/issues/478#issuecomment-564757098) to see the steps.
3344
3445
## Requirements
46+
3547
- [VS Code 1.30.1+](https://code.visualstudio.com/)
3648
- [Node.js 10+](https://nodejs.org)
37-
> NOTE: Please make sure that `Node` is in your `PATH` environment variable. You can also use the setting `leetcode.nodePath` to specify the location of your `Node.js` executable.
49+
> NOTE: Please make sure that `Node` is in your `PATH` environment variable. You can also use the setting `leetcode.nodePath` to specify the location of your `Node.js` executable.
3850
3951
## Quick Start
4052

@@ -43,6 +55,7 @@ Thanks for [@yihong0618](https://github.com/yihong0618) provided a workaround wh
4355
## Features
4456

4557
### Sign In/Out
58+
4659
<p align="center">
4760
<img src="https://raw.githubusercontent.com/LeetCode-OpenSource/vscode-leetcode/master/docs/imgs/sign_in.png" alt="Sign in" />
4861
</p>
@@ -52,16 +65,19 @@ Thanks for [@yihong0618](https://github.com/yihong0618) provided a workaround wh
5265
- You can also use the following command to sign in/out:
5366
- **LeetCode: Sign in**
5467
- **LeetCode: Sign out**
68+
5569
---
5670

5771
### Switch Endpoint
72+
5873
<p align="center">
5974
<img src="https://raw.githubusercontent.com/LeetCode-OpenSource/vscode-leetcode/master/docs/imgs/endpoint.png" alt="Switch Endpoint" />
6075
</p>
6176

6277
- By clicking the button ![btn_endpoint](https://raw.githubusercontent.com/LeetCode-OpenSource/vscode-leetcode/master/docs/imgs/btn_endpoint.png) at the **explorer's navigation bar**, you can switch between different endpoints.
6378

6479
- The supported endpoints are:
80+
6581
- **leetcode.com**
6682
- **leetcode.cn**
6783

@@ -70,14 +86,15 @@ Thanks for [@yihong0618](https://github.com/yihong0618) provided a workaround wh
7086
---
7187

7288
### Pick a Problem
89+
7390
<p align="center">
7491
<img src="https://raw.githubusercontent.com/LeetCode-OpenSource/vscode-leetcode/master/docs/imgs/pick_problem.png" alt="Pick a Problem" />
7592
</p>
7693

7794
- Directly click on the problem or right click the problem in the `LeetCode Explorer` and select `Preview Problem` to see the problem description.
7895
- Select `Show Problem` to directly open the file with the problem description.
7996

80-
> Note:You can specify the path of the workspace folder to store the problem files by updating the setting `leetcode.workspaceFolder`. The default value is:**$HOME/.leetcode/**.
97+
> Note:You can specify the path of the workspace folder to store the problem files by updating the setting `leetcode.workspaceFolder`. The default value is:**\$HOME/.leetcode/**.
8198
8299
> You can specify whether including the problem description in comments or not by updating the setting `leetcode.showCommentDescription`.
83100
@@ -86,11 +103,13 @@ Thanks for [@yihong0618](https://github.com/yihong0618) provided a workaround wh
86103
---
87104

88105
### Editor Shortcuts
106+
89107
<p align="center">
90108
<img src="https://raw.githubusercontent.com/LeetCode-OpenSource/vscode-leetcode/master/docs/imgs/shortcuts.png" alt="Editor Shortcuts" />
91109
</p>
92110

93111
- The extension supports 5 editor shortcuts (aka Code Lens):
112+
94113
- `Submit`: Submit your answer to LeetCode.
95114
- `Test`: Test your answer with customized test cases.
96115
- `Star/Unstar`: Star or unstar the current problem.
@@ -102,6 +121,7 @@ Thanks for [@yihong0618](https://github.com/yihong0618) provided a workaround wh
102121
---
103122

104123
### Search problems by Keywords
124+
105125
<p align="center">
106126
<img src="https://raw.githubusercontent.com/LeetCode-OpenSource/vscode-leetcode/master/docs/imgs/search.png" alt="Search problems by Keywords" />
107127
</p>
@@ -111,13 +131,13 @@ Thanks for [@yihong0618](https://github.com/yihong0618) provided a workaround wh
111131
---
112132

113133
### Manage Session
134+
114135
<p align="center">
115136
<img src="https://raw.githubusercontent.com/LeetCode-OpenSource/vscode-leetcode/master/docs/imgs/session.png" alt="Manage Session" />
116137
</p>
117138

118139
- To manage your LeetCode sessions, just clicking the `LeetCode: ***` at the bottom of the status bar. You can **switch** between sessions or **create**, **delete** a session.
119140

120-
121141
## Settings
122142

123143
| Setting Name | Description | Default Value |

package.json

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
{
2-
"name": "vscode-leetcode",
3-
"displayName": "LeetCode",
4-
"description": "Solve LeetCode problems in VS Code",
5-
"version": "0.18.1",
2+
"name": "vscode-leetcode-dggua",
3+
"displayName": "LeetCodeEveryday",
4+
"description": "Solve LeetCode problems in VS Code EveryDay",
5+
"version": "0.19.0",
66
"author": "Sheng Chen",
7-
"publisher": "LeetCode",
7+
"publisher": "dggua",
88
"license": "MIT",
99
"icon": "resources/LeetCode.png",
1010
"engines": {
1111
"vscode": "^1.57.0"
1212
},
1313
"repository": {
1414
"type": "git",
15-
"url": "https://github.com/LeetCode-OpenSource/vscode-leetcode"
15+
"url": "https://github.com/dggua/vscode-leetcode"
1616
},
17-
"homepage": "https://github.com/LeetCode-OpenSource/vscode-leetcode/blob/master/README.md",
1817
"categories": [
1918
"Other",
2019
"Snippets"
@@ -32,6 +31,7 @@
3231
"onCommand:leetcode.manageSessions",
3332
"onCommand:leetcode.refreshExplorer",
3433
"onCommand:leetcode.pickOne",
34+
"onCommand:leetcode.pickToday",
3535
"onCommand:leetcode.showProblem",
3636
"onCommand:leetcode.previewProblem",
3737
"onCommand:leetcode.searchProblem",
@@ -82,6 +82,11 @@
8282
"title": "Pick One",
8383
"category": "LeetCode"
8484
},
85+
{
86+
"command": "leetcode.pickToday",
87+
"title": "Pick Problem Today",
88+
"category": "LeetCode"
89+
},
8590
{
8691
"command": "leetcode.showProblem",
8792
"title": "Show Problem",
@@ -709,7 +714,8 @@
709714
"vscode:prepublish": "npm run compile",
710715
"compile": "tsc -p ./",
711716
"watch": "tsc -watch -p ./",
712-
"lint": "tslint --project tsconfig.json -e src/*.d.ts -t verbose"
717+
"lint": "tslint --project tsconfig.json -e src/*.d.ts -t verbose",
718+
"publish": "vsce package"
713719
},
714720
"devDependencies": {
715721
"@types/fs-extra": "^9.0.11",
@@ -723,6 +729,7 @@
723729
"typescript": "^4.3.2"
724730
},
725731
"dependencies": {
732+
"axios": "^0.27.2",
726733
"fs-extra": "^10.0.0",
727734
"highlight.js": "^10.7.2",
728735
"lodash": "^4.17.21",

src/commands/list.ts

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// Copyright (c) jdneo. All rights reserved.
22
// Licensed under the MIT license.
33

4+
import axios from "axios"
45
import * as vscode from "vscode";
56
import { leetCodeExecutor } from "../leetCodeExecutor";
67
import { leetCodeManager } from "../leetCodeManager";
7-
import { IProblem, ProblemState, UserStatus } from "../shared";
8+
import { DailyProblem, DailyProblemSet, IProblem, ProblemState, UserStatus } from "../shared";
89
import * as settingUtils from "../utils/settingUtils";
910
import { DialogType, promptForOpenOutputChannel } from "../utils/uiUtils";
1011

@@ -45,6 +46,32 @@ export async function listProblems(): Promise<IProblem[]> {
4546
}
4647
}
4748

49+
export async function listDailyProblems(context: vscode.ExtensionContext): Promise<DailyProblem[]> {
50+
try {
51+
const cookie = context.globalState.get<string>("cookie")
52+
if (leetCodeManager.getStatus() === UserStatus.SignedOut || cookie === undefined) {
53+
return [];
54+
}
55+
const date = new Date();
56+
const res = await axios.post<DailyProblemSet>(
57+
"https://leetcode.cn/graphql/", {
58+
"query": "\n query dailyQuestionRecords($year: Int!, $month: Int!) {\n dailyQuestionRecords(year: $year, month: $month) {\n date\n userStatus\n question {\n questionFrontendId\n title\n titleSlug\n translatedTitle\n }\n }\n}\n ",
59+
"variables": {
60+
"year": date.getFullYear(),
61+
"month": date.getMonth() + 1,
62+
}
63+
}, {
64+
headers: {
65+
cookie,
66+
},
67+
})
68+
return res.data.data.dailyQuestionRecords;
69+
} catch (e) {
70+
await promptForOpenOutputChannel("Failed to list daily Problems. Please open the output channel for details.", DialogType.error);
71+
return []
72+
}
73+
}
74+
4875
function parseProblemState(stateOutput: string): ProblemState {
4976
if (!stateOutput) {
5077
return ProblemState.Unknown;

src/commands/show.ts

+12
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ export async function pickOne(): Promise<void> {
5252
await showProblemInternal(randomProblem);
5353
}
5454

55+
export async function pickToday(context: vscode.ExtensionContext): Promise<void> {
56+
const dailyProblems = await list.listDailyProblems(context);
57+
const problemToday = dailyProblems.find(problem => Number.parseInt(problem.date.split("-")[2]) == new Date().getDate())
58+
const problems: IProblem[] = await list.listProblems();
59+
const targetProblem = problems.find(problem => problem.id == problemToday?.question.questionFrontendId)
60+
if (!targetProblem) {
61+
vscode.window.showErrorMessage("Get problem today failed.");
62+
return;
63+
}
64+
await showProblemInternal(targetProblem)
65+
}
66+
5567
export async function showProblem(node?: LeetCodeNode): Promise<void> {
5668
if (!node) {
5769
return;

src/explorer/LeetCodeNode.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { IProblem, ProblemState } from "../shared";
66

77
export class LeetCodeNode {
88

9-
constructor(private data: IProblem, private isProblemNode: boolean = true) { }
9+
constructor(protected data: IProblem, private isProblemNode: boolean = true) { }
1010

1111
public get locked(): boolean {
1212
return this.data.locked;
@@ -47,6 +47,10 @@ export class LeetCodeNode {
4747
return this.isProblemNode;
4848
}
4949

50+
public get dataClone(): IProblem {
51+
return Object.assign({}, this.data)
52+
}
53+
5054
public get previewCommand(): Command {
5155
return {
5256
title: "Preview Problem",
@@ -67,5 +71,11 @@ export class LeetCodeNode {
6771
query: `difficulty=${this.difficulty}`,
6872
});
6973
}
74+
}
7075

76+
export class LeetCodeDailyNode extends LeetCodeNode {
77+
78+
constructor(node: LeetCodeNode, public date: Date) {
79+
super(node.dataClone);
80+
}
7181
}

src/explorer/LeetCodeTreeDataProvider.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as vscode from "vscode";
77
import { leetCodeManager } from "../leetCodeManager";
88
import { Category, defaultProblem, ProblemState } from "../shared";
99
import { explorerNodeManager } from "./explorerNodeManager";
10-
import { LeetCodeNode } from "./LeetCodeNode";
10+
import { LeetCodeDailyNode, LeetCodeNode } from "./LeetCodeNode";
1111

1212
export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCodeNode> {
1313

@@ -46,7 +46,11 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
4646
}
4747

4848
return {
49-
label: element.isProblem ? `[${element.id}] ${element.name}` : element.name,
49+
label: element.isProblem ?
50+
`[${element instanceof LeetCodeDailyNode ?
51+
`${element.date.getMonth()}-${element.date.getDate()}` :
52+
element.id}] ${element.name}` :
53+
element.name,
5054
tooltip: this.getSubCategoryTooltip(element),
5155
collapsibleState: element.isProblem ? vscode.TreeItemCollapsibleState.None : vscode.TreeItemCollapsibleState.Collapsed,
5256
iconPath: this.parseIconPathFromProblemState(element),
@@ -69,6 +73,8 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
6973
return explorerNodeManager.getRootNodes();
7074
} else {
7175
switch (element.id) { // First-level
76+
case Category.Daily:
77+
return explorerNodeManager.getDailyNodes();
7278
case Category.All:
7379
return explorerNodeManager.getAllNodes();
7480
case Category.Favorite:

0 commit comments

Comments
 (0)