Skip to content

Commit f31e976

Browse files
committed
add propagation of data
TODO: design the card then slap to PR and boast it in Discord... weheheheh..wahahahaha.. *cough, cough*...
1 parent c395b85 commit f31e976

File tree

2 files changed

+71
-26
lines changed

2 files changed

+71
-26
lines changed

index.html

Lines changed: 67 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -62,27 +62,26 @@ <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="subdomain" type="text" placeholder="Check domain name e.g. william">
66-
<div 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-btn" onclick="check()">
6767
Check
6868
</div>
6969
</div>
7070
<div class="search-result-cntnr">
71-
<div hidden id="bg-card" style="width:100%;margin:4-x;padding:8px">
72-
<div style="border-radius;display:flex; align-items:center;justify-content:start;gap:1rem;width:100%">
73-
<img id="avatar" alt="user-avatar" src="http://github.com/STICKnoLOGIC.png?size=64">
74-
<div style="display:flex;flex-direction:column;width:100%">
75-
<a id="user-gh-link" href="htttps://facebook.com">
76-
<h2 id="user-name" style="line-height:1rem">AERIAL</h2>
77-
</a>
78-
<a id="user-website-name" href="https://google/com" style="line-height:0 ;margin:0">
79-
<span id="user-website-link" style="font-size:1.2rem">sticknologic.is-a.dev</span>
80-
</a>
81-
</div>
82-
</div>
83-
<p id="user-info">STICK NOLOGIC</p>
84-
</div>
85-
<p>Perfect! The subdomain is not yet available, <a href="https://docs.is-a.dev">read more here</a> to register this subdomain!</p>
71+
<div id="result-card" class="hiddens" style="width:100%;margin:4-x;padding:8px">
72+
<div style="display:flex; align-items:center;justify-content:start;gap:1rem;width:100%">
73+
<img id="user-avatar" alt="user-avatar" src="http://github.com/wdhdev.png?size=64">
74+
<div style="display:flex;flex-direction:column;width:100%">
75+
<a id="user-gh-link" href="htttps://github.com/wdhdev">
76+
<h2 id="user-name" style="line-height:1rem">William</h2>
77+
</a>
78+
<a id="user-website-link" href="https://william.is-a.dev" style="margin-top:-1.5rem;font-size:1.2rem">william.is-a.dev</a>
79+
</div>
80+
</div>
81+
<p id="user-info">Simple Website</p>
82+
</div>
83+
<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>
84+
<p id="result-error" class="hidden">An Error Occurred while checking the subdomain, please try again...</p>
8685
</div>
8786

8887
<h2>Important Links</h2>
@@ -114,22 +113,64 @@ <h2>Donations</h2>
114113
</p>
115114
</main>
116115
<script>
116+
let is_searching=false;
117+
// result containers
118+
const result_card=document.getElementById('result-card');
119+
const result_none=document.getElementById('result-none');
120+
const result_error=document.getElementById('result-error');
121+
// user propagate
122+
const user_avatar=document.getElementById('user-avatar');
123+
const user_gh_link=document.getElementById('user-gh-link');
124+
const user_name=document.getElementById('user-name');
125+
const user_website_link=document.getElementById('user-website-link');
126+
const user_info=document.getElementById('user-info');
127+
117128
function check(){
118-
fetch('https://raw.githubusercontent.com/is-a-dev/register/main/domains/'+document.getElementById('subdomain').value.trim().replace(' ','-').toLowerCase()+'.json')
129+
var search=document.getElementById('search-domain').value.trim().replace(' ','-').toLowerCase()
130+
if(search ==='' || is_searching) return;
131+
is_searching=true;
132+
fetch('https://raw.githubusercontent.com/is-a-dev/register/main/domains/'+search+'.json')
119133
.then(response => {
120-
if (!response.ok) {
121-
throw new Error("HTTP error " + response.status);
122-
}
123-
return response.json();
134+
hide_results();
135+
if(!response.ok && response.status !== 404)
136+
throw new Error('Something went wrong');
137+
return !response.ok? null :
138+
response.json();
124139
})
125140
.then(json => {
126-
// this.users = json;
127-
console.log(json);
141+
if(json!=null)
142+
{
143+
json.search=search;
144+
propagate_result(json);
145+
}
146+
else if (result_none.classList.contains('hidden'))
147+
result_none.classList.toggle('hidden');
128148
})
129-
.catch(function () {
130-
this.dataError = true;
149+
.catch(()=>{
150+
print(1111);
151+
if (result_error.classList.contains('hidden')) result_error.classList.toggle('hidden');
152+
}).finally(()=>{
153+
is_searching=false;
131154
})
132155
}
156+
157+
function propagate_result(data){
158+
if (result_card.classList.contains('hidden')) result_card.classList.toggle('hidden');
159+
var gh_link='https://github.com/'+data.owner.username;
160+
var website_link=data.search+'.is-a.dev';
161+
user_avatar.src=gh_link+'.png?size=64';
162+
user_gh_link.href=gh_link;
163+
user_name.innerHTML=data.owner.username;
164+
user_website_link.href='https://'+website_link;
165+
user_website_link.innerHTML=website_link;
166+
user_info.textContent=data.description===undefined?'':data.description;
167+
}
168+
169+
function hide_results(){
170+
if (!result_card.classList.contains('hidden')) result_card.classList.toggle('hidden');
171+
if (!result_none.classList.contains('hidden')) result_none.classList.toggle('hidden');
172+
if (!result_error.classList.contains('hidden')) result_error.classList.toggle('hidden');
173+
}
133174
</script>
134175
</body>
135176
</html>

styles/main.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ input::placeholder{
157157
user-select: none;
158158
}
159159

160+
.hidden{
161+
display: none;
162+
}
163+
160164
/* Carbon Ads */
161165
#carbonads {
162166
padding-top: 20px;

0 commit comments

Comments
 (0)