-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
560 lines (496 loc) · 18.7 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Domain Checker by jmitander</title>
<style>
/* Global Styling */
body {
margin: 0;
padding: 0;
background-color: #121212; /* Dark background */
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
color: #e0e0e0; /* Light text for readability */
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
box-sizing: border-box;
}
/* Container Styling */
.domain-checker {
width: 40%;
max-width: 500px;
padding: 30px;
background: rgba(0, 0, 0, 0.85); /* Slightly more opaque */
border-radius: 12px;
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.5);
text-align: center;
position: relative;
transition: all 0.5s ease; /* Smooth transition for resizing */
}
/* Title Styling */
.domain-checker h2 {
margin-bottom: 20px;
font-size: 25px;
color: #ffffff;
}
/* Input Group Styling */
.input-group {
display: flex;
margin-bottom: 30px;
}
/* Input Field Styling */
.domain-checker input[type="text"] {
flex: 1;
padding: 12px 15px;
border: none;
border-radius: 6px 0 0 6px;
font-size: 16px;
outline: none;
background: #1e1e1e;
color: #ffffff;
transition: border 0.3s ease;
}
.domain-checker input[type="text"]:focus {
border: 2px solid #1e88e5;
}
.domain-checker input[type="text"]::placeholder {
color: #b0b0b0;
}
/* TLD Dropdown Styling */
.tld-dropdown {
padding: 12px 15px;
border: none;
border-radius: 0 6px 6px 0;
font-size: 16px;
outline: none;
background: #2c2c2c;
color: #ffffff;
cursor: pointer;
transition: background-color 0.3s ease;
}
.tld-dropdown:hover {
background-color: #3c3c3c;
}
/* Button Styling */
.domain-checker button {
width: 50%;
padding: 12px 15px;
border: none;
border-radius: 6px;
background-color: #1e88e5;
color: white;
font-size: 16px;
cursor: pointer;
transition: background-color 0.3s ease;
margin-top: 5px;
}
.domain-checker button:hover {
background-color: #1565c0;
}
/* Result Icon Styling */
.result {
margin-top: 5px;
font-size: 22px;
display: flex;
align-items: center;
justify-content: center;
min-height: 5px;
}
.result.available {
color: #4caf50; /* Green */
}
.result.taken {
color: #f44336; /* Red */
}
.result.loading {
color: #ff9800; /* Orange */
}
/* Price Estimation Styling */
.price-estimation {
margin-top: 5px;
font-size: 18px;
color: #ffeb3b; /* Yellow */
text-align: left;
background: #1e1e1e;
padding: 10px;
border-radius: 6px;
position: relative;
opacity: 0; /* Initially hidden */
max-height: 0; /* Initially collapsed */
overflow: hidden;
transition: opacity 0.5s ease, max-height 0.5s ease; /* Smooth transition for visibility and size */
}
.price-estimation.visible {
opacity: 1;
max-height: 200px; /* Adjust as needed */
}
.price-estimation strong {
color: #ffffff;
}
/* Progress Bar Styling */
.progress-bar {
width: 100%;
background-color: #1e1e1e;
border-radius: 10px;
overflow: hidden;
margin-top: 30px;
height: 10px;
}
.progress-bar-inner {
height: 100%;
width: 0%;
background-color: #1e88e5;
transition: width 0.3s ease;
}
/* Suggestions Styling */
.suggestions {
margin-top: 10px;
text-align: left;
}
.suggestions h3 {
font-size: 18px;
margin-bottom: 10px;
color: #ffffff;
}
.suggestions ul {
list-style: none;
padding: 0;
margin: 0;
}
.suggestions li {
background: #1e1e1e;
padding: 8px 12px;
margin-bottom: 8px;
border-radius: 6px;
display: flex;
justify-content: space-between;
align-items: center;
transition: background 0.3s ease;
}
.suggestions li:hover {
background: #2c2c2c;
}
/* Tooltip Styling */
.tooltip {
position: relative;
display: inline-block;
}
.tooltip .tooltiptext {
visibility: hidden;
width: 140px;
background-color: #555;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
position: absolute;
z-index: 1;
bottom: 125%; /* Position above the element */
left: 50%;
margin-left: -70px;
opacity: 0;
transition: opacity 0.3s;
}
.tooltip:hover .tooltiptext {
visibility: visible;
opacity: 1;
}
/* Responsive Design */
@media (max-width: 600px) {
.domain-checker {
padding: 20px;
}
.domain-checker h2 {
font-size: 24px;
}
.price-estimation {
font-size: 16px;
}
.suggestions h3 {
font-size: 16px;
}
}
</style>
</head>
<body>
<div class="domain-checker" role="region" aria-labelledby="domain-checker-title">
<h2 id="domain-checker-title">Check Domain Availability</h2>
<div class="input-group">
<input type="text" id="domain-input" placeholder="example" aria-label="Domain name input" />
<select class="tld-dropdown" id="tld-dropdown" aria-label="Select Top-Level Domain">
<option value=".com">.com</option>
<option value=".net">.net</option>
<option value=".org">.org</option>
<option value=".io">.io</option>
<option value=".co">.co</option>
<option value=".ai">.ai</option>
<!-- Add more TLDs as needed -->
</select>
</div>
<button id="check-button" aria-label="Search domain availability">Search</button>
<div class="progress-bar" aria-hidden="true">
<div class="progress-bar-inner" id="progress-bar-inner"></div>
</div>
<div class="result" id="result-icon" aria-live="polite"></div>
<div class="price-estimation" id="price-estimation" aria-live="polite">
<!-- Price details will be injected here -->
</div>
<div class="suggestions" id="suggestions" aria-live="polite">
<!-- Alternative suggestions will appear here -->
</div>
</div>
<!-- Font Awesome for Icons -->
<script src="https://kit.fontawesome.com/a076d05399.js" crossorigin="anonymous"></script>
<!-- Punycode.js Library -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/punycode/2.1.1/punycode.min.js" integrity="sha512-t9w3oVfsPwCLjI4O6Xk+rdJKSM1VInEORCtu1kckz3w6+0tgXruDco/8FftcjXk3/qE/1uIfpXbhdASuPClXbA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script>
// Cache to store recent domain checks
const domainCache = {};
document.getElementById('check-button').addEventListener('click', function() {
const domainInput = document.getElementById('domain-input');
const tldDropdown = document.getElementById('tld-dropdown');
let domainName = domainInput.value.trim().toLowerCase();
const tld = tldDropdown.value;
let domain = domainName + tld;
const resultIcon = document.getElementById('result-icon');
const priceEstimation = document.getElementById('price-estimation');
const progressBar = document.getElementById('progress-bar-inner');
const suggestionsDiv = document.getElementById('suggestions');
// Reset previous results and progress
resultIcon.innerHTML = '';
resultIcon.className = 'result';
priceEstimation.innerHTML = '';
priceEstimation.classList.remove('visible'); // Hide price estimation
suggestionsDiv.innerHTML = '';
progressBar.style.width = '0%';
if (domainName === "") {
resultIcon.innerHTML = '<span>Please enter a domain name.</span>';
resultIcon.classList.add('loading');
return;
}
// Real-time validation
if (!isValidDomainName(domainName)) {
resultIcon.innerHTML = '<span>Invalid domain name format.</span>';
resultIcon.classList.add('loading');
return;
}
// Convert IDN to Punycode if necessary
try {
domain = toPunycode(domain);
} catch (e) {
resultIcon.innerHTML = '<span>Invalid domain name format.</span>';
resultIcon.classList.add('loading');
return;
}
// Check cache first
if (domainCache[domain] !== undefined) {
displayResult(domainCache[domain], resultIcon, priceEstimation, domain, domainName);
return;
}
// Show loading state
resultIcon.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Checking...';
resultIcon.classList.add('loading');
// Update progress bar
progressBar.style.width = '10%';
// Perform DNS query using DNS over HTTPS (DoH) with fallback and additional record types
checkDomainAvailability(domain)
.then(isAvailable => {
// Cache the result
domainCache[domain] = isAvailable;
displayResult(isAvailable, resultIcon, priceEstimation, domain, domainName);
})
.catch(error => {
console.error(error);
resultIcon.innerHTML = '<span>Error checking domain.</span>';
resultIcon.classList.remove('loading');
progressBar.style.width = '100%';
});
});
/**
* Validates the domain name format.
* @param {string} name - The domain name without TLD.
* @returns {boolean} - True if valid, else false.
*/
function isValidDomainName(name) {
// Enhanced regex for domain name validation
const domainPattern = /^(?!-)(?!.*--)[A-Za-z0-9-]{1,63}(?<!-)$/;
return domainPattern.test(name);
}
/**
* Displays the result based on availability and shows price estimation if available.
* @param {boolean} isAvailable - Availability status.
* @param {HTMLElement} resultIcon - The DOM element to display the result.
* @param {HTMLElement} priceEstimation - The DOM element to display the price.
* @param {string} domain - The domain name.
* @param {string} domainName - The name part of the domain.
*/
function displayResult(isAvailable, resultIcon, priceEstimation, domain, domainName) {
const progressBar = document.getElementById('progress-bar-inner');
const suggestionsDiv = document.getElementById('suggestions');
if (isAvailable) {
resultIcon.innerHTML = '<i class="fas fa-check-circle"></i> Available';
resultIcon.className = 'result available';
progressBar.style.width = '100%';
// Simulate a 3-second delay before showing the estimated price
setTimeout(() => {
const estimatedPrice = estimatePrice(domain);
priceEstimation.innerHTML = `Estimated Price: <strong>$${estimatedPrice}</strong>`;
priceEstimation.classList.add('visible'); // Show price estimation
}, 3000); // 3000 milliseconds = 3 seconds
} else {
resultIcon.innerHTML = '<i class="fas fa-times-circle"></i> Taken';
resultIcon.className = 'result taken';
progressBar.style.width = '100%';
// Generate and display alternative suggestions
const alternatives = generateSuggestions(domainName);
if (alternatives.length > 0) {
suggestionsDiv.innerHTML = `<h3>Alternative Suggestions:</h3><ul>${alternatives.map(sugg =>
`<li>${sugg.domain}</li>`).join('')}</ul>`;
}
// Ensure price estimation is hidden if domain is taken
priceEstimation.innerHTML = '';
priceEstimation.classList.remove('visible');
}
}
/**
* Converts a domain to Punycode if it contains non-ASCII characters.
* Utilizes the punycode.js library for accurate conversions.
* @param {string} domain - The domain name to convert.
* @returns {string} - The Punycode-converted domain.
*/
function toPunycode(domain) {
// Check if domain contains non-ASCII characters
if (/[^\x00-\x7F]/.test(domain)) {
return punycode.toASCII(domain);
}
return domain;
}
/**
* Estimates the price of a domain based on its TLD and characteristics.
* @param {string} domain - The domain name.
* @returns {number} - The estimated price in USD.
*/
function estimatePrice(domain) {
const tldPrices = {
'.com': 1000,
'.net': 500,
'.org': 500,
'.io': 700,
'.co': 600,
'.ai': 800,
// Add more TLDs and their base prices as needed
};
// Extract TLD
const tldMatch = domain.match(/\.[a-zA-Z]{2,}$/);
const tld = tldMatch ? tldMatch[0].toLowerCase() : '';
// Base price based on TLD
let price = tldPrices[tld] || 15; // Default base price if TLD not listed
// Domain name length based pricing
const namePart = domain.split('.')[0];
if (namePart.length === 1) {
price += 149000; // Premium for single-letter domains
} else if (namePart.length === 2) {
price += 89500; // Premium for two-letter domains
} else if (namePart.length === 3) {
price += 3500; // Premium for three-letter domains
} else {
// For longer names, price decreases
price += Math.max(10 - (namePart.length - 3) * 1, 1); // $10 for 4 letters, $9 for 5, etc., minimum $1
}
return price;
}
/**
* Generates alternative domain suggestions by appending/prepending common prefixes/suffixes.
* @param {string} baseName - The base name of the domain.
* @returns {Array} - Array of suggestion objects with domain property.
*/
function generateSuggestions(baseName) {
const prefixes = ['get', 'my', 'the', 'go', 'try', 'best'];
const suffixes = ['online', 'site', 'app', 'now', 'hub', 'pro'];
const extensions = ['.com', '.net', '.org'];
const suggestions = [];
prefixes.forEach(prefix => {
extensions.forEach(ext => {
suggestions.push({ domain: prefix + baseName + ext });
});
});
suffixes.forEach(suffix => {
extensions.forEach(ext => {
suggestions.push({ domain: baseName + suffix + ext });
});
});
// Remove duplicates and limit to 5 suggestions
const uniqueSuggestions = [...new Set(suggestions.map(s => s.domain))].slice(0, 5);
return uniqueSuggestions.map(domain => ({ domain }));
}
/**
* Checks domain availability using DNS over HTTPS (DoH) with fallback and multiple DNS record types.
* @param {string} domain - The domain name to check.
* @returns {Promise<boolean>} - Resolves to true if available, false if taken.
*/
async function checkDomainAvailability(domain) {
// Define DoH providers in order of priority
const dohProviders = [
{
name: 'Cloudflare',
baseUrl: 'https://cloudflare-dns.com/dns-query',
headers: {
'Accept': 'application/dns-json'
}
},
{
name: 'Google',
baseUrl: 'https://dns.google/resolve',
headers: {
'Accept': 'application/dns-json'
}
}
];
// Define DNS record types to check
const recordTypes = ['A', 'AAAA', 'MX', 'TXT', 'CNAME', 'NS', 'SOA', 'PTR'];
/**
* Performs a single DNS query.
* @param {Object} provider - The DoH provider details.
* @param {string} type - The DNS record type to query.
* @returns {Promise<boolean|null>} - Returns false if taken, true if no records, null if indeterminate.
*/
const performQuery = async (provider, type) => {
const url = `${provider.baseUrl}?name=${domain}&type=${type}`;
try {
const response = await fetch(url, {
method: 'GET',
headers: provider.headers
});
if (!response.ok) {
throw new Error(`Network response was not ok for provider ${provider.name}, type ${type}`);
}
const data = await response.json();
// If there are Answer records, the domain is likely taken
if (data.Answer && data.Answer.length > 0) {
return false; // Taken
}
return true; // No records for this type
} catch (error) {
console.warn(`Failed to fetch ${type} record from ${provider.name}:`, error);
return null; // Indeterminate
}
};
// Iterate over DoH providers and record types sequentially for early termination
for (let provider of dohProviders) {
for (let type of recordTypes) {
const result = await performQuery(provider, type);
if (result === false) {
// Domain is taken
return false;
}
// If result is null, try the next provider or type
}
}
// After checking all providers and record types, assume available
return true;
}
</script>
</body>
</html>