-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbook.html
383 lines (328 loc) · 12.6 KB
/
book.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hadith Viewer</title>
<!-- FontAwesome Icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<!-- Google Fonts for Arabic fonts -->
<link href="https://fonts.googleapis.com/css2?family=Amiri&family=Scheherazade+New&family=Cairo&family=Lalezar&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Arial', sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
line-height: 1.6;
transition: background-color 0.3s, color 0.3s, font-size 0.3s;
font-size: 18px; /* Default font size */
}
h1, h2 {
text-align: center;
color: #2c3e50;
margin-top: 20px;
}
.settings-container {
display: flex;
justify-content: flex-start;
align-items: center;
padding: 10px 20px;
background-color: rgba(255, 255, 255, 0.8);
border-bottom: 2px solid #3498db;
position: fixed;
top: 0;
left: 0;
width: 100%;
z-index: 1000;
white-space: nowrap;
overflow-x: auto;
}
.settings-item {
margin-right: 20px;
font-size: 24px;
cursor: pointer;
transition: transform 0.2s ease-in-out;
}
.settings-item:hover {
color: #2980b9;
transform: scale(1.1);
}
.hadith {
margin: 20px;
padding: 10px;
background-color: #fafafa;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
border-radius: 4px;
border: 1px solid transparent; /* Border for visual difference */
cursor: pointer;
transition: border-color 0.3s ease, background-color 0.3s ease;
}
.hadith.selected {
border-color: #3498db; /* Blue border when selected */
background-color: #eaf6fb; /* Light blue background when selected */
}
.hadith:hover {
background-color: #f1f1f1;
}
.hadith h3 {
margin-top: 0;
font-size: 20px;
color: #16a085;
}
.hadith p {
margin: 10px 0;
font-size: 16px;
color: #34495e;
}
.hadith .arabic-text {
font-size: inherit;
text-align: center;
direction: rtl;
transition: font-size 0.3s ease;
}
.hadith .english-text {
font-size: inherit;
font-family: 'Arial', sans-serif;
color: #555;
}
.loading,
.error {
text-align: center;
font-size: 20px;
color: #3498db;
}
.error {
color: red;
}
#hadithResult {
margin-top: 30px;
}
.header-meta {
background-color: #ecf0f1;
padding: 10px;
border-radius: 8px;
margin-bottom: 20px;
}
.header-meta strong {
color: #2c3e50;
}
body.dark-mode {
background-color: #1a1a1a;
color: white;
}
body.dark-mode .hadith {
background-color: #1a1a1a;
border-color: #555;
}
body.dark-mode .hadith.selected {
border-color: #1abc9c; /* Light green border for dark mode */
background-color: #2c3e50; /* Darker background when selected in dark mode */
}
body.dark-mode .hadith:hover {
background-color: #34495e;
}
body.dark-mode .header-meta {
background-color: #1a1a1a;
}
body.dark-mode .arabic-text,
body.dark-mode .english-text {
color: #ecf0f1;
}
@media (max-width: 768px) {
.settings-container {
padding: 10px;
}
.settings-item {
font-size: 20px;
}
}
@media (max-width: 480px) {
.settings-container {
padding: 10px;
}
.settings-item {
font-size: 18px;
margin-right: 10px;
}
}
</style>
</head>
<body>
<!-- Settings Section at the top (Fixed) -->
<div class="settings-container">
<input type="text" id="verseSearch" placeholder="Search for a verse..." onkeyup="searchVerse()" />
<div class="settings-item" onclick="toggleTheme()">
<i class="fas fa-adjust"></i>
</div>
<div class="settings-item" onclick="changeTextSize(1)">
<i class="fas fa-plus"></i>
</div>
<div class="settings-item" onclick="changeTextSize(-1)">
<i class="fas fa-minus"></i>
</div>
<div class="settings-item">
<select id="fontSelect" onchange="changeFont()">
<option value="Amiri">Amiri</option>
<option value="Cairo">Cairo</option>
<option value="Scheherazade New">Scheherazade New</option>
<option value="Lalezar">Lalezar</option>
</select>
</div>
<div class="settings-item" onclick="resetPreferences()">
<i class="fas fa-undo"></i>
</div>
</div>
<div id="loading" class="loading">Loading...</div>
<div id="hadithResult"></div>
<script>
const books = [
{ slug: 'bukhari', name: 'Sahih al-Bukhari' },
{ slug: 'muslim', name: 'Sahih Muslim' },
{ slug: 'tirmidhi', name: 'Jami` at-Tirmidhi' },
{ slug: 'nasa', name: 'Sunan al-Nasa\'i' },
{ slug: 'ibnmajah', name: 'Sunan Ibn Majah' },
{ slug: 'abudawud', name: 'Sunan Abu Dawud' },
{ slug: 'malik', name: 'Muwatta Malik' },
{ slug: 'ahmed', name: 'Musnad Ahmad ibn Hanbal' },
{ slug: 'darimi', name: 'Sunan al-Darimi' }
];
let chaptersData = [];
document.addEventListener('DOMContentLoaded', () => {
const darkMode = localStorage.getItem('darkMode') === 'true';
const textSize = localStorage.getItem('textSize') || '18';
const selectedFont = localStorage.getItem('selectedFont') || 'Amiri';
if (darkMode) {
document.body.classList.add('dark-mode');
}
// Set font size directly on the body
document.body.style.fontSize = textSize + 'px';
document.body.style.fontFamily = selectedFont;
document.getElementById('fontSelect').value = selectedFont;
const { bookSlug, bookNumber } = getURLParams();
if (bookSlug && bookNumber) {
fetchChaptersData(bookSlug);
} else {
document.getElementById('loading').style.display = 'none';
document.getElementById('hadithResult').innerHTML = '<p class="error">Please specify both the book and book number in the URL (e.g., ?book=bukhari&bookNumber=1).</p>';
}
});
function toggleTheme() {
const isDark = document.body.classList.toggle('dark-mode');
localStorage.setItem('darkMode', isDark);
}
function changeTextSize(increment) {
const currentSize = parseInt(window.getComputedStyle(document.body).fontSize);
const newSize = currentSize + increment;
document.body.style.fontSize = newSize + 'px';
localStorage.setItem('textSize', newSize);
}
function changeFont() {
const selectedFont = document.getElementById('fontSelect').value;
document.body.style.fontFamily = selectedFont;
localStorage.setItem('selectedFont', selectedFont);
}
function resetPreferences() {
localStorage.removeItem('darkMode');
localStorage.removeItem('textSize');
localStorage.removeItem('selectedFont');
location.reload();
}
// Function to retrieve the book and bookNumber parameters from the URL
function getURLParams() {
const urlParams = new URLSearchParams(window.location.search);
const bookSlug = urlParams.get('book'); // Get the 'book' parameter
const bookNumber = urlParams.get('bookNumber'); // Get the 'bookNumber' parameter
return { bookSlug, bookNumber };
}
// Function to fetch chapter data for the book
function fetchChaptersData(bookSlug) {
const chaptersUrl = `https://raw.githubusercontent.com/itzfew/Quran-Online/refs/heads/main/source/hadiths/${bookSlug}/books.json`;
fetch(chaptersUrl)
.then(response => response.json())
.then(data => {
chaptersData = data.collection.books;
initializeViewer(bookSlug);
})
.catch(error => {
console.error('Error fetching chapters data:', error);
document.getElementById('hadithResult').innerHTML = '<p class="error">Failed to load chapters data for this book. Please try again later.</p>';
document.getElementById('loading').style.display = 'none';
});
}
// Function to fetch the Hadiths for the given book and book number
function fetchHadiths(bookSlug, bookNumber) {
const url = `https://raw.githubusercontent.com/itzfew/Quran-Online/refs/heads/main/source/hadiths/${bookSlug}/${bookNumber}.json`;
fetch(url)
.then(response => response.json())
.then(data => {
displayHadiths(data, bookSlug);
})
.catch(error => {
console.error('Error fetching data:', error);
document.getElementById('hadithResult').innerHTML = '<p class="error">Failed to load Hadiths for this book. Please try again later.</p>';
document.getElementById('loading').style.display = 'none';
});
}
// Function to display the Hadiths on the page
function displayHadiths(data, bookSlug) {
const hadithResult = document.getElementById('hadithResult');
const loading = document.getElementById('loading');
loading.style.display = 'none';
const bookName = books.find(b => b.slug === bookSlug)?.name || 'Unknown Book';
if (data.hadiths && data.hadiths.length > 0) {
let htmlContent = `
<div class="header-meta">
<h2>${bookName} <span style="font-size: 18px;">(Book Number: ${data.metadata.english.introduction})</span></h2>
<p><strong>Author:</strong> ${data.metadata.english.author}</p>
<p><strong>Introduction:</strong> ${data.metadata.english.introduction}</p>
</div>
`;
data.hadiths.forEach(hadith => {
htmlContent += `
<div class="hadith" onclick="selectHadith(event)">
<h3>Hadith #${hadith.id}</h3>
<p class="arabic-text"><strong>Arabic:</strong> ${hadith.arabic}</p>
<p class="english-text"><strong>English:</strong> ${hadith.english.text}</p>
</div>
`;
});
hadithResult.innerHTML = htmlContent;
} else {
hadithResult.innerHTML = '<p>No Hadiths found for this book number.</p>';
}
}
// Function to highlight the selected Hadith
function selectHadith(event) {
const allHadiths = document.querySelectorAll('.hadith');
allHadiths.forEach(hadith => hadith.classList.remove('selected'));
const selectedHadith = event.currentTarget;
selectedHadith.classList.add('selected');
}
// Function to initialize the viewer and fetch Hadith data
function initializeViewer(bookSlug) {
const { bookNumber } = getURLParams();
if (bookSlug && bookNumber) {
fetchHadiths(bookSlug, bookNumber);
} else {
document.getElementById('loading').style.display = 'none';
document.getElementById('hadithResult').innerHTML = '<p class="error">Please specify both the book and book number in the URL (e.g., ?book=bukhari&bookNumber=1).</p>';
}
}
// Search function to filter verses based on user input
function searchVerse() {
const searchQuery = document.getElementById('verseSearch').value.toLowerCase();
const allHadiths = document.querySelectorAll('.hadith');
allHadiths.forEach(hadith => {
const englishText = hadith.querySelector('.english-text').textContent.toLowerCase();
const arabicText = hadith.querySelector('.arabic-text').textContent.toLowerCase();
if (englishText.includes(searchQuery) || arabicText.includes(searchQuery)) {
hadith.style.display = 'block';
} else {
hadith.style.display = 'none';
}
});
}
</script>
</body>
</html>