Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4979a0f

Browse files
yihong0618jdneo
authored andcommitted
feat: add leetcode.signinByCookie but simple change (LeetCode-OpenSource#487)
1 parenteb77cd9 commit4979a0f

File tree

5 files changed

+27
-14
lines changed

5 files changed

+27
-14
lines changed

‎README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@
4040

4141
- Simply click`Sign in to LeetCode` in the`LeetCode Explorer` will let you**sign in** with your LeetCode account.
4242

43-
- You can also use the following command to sign in/out:
43+
- You can also use the following command to sign in/sign in (by cookie)/out:
4444
-**LeetCode: Sign in**
45+
-**LeetCode: Sign in (by cookie)**
4546
-**LeetCode: Sign out**
4647

4748
---

‎docs/README_zh-CN.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@
4040

4141
- 点击`LeetCode Explorer` 中的`Sign in to LeetCode` 即可登入。
4242

43-
-你也可以使用下来命令登入或登出:
43+
-你也可以使用下来命令登入或利用cookie登入或登出:
4444
-**LeetCode: Sign in**
45+
-**LeetCode: Sign in (by cookie)**
4546
-**LeetCode: Sign out**
4647

4748
---

‎package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,17 @@
3838
"onCommand:leetcode.testSolution",
3939
"onCommand:leetcode.submitSolution",
4040
"onCommand:leetcode.switchDefaultLanguage",
41+
"onCommand:leetcode.signinByCookie",
4142
"onView:leetCodeExplorer"
4243
],
4344
"main":"./out/src/extension",
4445
"contributes": {
4546
"commands": [
47+
{
48+
"command":"leetcode.signinByCookie",
49+
"title":"Sign In by Cookie",
50+
"category":"LeetCode"
51+
},
4652
{
4753
"command":"leetcode.deleteCache",
4854
"title":"Delete Cache",
@@ -683,6 +689,6 @@
683689
"markdown-it":"^8.4.2",
684690
"require-from-string":"^2.0.2",
685691
"unescape-js":"^1.1.1",
686-
"vsc-leetcode-cli":"2.6.16"
692+
"vsc-leetcode-cli":"2.6.17"
687693
}
688694
}

‎src/extension.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
5151
vscode.commands.registerCommand("leetcode.deleteCache",()=>cache.deleteCache()),
5252
vscode.commands.registerCommand("leetcode.toggleLeetCodeCn",()=>plugin.switchEndpoint()),
5353
vscode.commands.registerCommand("leetcode.signin",()=>leetCodeManager.signIn()),
54+
vscode.commands.registerCommand("leetcode.signinByCookie",()=>leetCodeManager.signIn(true)),
5455
vscode.commands.registerCommand("leetcode.signout",()=>leetCodeManager.signOut()),
5556
vscode.commands.registerCommand("leetcode.manageSessions",()=>session.manageSessions()),
5657
vscode.commands.registerCommand("leetcode.previewProblem",(node:LeetCodeNode)=>show.previewProblem(node)),

‎src/leetCodeManager.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,20 @@ class LeetCodeManager extends EventEmitter {
3434
}
3535
}
3636

37-
publicasyncsignIn():Promise<void>{
37+
publicasyncsignIn(isByCookie:boolean=false):Promise<void>{
38+
constloginArg:string="-l";
39+
constcookieArg:string="-c";
40+
constcommandArg:string=isByCookie ?cookieArg :loginArg;
41+
constinMessage:string=isByCookie ?"sign in by cookie" :"sign in";
3842
try{
3943
constuserName:string|undefined=awaitnewPromise(async(resolve:(res:string|undefined)=>void,reject:(e:Error)=>void):Promise<void>=>{
4044
letresult:string="";
4145

4246
constleetCodeBinaryPath:string=awaitleetCodeExecutor.getLeetCodeBinaryPath();
4347

4448
constchildProc:cp.ChildProcess=wsl.useWsl()
45-
?cp.spawn("wsl",[leetCodeExecutor.node,leetCodeBinaryPath,"user","-l"],{shell:true})
46-
:cp.spawn(leetCodeExecutor.node,[leetCodeBinaryPath,"user","-l"],{
49+
?cp.spawn("wsl",[leetCodeExecutor.node,leetCodeBinaryPath,"user",commandArg],{shell:true})
50+
:cp.spawn(leetCodeExecutor.node,[leetCodeBinaryPath,"user",commandArg],{
4751
shell:true,
4852
env:createEnvOption(),
4953
});
@@ -67,9 +71,9 @@ class LeetCodeManager extends EventEmitter {
6771
}
6872
childProc.stdin.write(`${name}\n`);
6973
constpwd:string|undefined=awaitvscode.window.showInputBox({
70-
prompt:"Enter password.",
74+
prompt:isByCookie ?"Enter cookie" :"Enter password.",
7175
password:true,
72-
validateInput:(s:string):string|undefined=>s ?undefined :"Password must not be empty",
76+
validateInput:(s:string):string|undefined=>s ?undefined :isByCookie ?"Cookie must not be empty" :"Password must not be empty",
7377
});
7478
if(!pwd){
7579
childProc.kill();
@@ -78,22 +82,22 @@ class LeetCodeManager extends EventEmitter {
7882
childProc.stdin.write(`${pwd}\n`);
7983
childProc.stdin.end();
8084
childProc.on("close",()=>{
81-
constmatch:RegExpMatchArray|null=result.match(/(?:.*)Successfullyloginas(.*)/i);
82-
if(match&&match[1]){
83-
resolve(match[1]);
85+
constmatch:RegExpMatchArray|null=result.match(/(?:.*)Successfully(login|cookielogin)as(.*)/i);
86+
if(match&&match[2]){
87+
resolve(match[2]);
8488
}else{
85-
reject(newError("Failed tosign in."));
89+
reject(newError(`Failed to${inMessage}.`));
8690
}
8791
});
8892
});
8993
if(userName){
90-
vscode.window.showInformationMessage("Successfullysigned in.");
94+
vscode.window.showInformationMessage(`Successfully${inMessage}.`);
9195
this.currentUser=userName;
9296
this.userStatus=UserStatus.SignedIn;
9397
this.emit("statusChanged");
9498
}
9599
}catch(error){
96-
promptForOpenOutputChannel("Failed tosign in. Please open the output channel for details",DialogType.error);
100+
promptForOpenOutputChannel(`Failed to${inMessage}. Please open the output channel for details`,DialogType.error);
97101
}
98102

99103
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp