-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathread.html
366 lines (313 loc) · 11.8 KB
/
read.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Quran Surah Viewer</title>
<link href="https://fonts.googleapis.com/css2?family=Scheherazade&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
background-color: #fff;
overflow-y: auto; /* Allow body to scroll when content overflows */
height: 100vh; /* Ensure full page height */
box-sizing: border-box; /* Include padding in height calculations */
}
h1, h2 {
text-align: center;
color: #111;
font-family: 'Scheherazade', serif;
margin-bottom: 20px;
font-weight: normal;
}
.navigation {
position: fixed;
top: 20px;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
z-index: 100;
}
.button {
padding: 10px;
font-size: 20px;
background-color: transparent;
color: #111;
border: none;
cursor: pointer;
font-weight: normal;
}
.button:disabled {
color: #ccc;
cursor: not-allowed;
}
.button i {
font-size: 25px;
}
.back-button-left,
.back-button-right {
position: fixed;
top: 10px;
font-size: 20px;
color: #2980b9;
background: transparent;
border: none;
cursor: pointer;
z-index: 101;
}
.back-button-left {
left: 10px;
}
.back-button-right {
right: 10px;
}
/* Fixed position for Next and Previous buttons at the bottom */
.next-button {
position: fixed;
bottom: 20px;
left: 20px;
margin-left: 20px;
}
.prev-button {
position: fixed;
bottom: 20px;
right: 20px;
margin-right: 20px;
}
.verses {
line-height: 1.8;
text-align: right;
font-size: 35px;
color: #111;
overflow-y: auto; /* Allow body to scroll when content overflows */
font-family: 'Scheherazade', serif;
margin-top: 60px;
font-weight: normal;
}
.verse-number {
font-size: 1.2em;
font-weight: normal;
margin-left: 10px;
color: #111;
}
.verse-heading {
font-size: 1.8em;
font-weight: normal;
margin-bottom: 15px;
text-align: center;
color: #2980b9;
}
.page-number {
font-size: 1.2em;
text-align: center;
font-weight: normal;
color: #2980b9;
margin-top: 20px;
position: fixed;
bottom: 1px;
width: 100%;
}
.surah-details {
font-size: 1.2em;
text-align: center;
margin-top: 20px;
color: #111;
font-weight: normal;
}
.surah-details strong {
color: #2980b9;
}
@media (max-width: 768px) {
.verses {
font-size: 28px;
}
.verse-heading {
font-size: 1.5em;
}
h2 {
font-size: 1.4em;
}
.button {
font-size: 18px;
padding: 8px;
}
}
@media (max-width: 480px) {
.verses {
font-size: 24px;
}
.verse-heading {
font-size: 1.3em;
}
h2 {
font-size: 1.2em;
}
.button {
font-size: 16px;
padding: 6px;
}
}
</style>
</head>
<body>
<button id="back-button-left" class="back-button-left"><i class="fas fa-arrow-left"></i> Back</button>
<button id="back-button-right" class="back-button-right"><i class="fas fa-home"></i> Home</button>
<div class="navigation">
<h2 id="surah-name">Loading...</h2>
</div>
<div id="verses" class="verses">Please wait...</div>
<div id="page-number" class="page-number">Page 1</div>
<!-- Position buttons fixed at the bottom -->
<button id="prev-button" class="button prev-button" disabled><i class="fas fa-chevron-right"></i></button>
<button id="next-button" class="button next-button"><i class="fas fa-chevron-left"></i></button>
<script>
const surahBaseURL = "https://raw.githubusercontent.com/itzfew/Quran-Online/refs/heads/main/source/surah/surah_";
const surahDetailsURL = "https://raw.githubusercontent.com/itzfew/Quran-Online/refs/heads/main/source/surah.json";
let currentSurah = 1;
let currentPage = 1;
let surahDetails = [];
const surahNameEl = document.getElementById("surah-name");
const versesEl = document.getElementById("verses");
const prevButton = document.getElementById("prev-button");
const nextButton = document.getElementById("next-button");
const pageNumberEl = document.getElementById("page-number");
const backButtonLeft = document.getElementById("back-button-left");
const backButtonRight = document.getElementById("back-button-right");
// Convert numbers to Arabic numerals
function convertToArabicNumerals(number) {
const arabicNumerals = ['٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩'];
return number.toString().split('').map(digit => arabicNumerals[parseInt(digit)]).join('');
}
// Fetch surah details
const fetchSurahDetails = async () => {
try {
const response = await fetch(surahDetailsURL);
if (!response.ok) {
throw new Error("Failed to fetch Surah details.");
}
surahDetails = await response.json();
displaySurahInfo(currentSurah);
fetchSurah(currentSurah);
} catch (error) {
console.error(error);
}
};
// Display Surah information like title, verses count, etc.
const displaySurahInfo = (surahIndex) => {
const surah = surahDetails.find(item => item.index === surahIndex.toString().padStart(3, '0'));
if (surah) {
surahNameEl.textContent = `${surah.title}`;
return surah.count;
} else {
surahNameEl.textContent = "Surah details not found.";
return 0;
}
};
// Fetch Surah verses
const fetchSurah = async (surahNumber) => {
try {
const response = await fetch(`${surahBaseURL}${surahNumber}.json`);
if (!response.ok) {
throw new Error("Failed to fetch Surah.");
}
const surahData = await response.json();
displaySurah(surahData);
} catch (error) {
surahNameEl.textContent = "Error loading Surah";
versesEl.textContent = error.message;
}
};
// Display Surah verses on the page
const displaySurah = (data) => {
const verseCount = displaySurahInfo(currentSurah);
const versesPerPage = 6;
const totalPages = Math.ceil(verseCount / versesPerPage);
const startIndex = (currentPage - 1) * versesPerPage;
const endIndex = Math.min(startIndex + versesPerPage, verseCount);
let versesHTML = "";
let verseCounter = startIndex + 1;
Object.entries(data.verse).slice(startIndex, endIndex).forEach(([key, verse]) => {
if (key === "verse_0") {
versesHTML += `<div class="verse-heading">${verse}</div>`;
} else {
const arabicVerseNumber = convertToArabicNumerals(verseCounter);
versesHTML += `${verse} <span class="verse-number">(${arabicVerseNumber})</span>`;
verseCounter++;
}
});
versesEl.innerHTML = versesHTML;
pageNumberEl.textContent = `Page ${currentPage}`;
prevButton.disabled = currentPage === 1;
nextButton.disabled = currentPage === totalPages;
};
// Update Surah and Page from the URL
const getSurahFromURL = () => {
const urlParams = new URLSearchParams(window.location.search);
const surahIndex = urlParams.get('index');
if (surahIndex) {
const [surah, page] = surahIndex.split('/');
currentSurah = parseInt(surah);
currentPage = parseInt(page);
}
fetchSurahDetails(); // Fetch Surah details when loading
};
// Event listeners for navigation buttons
prevButton.addEventListener("click", () => {
if (currentPage > 1) {
currentPage--;
updateURLAndFetch();
}
});
nextButton.addEventListener("click", () => {
const verseCount = displaySurahInfo(currentSurah);
const totalPages = Math.ceil(verseCount / 6);
if (currentPage < totalPages) {
currentPage++;
updateURLAndFetch();
}
});
// Update the URL and fetch the new Surah
const updateURLAndFetch = () => {
const newURL = new URL(window.location);
newURL.searchParams.set('index', `${currentSurah}/${currentPage}`);
window.history.pushState({}, '', newURL);
fetchSurah(currentSurah);
};
// Back button event listeners
backButtonLeft.addEventListener("click", () => {
const surahIndex = currentSurah; // Keep the current Surah
const newURL = new URL(window.location);
newURL.pathname = '/surah'; // Change path to `/surah`
newURL.searchParams.set('index', `${surahIndex}`); // Set the Surah index without the page parameter
window.location.href = newURL.toString(); // Redirect to the new URL
});
backButtonRight.addEventListener("click", () => {
window.location.href = "index.html"; // Redirect to home page
});
// Swipe detection (touch event listeners)
let touchStartX = 0; // For detecting touch start position
let touchEndX = 0; // For detecting touch end position
// Touch start event listener
document.addEventListener('touchstart', (e) => {
touchStartX = e.changedTouches[0].screenX; // Save the initial touch position
});
// Touch end event listener
document.addEventListener('touchend', (e) => {
touchEndX = e.changedTouches[0].screenX; // Get the final touch position
// Check if the touch is a swipe right (previous page) or swipe left (next page)
if (touchStartX - touchEndX > 100) {
// Swiped left, next page
prevButton.click(); // Trigger the next button click
} else if (touchEndX - touchStartX > 100) {
// Swiped right, previous page
nextButton.click(); // Trigger the previous button click
}
});
getSurahFromURL(); // Initialize and load the Surah when the page is loaded
</script>
</body>
</html>