@@ -62,8 +62,8 @@ <h3>Grab your own sweet-looking <span>.is-a.dev</span> subdomain.</h3>
6262
6363 < h2 > Check SubDomain Availability</ h2 >
6464 < div class ="search-cntnr ">
65- < input id ="search-domain " type ="text " onkeyup =" check() " placeholder ="Check domain name e.g. william ">
66- < div id ="search-btn " class ="search-btn " onclick =" check() ">
65+ < input id ="search-domain " type ="text " placeholder ="Check domain name e.g. william ">
66+ < div id ="search-btn " class ="search-tip ">
6767 Check
6868 </ div >
6969 </ div >
@@ -82,6 +82,7 @@ <h2 id="user-name" style="line-height:1rem">William</h2>
8282 </ div >
8383 < p id ="result-none " class ="hidden "> Nice! The subdomain is still available, < a href ="https://docs.is-a.dev "> read more here</ a > to register the subdomain!</ p >
8484 < p id ="result-error " class ="hidden "> An Error Occurred while checking the subdomain, please try again...</ p >
85+ < p id ="result-reserved " class ="hidden "> Unfortunately, this domain you are searching is reserved by the developer for development purposes...</ p >
8586 </ div >
8687
8788 < h2 > Important Links</ h2 >
@@ -114,10 +115,14 @@ <h2>Donations</h2>
114115 </ main >
115116 < script >
116117 let is_searching = false ;
118+ let timer_search = undefined ;
119+ let reserved_domain = undefined ;
120+ const search_domain = document . getElementById ( 'search-domain' ) ;
117121 // result containers
118122 const result_card = document . getElementById ( 'result-card' ) ;
119123 const result_none = document . getElementById ( 'result-none' ) ;
120124 const result_error = document . getElementById ( 'result-error' ) ;
125+ const result_reserved = document . getElementById ( 'result-reserved' ) ;
121126 // user propagate
122127 const user_avatar = document . getElementById ( 'user-avatar' ) ;
123128 const user_gh_link = document . getElementById ( 'user-gh-link' ) ;
@@ -126,7 +131,12 @@ <h2>Donations</h2>
126131 const user_info = document . getElementById ( 'user-info' ) ;
127132
128133 function check ( ) {
129- var search = document . getElementById ( 'search-domain' ) . value . trim ( ) . replace ( ' ' , '-' ) . toLowerCase ( )
134+ var search = search_domain . value . trim ( ) . replace ( ' ' , '-' ) . toLowerCase ( ) ;
135+ if ( its_reserved ( search ) ) {
136+ hide_results ( ) ;
137+ result_reserved . classList . toggle ( 'hidden' ) ;
138+ return ;
139+ }
130140 if ( search === '' || is_searching ) return ;
131141 is_searching = true ;
132142 fetch ( 'https://raw.githubusercontent.com/is-a-dev/register/main/domains/' + search + '.json' )
@@ -146,11 +156,11 @@ <h2>Donations</h2>
146156 else if ( result_none . classList . contains ( 'hidden' ) )
147157 result_none . classList . toggle ( 'hidden' ) ;
148158 } )
149- . catch ( ( ) => {
159+ . catch ( ( reason ) => {
150160 if ( result_error . classList . contains ( 'hidden' ) ) result_error . classList . toggle ( 'hidden' ) ;
151161 } ) . finally ( ( ) => {
152162 is_searching = false ;
153- } )
163+ } ) ;
154164 }
155165
156166 function propagate_result ( data ) {
@@ -169,7 +179,56 @@ <h2>Donations</h2>
169179 if ( ! result_card . classList . contains ( 'hidden' ) ) result_card . classList . toggle ( 'hidden' ) ;
170180 if ( ! result_none . classList . contains ( 'hidden' ) ) result_none . classList . toggle ( 'hidden' ) ;
171181 if ( ! result_error . classList . contains ( 'hidden' ) ) result_error . classList . toggle ( 'hidden' ) ;
182+ if ( ! result_reserved . classList . contains ( 'hidden' ) ) result_reserved . classList . toggle ( 'hidden' ) ;
183+ }
184+
185+ function its_reserved ( domain ) {
186+ var s = reserved_domain . filter ( function ( pattern ) {
187+ if ( pattern . includes ( '[' ) )
188+ return new RegExp ( pattern ) . test ( domain ) ;
189+ else
190+ return domain === pattern ;
191+ } ) ;
192+ return s . length > 0 ;
193+ }
194+
195+ function fetch_reserve ( ) {
196+ if ( reserved_domain === undefined ) {
197+ if ( timer_search !== undefined )
198+ clearInterval ( timer_search ) ;
199+ fetch ( 'https://raw.githubusercontent.com/is-a-dev/register/main/util/reserved.json' )
200+ . then ( response => {
201+ if ( ! response . ok )
202+ throw new Error ( 'Something went wrong' ) ;
203+ return response . json ( ) ;
204+ } )
205+ . then ( data => {
206+ reserved_domain = data ;
207+ timer_search = setTimeout ( ( ) => check ( this . value ) , 300 ) ;
208+ } )
209+ . catch ( ( reason ) => {
210+
211+ } ) ;
212+ return ;
213+ }
172214 }
215+
216+ search_domain . addEventListener ( 'input' , function ( evt ) {
217+ if ( this . value === '' ) {
218+ if ( timer_search !== undefined ) {
219+ clearInterval ( timer_search ) ;
220+ }
221+ hide_results ( ) ;
222+ return ;
223+ }
224+
225+ if ( timer_search !== undefined )
226+ clearInterval ( timer_search ) ;
227+
228+ timer_search = setTimeout ( ( ) => check ( this . value ) , 300 ) ;
229+ } ) ;
230+
231+ fetch_reserve ( ) ;
173232 </ script >
174233 </ body >
175234</ html >
0 commit comments