Skip to content

Commit 77724b8

Browse files
committed
add check function and reserved domain checker
todo: display
1 parent f7b7dc9 commit 77724b8

File tree

2 files changed

+81
-18
lines changed

2 files changed

+81
-18
lines changed

index.html

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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>

styles/main.css

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,13 @@ input {
126126
width: 100%;
127127
color: var(--body-fg);
128128
font-size: 1.2rem;
129-
padding: 4px;
130-
border-top-right-radius: 0;
131-
border-bottom-right-radius: 0;
132-
border-width: 5px;
133-
border-image: var(--card-border);
134-
background-color: #0f0c19
129+
padding: 8px;
130+
border-width: 1px;
131+
border-radius: 4px;
132+
border: 5px solid #0000;
133+
/* background-color: #0f0c19 */
134+
background: conic-gradient(#0f0c19 0 0) padding-box,linear-gradient(90deg,#1a1331,#4e3aa3) border-box;
135+
135136
}
136137

137138
input:focus {
@@ -145,20 +146,16 @@ input::placeholder {
145146
.search-cntnr {
146147
font-family: "Ubuntu Mono Regular";
147148
display: flex;
148-
flex-direction: row;
149+
flex-direction: column;
149150
justify-content: center;
150151
align-items: stretch;
151152
align-self: center;
152-
padding: 4px
153153
}
154154

155-
.search-btn {
156-
cursor: pointer;
157-
padding-right: 16px;
158-
font-weight: 400;
155+
.search-tip {
159156
font-size: 1rem;
160157
padding-left: 8px;
161-
background-color: var(--hover-bg);
158+
font-style: italic;
162159
align-items: center;
163160
align-content: center;
164161
border-top-right-radius: 8px;
@@ -197,6 +194,13 @@ input::placeholder {
197194
display: none;
198195
}
199196

197+
/* adjust body padding when using mobile devices */
198+
@media (max-width: 480px) {
199+
body{
200+
padding: 0;
201+
}
202+
}
203+
200204
/* Carbon Ads */
201205
#carbonads {
202206
padding-top: 20px;

0 commit comments

Comments
 (0)