File tree 1 file changed +11
-1
lines changed
1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ class LeetCodeManager extends EventEmitter {
24
24
public async getLoginStatus ( ) : Promise < void > {
25
25
try {
26
26
const result : string = await leetCodeExecutor . getUserInfo ( ) ;
27
- this . currentUser = result . slice ( "You are now login as" . length ) . trim ( ) ;
27
+ this . currentUser = this . tryParseUserName ( result ) ;
28
28
this . userStatus = UserStatus . SignedIn ;
29
29
} catch ( error ) {
30
30
this . currentUser = undefined ;
@@ -117,6 +117,16 @@ class LeetCodeManager extends EventEmitter {
117
117
public getUser ( ) : string | undefined {
118
118
return this . currentUser ;
119
119
}
120
+
121
+ private tryParseUserName ( output : string ) : string {
122
+ const reg : RegExp = / ^ \s * .\s * ( .+ ?) \s * h t t p s : \/ \/ l e e t c o d e / m;
123
+ const match : RegExpMatchArray | null = output . match ( reg ) ;
124
+ if ( match && match . length === 2 ) {
125
+ return match [ 1 ] . trim ( ) ;
126
+ }
127
+
128
+ return "Unknown" ;
129
+ }
120
130
}
121
131
122
132
export const leetCodeManager : LeetCodeManager = new LeetCodeManager ( ) ;
You can’t perform that action at this time.
0 commit comments