1
- $ ( function ( ) {
1
+ window . lichess . load . then ( ( ) => {
2
2
3
- var $form = $ ( ".search__form" ) ;
4
- var $usernames = $form . find ( ".usernames input" ) ;
5
- var $userRows = $form . find ( ".user-row" ) ;
6
- var $result = $ ( ".search__result" ) ;
3
+ const form = document . querySelector ( '.search__form' ) as HTMLFormElement ,
4
+ $form = $ ( form ) ,
5
+ $usernames = $form . find ( ".usernames input" ) ,
6
+ $userRows = $form . find ( ".user-row" ) ,
7
+ $result = $ ( ".search__result" ) ;
7
8
8
9
function getUsernames ( ) {
9
- var us = [ ] ;
10
- $usernames . each ( function ( ) {
11
- var u = $ ( this ) . val ( ) . trim ( ) ;
10
+ const us : string [ ] = [ ] ;
11
+ $usernames . each ( function ( this : HTMLInputElement ) {
12
+ const u = this . value . trim ( ) ;
12
13
if ( u ) us . push ( u ) ;
13
14
} ) ;
14
15
return us ;
@@ -21,7 +22,7 @@ $(function() {
21
22
return ( row . classList . contains ( rowClassName ) && player . length && user == player ) ? "selected" : ""
22
23
}
23
24
getUsernames ( ) . forEach ( function ( user ) {
24
- var option = [ ] ;
25
+ const option : string [ ] = [ ] ;
25
26
option . push ( "<option value='" + user + "'" ) ;
26
27
option . push ( isSelected ( row , "winner" , user , 'req-winner' ) ) ;
27
28
option . push ( isSelected ( row , "loser" , user , 'req-loser' ) ) ;
@@ -35,25 +36,24 @@ $(function() {
35
36
}
36
37
37
38
function reloadUserChoices ( ) {
38
- $userRows . each ( function ( ) {
39
+ $userRows . each ( function ( this : HTMLTableRowElement ) {
39
40
userChoices ( this ) ;
40
41
} ) ;
41
42
}
42
43
reloadUserChoices ( ) ;
43
44
$usernames . on ( "input paste" , reloadUserChoices ) ;
44
45
45
46
var toggleAiLevel = function ( ) {
46
- $form . find ( ".opponent select" ) . each ( function ( ) {
47
- $form [ 0 ] . querySelector ( '.aiLevel' ) ?. classList . toggle ( 'none' , $ ( this ) . val ( ) != 1 ) ;
48
- $form [ 0 ] . querySelector ( '.opponentName' ) ?. classList . toggle ( 'none' , $ ( this ) . val ( ) == 1 ) ;
47
+ $form . find ( ".opponent select" ) . each ( function ( this : HTMLSelectElement ) {
48
+ $form [ 0 ] . querySelector ( '.aiLevel' ) ?. classList . toggle ( 'none' , this . value != "1" ) ;
49
+ $form [ 0 ] . querySelector ( '.opponentName' ) ?. classList . toggle ( 'none' , this . value == "1" ) ;
49
50
} ) ;
50
51
} ;
51
52
toggleAiLevel ( ) ;
52
53
$form . find ( ".opponent select" ) . change ( toggleAiLevel ) ;
53
54
54
55
function serialize ( ) {
55
- const data = new FormData ( $form [ 0 ] ) ,
56
- params = new URLSearchParams ( data ) ,
56
+ const params = new URLSearchParams ( new FormData ( form ) as any ) ,
57
57
keys = Array . from ( params . keys ( ) ) ;
58
58
for ( let k of keys ) {
59
59
if ( params . get ( k ) == '' ) params . delete ( k ) ;
@@ -62,10 +62,10 @@ $(function() {
62
62
}
63
63
64
64
const serialized = serialize ( ) ;
65
- $result . find ( "a.permalink" ) . each ( function ( ) {
65
+ $result . find ( "a.permalink" ) . each ( function ( this : HTMLAnchorElement ) {
66
66
$ ( this ) . attr ( "href" , $ ( this ) . attr ( "href" ) . split ( '?' ) [ 0 ] + "?" + serialized ) ;
67
67
} ) ;
68
- $result . find ( '.search__rows' ) . each ( function ( ) {
68
+ $result . find ( '.search__rows' ) . each ( function ( this : HTMLTableRowElement ) {
69
69
var $next = $ ( this ) . find ( ".pager a" ) ;
70
70
if ( ! $next . length ) return ;
71
71
$next . attr ( "href" , $next . attr ( "href" ) + "&" + serialized ) ;
@@ -79,12 +79,12 @@ $(function() {
79
79
}
80
80
} , function ( ) {
81
81
$ ( "#infscr-loading" ) . remove ( ) ;
82
- lichess . pubsub . emit ( 'content_loaded' ) ;
82
+ window . lichess . pubsub . emit ( 'content_loaded' ) ;
83
83
} ) ;
84
84
} ) ;
85
85
86
86
$form . submit ( function ( ) {
87
- $form . find ( "input,select" ) . filter ( function ( ) { return ! this . value ; } ) . attr ( "disabled" , "disabled" ) ;
87
+ $form . find ( "input,select" ) . filter ( function ( this : HTMLInputElement ) { return ! this . value ; } ) . attr ( "disabled" , "disabled" ) ;
88
88
$form . addClass ( 'searching' ) ;
89
89
} ) ;
90
90
} ) ;
0 commit comments