@@ -28,7 +28,7 @@ document.addEventListener("DOMContentLoaded", function () {
28
28
document . getElementById ( "styled-checkbox-1" ) . checked = true ;
29
29
}
30
30
if ( new URLSearchParams ( window . location . search ) . get ( "medal" ) == null ) landingPage ( ) ;
31
- requestMedals ( true , "" ) ;
31
+ requestMedals ( true ) ;
32
32
} ) ;
33
33
34
34
window . addEventListener ( 'popstate' , function ( event ) {
@@ -151,26 +151,63 @@ async function initColMedals() {
151
151
} ) ;
152
152
}
153
153
154
- async function requestMedals ( init , strValue ) {
154
+ async function requestMedals ( init , strValue = '' ) {
155
155
if ( init || Object . values ( colMedals ) . length == 0 ) // Init the colMedals object
156
156
await initColMedals ( ) ;
157
157
158
+ let query = strValue . trim ( ) ;
159
+ while ( query . includes ( ' ' ) ) {
160
+ query = query . replace ( ' ' , ' ' ) ;
161
+ query = query . trim ( ) ;
162
+ }
163
+
158
164
let filteredMedalsArrayByGroup = [ ] ;
159
165
for ( let v of Object . values ( colMedals ) ) {
160
- let doModsMatch = false ;
161
- for ( const word of strValue . split ( ' ' ) ) {
162
- if ( v . Mods == '' || v . Mods == null ) break ;
163
- doModsMatch = v . Mods . replace ( ',' , '' ) . toUpperCase ( ) . includes ( word . toUpperCase ( ) ) ;
164
- if ( doModsMatch ) break ;
166
+ let medalMatches = false ;
167
+ if ( query == '' ) {
168
+ medalMatches = true ;
169
+ } else {
170
+ let wordMatches = [ ] ;
171
+ for ( const word of query . split ( ' ' ) ) {
172
+ thisWordMatches = false ;
173
+ if ( v . Mods == null ) v . Mods = '' ;
174
+ thisWordMatches = v . Mods . replace ( ',' , '' ) . toUpperCase ( ) . includes ( word . toUpperCase ( ) ) ;
175
+ if ( thisWordMatches ) {
176
+ wordMatches . push ( true ) ;
177
+ continue ;
178
+ }
179
+
180
+ thisWordMatches = v . Name . toLowerCase ( ) . includes ( word . toLowerCase ( ) ) ;
181
+ if ( thisWordMatches ) {
182
+ wordMatches . push ( true ) ;
183
+ continue ;
184
+ }
185
+ thisWordMatches = v . Solution ?. toLowerCase ( ) . includes ( word . toLowerCase ( ) ) ;
186
+ if ( thisWordMatches ) {
187
+ wordMatches . push ( true ) ;
188
+ continue ;
189
+ }
190
+ thisWordMatches = v . Description ?. toLowerCase ( ) . includes ( word . toLowerCase ( ) ) ;
191
+ if ( thisWordMatches ) {
192
+ wordMatches . push ( true ) ;
193
+ continue ;
194
+ }
195
+ thisWordMatches = v . Instructions ?. toLowerCase ( ) . includes ( word . toLowerCase ( ) ) ;
196
+ if ( thisWordMatches ) {
197
+ wordMatches . push ( true ) ;
198
+ continue ;
199
+ }
200
+ thisWordMatches = v . MedalID == parseInt ( word ) ;
201
+ if ( thisWordMatches ) {
202
+ wordMatches . push ( true ) ;
203
+ continue ;
204
+ }
205
+ wordMatches . push ( false ) ;
206
+ }
207
+ medalMatches = ! wordMatches . includes ( false ) ;
165
208
}
166
209
167
- // Match Name, Solution, Description, Instructions and medal id
168
- if ( v . Name . toLowerCase ( ) . includes ( strValue . toLowerCase ( ) ) ||
169
- v . Solution ?. toLowerCase ( ) . includes ( strValue . toLowerCase ( ) ) ||
170
- v . Description ?. toLowerCase ( ) . includes ( strValue . toLowerCase ( ) ) ||
171
- v . Instructions ?. toLowerCase ( ) . includes ( strValue . toLowerCase ( ) ) ||
172
- doModsMatch ||
173
- v . MedalID == parseInt ( strValue ) ) {
210
+ if ( medalMatches ) {
174
211
if ( filteredMedalsArrayByGroup [ v . Grouping ] == null ) filteredMedalsArrayByGroup [ v . Grouping ] = [ ] ;
175
212
filteredMedalsArrayByGroup [ v . Grouping ] . push ( v ) ;
176
213
}
0 commit comments