1+ lastCountrySelected = "Country" ;
2+ var myInterval = setInterval ( autoChecker , 500 ) ;
3+ console . log ( "ESEA Filter enabled" )
4+
5+ function autoChecker ( ) {
6+ teamList = document . getElementsByClassName ( 'Tr' ) ;
7+ exists = document . getElementById ( 'flag' ) ;
8+ if ( teamList . length > 1 && ( exists === null || exists === undefined ) ) {
9+ doWork ( ) ;
10+ document . getElementById ( "level" ) . onchange = function ( ) {
11+ console . log ( "Switched division" ) ;
12+ myInterval = setInterval ( autoChecker , 500 ) ;
13+ } ;
14+ }
15+ }
16+
17+ function doWork ( ) {
18+ class dropDownFilter {
19+ teamList = document . getElementsByClassName ( 'Tr' ) ;
20+ totalFlags = [ ] ;
21+ flagImages = [ ] ;
22+ flagsCount = 0 ;
23+ flagBox = "" ;
24+
25+ constructor ( ) { } ;
26+ create ( ) {
27+ var regionBox = document . getElementById ( "region" ) . parentElement . parentElement ;
28+ this . flagBox = regionBox . cloneNode ( true ) ;
29+ this . flagBox . childNodes [ 0 ] . childNodes [ 0 ] . setAttribute ( "id" , "flag" ) ;
30+ this . flagBox . style . top = "10px" ;
31+ this . flagBox . style . position = "relative" ;
32+ this . flagBox . childNodes [ 0 ] . childNodes [ 0 ] . innerHTML = "" ;
33+
34+ regionBox . parentElement . parentElement . parentElement . append ( this . flagBox ) ;
35+
36+ this . flagBox = document . getElementById ( "flag" ) ;
37+ }
38+ addDropDownFlag ( flagName ) {
39+ let newOption = document . createElement ( "option" ) ;
40+ newOption . text = flagName ;
41+ this . flagBox . add ( newOption ) ;
42+ }
43+ addFlag ( indexTeam ) {
44+ this . flagOptions = this . flagBox . childNodes [ 0 ] . childNodes [ 0 ] ;
45+
46+ let flagName = this . teamList [ indexTeam ] . childNodes [ 1 ] . childNodes [ 0 ] . childNodes [ 0 ] . title ?? this . teamList [ indexTeam ] . childNodes [ 1 ] . childNodes [ 0 ] . childNodes [ 0 ] . childNodes [ 0 ] . textContent ;
47+ for ( let i = 0 ; i <= this . flagsCount ; i ++ ) {
48+ if ( flagName == this . totalFlags [ i ] ) return ;
49+ }
50+
51+ this . totalFlags [ this . flagsCount ] = flagName ;
52+ this . flagsCount ++ ;
53+ }
54+
55+ fillDropDown ( ) {
56+ for ( let i = 0 ; i < this . totalFlags . length ; i ++ ) {
57+ this . addDropDownFlag ( this . totalFlags [ i ] ) ;
58+ if ( this . totalFlags [ i ] == lastCountrySelected ) this . flagBox . selectedIndex = i + 1 ;
59+ }
60+ lastCountrySelected = this . selectedCountry ( ) ;
61+ }
62+
63+ indexFlags ( ) {
64+ this . addDropDownFlag ( "Country" ) ;
65+
66+ for ( let i = 1 ; i < this . teamList . length ; i ++ ) {
67+ this . addFlag ( i ) ;
68+ }
69+
70+ this . totalFlags = this . totalFlags . sort ( ) ;
71+ this . fillDropDown ( ) ;
72+ }
73+
74+ selectedCountry ( ) {
75+ return document . getElementById ( "flag" ) . value ;
76+ }
77+ } countryBox = new dropDownFilter ;
78+
79+ class eseaHelper {
80+ teamList = document . getElementsByClassName ( 'Tr' ) ;
81+ qeuedTeams = [ ] ;
82+ removedTeams = 0 ;
83+
84+ largeCutOff ( teamsSize ) {
85+ let newCuttOff = 0 ;
86+ switch ( true ) {
87+ case ( teamsSize < 17 ) :
88+ newCuttOff = 8 ;
89+ break ;
90+ case ( teamsSize >= 17 && teamsSize < 24 ) :
91+ newCuttOff = 8 ;
92+ break ;
93+ case ( teamsSize >= 24 && teamsSize < 32 ) :
94+ newCuttOff = 12 ;
95+ break ;
96+ case ( teamsSize >= 32 && teamsSize < 48 ) :
97+ newCuttOff = 16 ;
98+ break ;
99+ case ( teamsSize >= 48 && teamsSize < 64 ) :
100+ newCuttOff = 24 ;
101+ break ;
102+ case ( teamsSize >= 64 && teamsSize < 96 ) :
103+ newCuttOff = 32 ;
104+ break ;
105+ case ( teamsSize >= 96 && teamsSize < 128 ) :
106+ newCuttOff = 48 ;
107+ break ;
108+ case ( teamsSize >= 128 && teamsSize < 192 ) :
109+ newCuttOff = 64 ;
110+ break ;
111+ case ( teamsSize >= 192 && teamsSize < 256 ) :
112+ newCuttOff = 96 ;
113+ break ;
114+ case ( teamsSize >= 256 && teamsSize < 384 ) :
115+ newCuttOff = 128 ;
116+ break ;
117+ case ( teamsSize >= 384 && teamsSize < 512 ) :
118+ newCuttOff = 192 ;
119+ break ;
120+ case ( teamsSize >= 512 && teamsSize < 768 ) :
121+ newCuttOff = 256 ;
122+ break ;
123+ case ( teamsSize >= 768 && teamsSize < 1024 ) :
124+ newCuttOff = 384 ;
125+ break ;
126+ default :
127+ newCuttOff = 4 ;
128+ break ;
129+ }
130+ return newCuttOff ;
131+ }
132+
133+ smallCutOff ( teamsSize ) {
134+ let newCuttOff = 0 ;
135+ switch ( true ) {
136+ case ( teamsSize < 48 ) :
137+ newCuttOff = 8 ;
138+ break ;
139+ case ( teamsSize >= 48 && teamsSize < 64 ) :
140+ newCuttOff = 16 ;
141+ break ;
142+ case ( teamsSize >= 64 && teamsSize < 96 ) :
143+ newCuttOff = 24 ;
144+ break ;
145+ case ( teamsSize >= 96 && teamsSize < 128 ) :
146+ newCuttOff = 32 ;
147+ break ;
148+ case ( teamsSize >= 128 && teamsSize < 192 ) :
149+ newCuttOff = 48 ;
150+ break ;
151+ case ( teamsSize >= 192 && teamsSize < 255 ) :
152+ newCuttOff = 64 ;
153+ break ;
154+ default :
155+ newCuttOff = 4 ;
156+ break ;
157+ }
158+ return newCuttOff ;
159+ }
160+
161+ getDivision ( ) {
162+ return document . getElementById ( "level" ) . value ;
163+ }
164+
165+ getSeasonStage ( ) {
166+ return seasonStage = document . getElementById ( "round" ) . value ;
167+ }
168+
169+ getCutOff ( ) {
170+ let cutOffValue = 0 ;
171+ let teamsSize = this . teamList . length - 1 ;
172+ switch ( esea . getDivision ( ) ) {
173+ case "open" :
174+ cutOffValue = esea . largeCutOff ( teamsSize ) ;
175+ break ;
176+ case "intermediate" :
177+ cutOffValue = esea . largeCutOff ( teamsSize ) ;
178+ break ;
179+ case "main" :
180+ cutOffValue = esea . smallCutOff ( teamsSize ) ;
181+ break ;
182+ case "advanced" :
183+ cutOffValue = esea . smallCutOff ( teamsSize ) ;
184+ break ;
185+ default :
186+ cutOffValue = - 1 ;
187+ break ;
188+ }
189+ return cutOffValue ;
190+ }
191+
192+ printInfo ( ) {
193+ console . log ( "Division: " + this . getDivision ( ) ) ;
194+ let size = this . teamList . length - 1 ;
195+ console . log ( "Teams: " + size ) ;
196+ console . log ( "Cutoff: " + this . getCutOff ( ) ) ;
197+ }
198+
199+ filter ( ) {
200+ let qeuedCount = 0 ;
201+ for ( let i = 1 ; i < this . teamList . length ; i ++ ) {
202+
203+ let currentFlag = this . teamList [ i ] . childNodes [ 1 ] . childNodes [ 0 ] . childNodes [ 0 ] . title ?? this . teamList [ i ] . childNodes [ 1 ] . childNodes [ 0 ] . childNodes [ 0 ] . childNodes [ 0 ] . textContent ;
204+ if ( countryBox . selectedCountry ( ) == "Country" ) {
205+ currentFlag = countryBox . selectedCountry ( ) ;
206+ }
207+ if ( currentFlag != countryBox . selectedCountry ( ) ) {
208+ this . teamList [ i ] . style . display = "none" ;
209+ } else {
210+ this . teamList [ i ] . style . display = "" ;
211+ this . qeuedTeams [ qeuedCount ] = this . teamList [ i ] ;
212+ qeuedCount ++ ;
213+ }
214+ }
215+ for ( let i = 0 ; i < qeuedCount ; i ++ ) {
216+ let targetTeam = this . qeuedTeams [ i ] ;
217+ targetTeam . style . backgroundColor = 'rgb(51, 52, 51)' ;
218+ if ( i % 2 ) targetTeam . style . backgroundColor = 'rgb(68, 68, 68)' ;
219+
220+ let teamRank = targetTeam . childNodes [ 0 ] . textContent . slice ( 0 , targetTeam . childNodes [ 0 ] . textContent . length - 1 ) ;
221+
222+ if ( esea . getCutOff ( ) < 0 || teamRank <= esea . getCutOff ( ) ) {
223+ targetTeam . childNodes [ 0 ] . style . color = "green" ;
224+ } else {
225+ targetTeam . childNodes [ 0 ] . style . color = "red" ;
226+ }
227+ }
228+ }
229+ } esea = new eseaHelper ( ) ;
230+
231+ countryBox . create ( ) ;
232+ countryBox . indexFlags ( ) ;
233+
234+ document . getElementById ( "flag" ) . onchange = function ( ) {
235+
236+ lastCountrySelected = countryBox . selectedCountry ( ) ;
237+ esea . filter ( ) ;
238+ } ;
239+
240+ esea . printInfo ( ) ;
241+ esea . filter ( ) ;
242+ }
0 commit comments