-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
72 lines (66 loc) · 3.02 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Daily Hadith</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="min-h-screen flex items-center justify-center bg-cover bg-center" style="background-image: url('bgforhadith.jpeg');">
<div class="max-w-2xl w-full bg-white rounded-lg shadow-md p-8">
<h1 class="text-3xl font-bold text-center mb-6 text-gray-800">Daily Hadith</h1>
<div id="hadith-container" class="mb-6">
<p id="arabic-text" class="text-xl text-right mb-4 text-gray-800 line-clamp-3"></p>
<p id="english-text" class="text-lg mb-4 text-gray-700 line-clamp-3"></p>
<p id="urdu-text" class="text-lg text-right mb-4 text-gray-700 line-clamp-3"></p>
</div>
<button id="regenerate-btn" class="w-full bg-blue-500 text-white py-2 rounded-md hover:bg-blue-600 transition duration-300 mb-4">Regenerate Hadith</button>
<div class="mb-4">
<input type="email" id="email-input" placeholder="Enter your email" class="w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<button id="subscribe-btn" class="w-full bg-green-500 text-white py-2 rounded-md hover:bg-green-600 transition duration-300">Subscribe to Weekly Hadiths</button>
</div>
<script>
const arabicText = document.getElementById('arabic-text');
const englishText = document.getElementById('english-text');
const urduText = document.getElementById('urdu-text');
const regenerateBtn = document.getElementById('regenerate-btn');
const emailInput = document.getElementById('email-input');
const subscribeBtn = document.getElementById('subscribe-btn');
async function fetchHadith() {
try {
const response = await fetch('/.netlify/functions/fetchHadith');
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
// Check if the hadith is short (you can adjust the condition as needed)
if (data.english.length <= 300) {
arabicText.textContent = data.arabic;
englishText.textContent = data.english;
urduText.textContent = 'Urdu translation not available';
} else {
// If the hadith is too long, fetch another one
fetchHadith();
}
} catch (error) {
console.error('Error fetching hadith:', error);
arabicText.textContent = 'Failed to fetch hadith. Please try again.';
englishText.textContent = '';
urduText.textContent = '';
}
}
regenerateBtn.addEventListener('click', fetchHadith);
subscribeBtn.addEventListener('click', () => {
const email = emailInput.value.trim();
if (email) {
alert(`Subscribed with email: ${email}`);
emailInput.value = '';
} else {
alert('Please enter a valid email address.');
}
});
fetchHadith();
</script>
</body>
</html>