File tree Expand file tree Collapse file tree 3 files changed +29
-1
lines changed Expand file tree Collapse file tree 3 files changed +29
-1
lines changed Original file line number Diff line number Diff line change
1
+ import { GM_getValue } from '$'
2
+ import { TOTP } from 'totp-generator'
3
+ import { observe } from '../observer'
4
+ import { writeToken } from '../utils'
5
+ import { Handler } from './handler'
6
+
7
+ export class LoginHandler implements Handler {
8
+ shouldLoad ( ) : boolean {
9
+ return false
10
+ }
11
+
12
+ load ( ) : void {
13
+ const secret = GM_getValue ( 'totpSecret' , null )
14
+ if ( secret != null ) {
15
+ observe ( '#tokenValidationModal' , ( ) => {
16
+ const { otp } = TOTP . generate ( secret )
17
+ writeToken ( otp )
18
+ } )
19
+ }
20
+ }
21
+ }
Original file line number Diff line number Diff line change 1
1
import { Handler } from './handlers/handler'
2
+ import { LoginHandler } from './handlers/login'
2
3
3
- const handlers : Handler [ ] = [ ]
4
+ const handlers : Handler [ ] = [ new LoginHandler ( ) ]
4
5
5
6
handlers . forEach ( ( h ) => {
6
7
if ( h . shouldLoad ( ) ) h . load ( )
Original file line number Diff line number Diff line change @@ -3,3 +3,9 @@ import $ from 'jquery'
3
3
export function isTokenModelOpen ( ) : boolean {
4
4
return $ ( '#tokenValidationModal' ) . css ( 'display' ) !== 'none'
5
5
}
6
+
7
+ export function writeToken ( token : string ) {
8
+ const input = $ ( 'input[name="token"]' )
9
+ input . val ( token )
10
+ $ ( 'button[sdaValidateToken=submit]' ) [ 0 ] . click ( )
11
+ }
You can’t perform that action at this time.
0 commit comments