<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Domain Acquisition</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
background-color: #fff;
padding: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
border-radius: 8px;
text-align: center;
width: 100%;
max-width: 600px;
}
h1 {
margin-bottom: 20px;
}
input[type="text"] {
width: 80%;
padding: 10px;
margin: 10px 0;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 16px;
}
button {
padding: 10px 20px;
border: none;
background-color: #007BFF;
color: white;
font-size: 16px;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
.result {
margin-top: 20px;
}
.loading {
display: none;
margin-top: 20px;
}
.domain-list {
margin-top: 20px;
}
.domain-list ul {
list-style-type: none;
padding: 0;
}
.domain-list li {
background-color: #f9f9f9;
margin: 10px 0;
padding: 10px;
border-radius: 5px;
border: 1px solid #ddd;
text-align: left;
display: flex;
justify-content: space-between;
}
.price {
color: green;
}
.purchase-link {
text-decoration: none;
background-color: #28a745;
color: white;
padding: 5px 10px;
border-radius: 5px;
}
.error {
color: red;
margin-top: 20px;
}
@media (max-width: 600px) {
input[type="text"] {
width: 100%;
}
}
</style>
</head>
<body>
<div class="container">
<h1>Check Domain Availability</h1>
<form id="domain-form">
<input type="text" id="domain-name" placeholder="Enter domain name" required>
<button type="submit">Search</button>
</form>
<div class="loading" id="loading">
<p>Searching...</p>
<img src="https://i.gifer.com/ZZ5H.gif" alt="Loading" width="50">
</div>
<div class="result" id="result"></div>
<div class="error" id="error"></div>
<div class="domain-list" id="domain-list"></div>
</div>
<script>
const form = document.getElementById('domain-form');
const resultDiv = document.getElementById('result');
const loadingDiv = document.getElementById('loading');
const errorDiv = document.getElementById('error');
const domainListDiv = document.getElementById('domain-list');
form.addEventListener('submit', function (event) {
event.preventDefault();
const domainName = document.getElementById('domain-name').value.trim();
// フィールドをリセット
resultDiv.innerHTML = '';
errorDiv.innerHTML = '';
domainListDiv.innerHTML = '';
loadingDiv.style.display = 'block'; // ローディング表示
if (validateDomainName(domainName)) {
// ダミーデータの使用例(実際にはAPIを呼び出します)
setTimeout(() => {
loadingDiv.style.display = 'none'; // ローディング終了
// 検索結果の仮表示
const available = Math.random() > 0.5; // ランダムに結果を生成
if (available) {
resultDiv.innerHTML = `<strong>${domainName}</strong> is available!`;
// 他のTLDを提案し、価格と購入リンクを表示
const suggestions = [
{ tld: '.com', price: '$10.99', link: 'https://buydomain.com/com' },
{ tld: '.net', price: '$9.99', link: 'https://buydomain.com/net' },
{ tld: '.org', price: '$11.99', link: 'https://buydomain.com/org' },
{ tld: '.info', price: '$8.99', link: 'https://buydomain.com/info' },
{ tld: '.co', price: '$12.99', link: 'https://buydomain.com/co' }
];
let domainList = '<ul>';
suggestions.forEach(({ tld, price, link }) => {
domainList += `<li>${domainName}${tld} <span class="price">${price}</span> <a href="${link}" target="_blank" class="purchase-link">Buy</a></li>`;
});
domainList += '</ul>';
domainListDiv.innerHTML = domainList;
} else {
resultDiv.innerHTML = `<strong>${domainName}</strong> is already taken.`;
}
}, 2000); // 実際のAPIではこのタイミングで結果を取得
} else {
errorDiv.innerHTML = 'Please enter a valid domain name. It should follow the format: example.com';
loadingDiv.style.display = 'none'; // エラー時はローディングを停止
}
});
// ドメイン名のバリデーション関数
function validateDomainName(domain) {
const domainPattern = /^[a-zA-Z0-9-]{1,63}\.[a-zA-Z]{2,}$/;
return domainPattern.test(domain);
}
</script>
</body>
</html>