-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathalquran.html
327 lines (275 loc) · 11.7 KB
/
alquran.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
<!DOCTYPE html>
<html lang="ar">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Quran Kareem (Ar)</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<link href="https://fonts.googleapis.com/css2?family=Amiri&family=Cairo&family=El+Messiri&family=Harmattan&family=Lateef&family=Scheherazade+New&display=swap" rel="stylesheet">
<link rel="stylesheet" href="main/css/surah.css">
<style>
.share-btn, .view-btn {
display: none;
margin-top: 10px;
}
.selected .share-btn, .selected .view-btn {
display: inline-block;
}
.history-container {
margin-top: 60px; /* Adjust for the settings container's height */
padding: 20px 10px 10px; /* Top padding adjusted for the h3 */
border: 1px solid #ddd;
background: #f9f9f9;
border-radius: 5px;
position: relative; /* Enable absolute positioning for child elements */
z-index: 5; /* Lower z-index than the settings container */
}
.history-container h3 {
margin: 0; /* Remove default margins */
padding: 0px 1px; /* Add some padding */
font-size: 12px; /* Make the text smaller */
font-weight: normal; /* Use normal weight for a subtle appearance */
color: #555; /* Set a muted color */
position: absolute; /* Position it absolutely within the container */
top: 5px; /* Adjust vertical position */
left: 10px; /* Adjust horizontal position */
background: #f9f9f9; /* Match container background for blending */
z-index: 1; /* Ensure it stays above content */
}
.history-list {
display: flex;
gap: 10px; /* Space between items */
overflow-x: auto; /* Enable horizontal scrolling */
padding-bottom: 10px;
scrollbar-width: thin; /* For Firefox */
scrollbar-color: #ccc #f9f9f9; /* For Firefox */
}
.history-list::-webkit-scrollbar {
height: 8px; /* Scrollbar height */
}
.history-list::-webkit-scrollbar-thumb {
background: #ccc; /* Scrollbar thumb color */
border-radius: 5px;
}
.history-list::-webkit-scrollbar-track {
background: #f9f9f9; /* Scrollbar track color */
}
.history-item {
flex: 0 0 auto; /* Prevent shrinking and set width automatically */
border: 1px solid #ccc; /* Border around each item */
border-radius: 5px;
padding: 5px 10px;
text-align: center;
background: #fff;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.history-item a {
text-decoration: none;
color: #007bff;
font-weight: bold;
}
.history-item a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="settings-container">
<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" onclick="navigateToWordToWord()">
<i class="fas fa-brands fa-fire"></i>
</div>
<div class="settings-item" onclick="navigateToRead()">
<i class="fas fa-book-open"></i>
</div>
</div>
<div class="history-container">
<h3>Last Read</h3>
<div id="history-list" class="history-list"></div>
</div>
<div class="header">
<i class="fas fa-arrow-left arrow arrow-left" onclick="navigateSurah(-1)"></i>
<div id="surah-heading" class="surah-heading" style="display: none;"></div>
<i class="fas fa-arrow-right arrow arrow-right" onclick="navigateSurah(1)"></i>
</div>
<div id="first-verse" class="first-verse" style="display: none;"></div>
<div id="content"></div>
<button class="back-to-top" onclick="scrollToTop()">
<i class="fas fa-arrow-up"></i>
</button>
<script>
document.addEventListener('DOMContentLoaded', () => {
const darkMode = localStorage.getItem('darkMode') === 'true';
const textSize = localStorage.getItem('textSize') || '18';
if (darkMode) {
document.body.classList.add('dark-mode');
}
document.body.style.fontSize = textSize + 'px';
const index = getQueryParam('index');
fetchSurah(index ? index : 1);
displayHistory(); // Display the saved history on page load
});
function getQueryParam(param) {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get(param);
}
async function fetchSurah(index) {
const arabicResponse = await fetch(`https://raw.githubusercontent.com/itzfew/Quran-Online/refs/heads/main/source/surah/surah_${String(index).padStart(1, '0')}.json`);
const arabicData = await arabicResponse.json();
const translationResponse = await fetch(`https://raw.githubusercontent.com/itzfew/Quran-Online/refs/heads/main/source/translation/en/en_translation_${String(index).padStart(1, '0')}.json`);
const translationData = await translationResponse.json();
const urduResponse = await fetch(`https://raw.githubusercontent.com/itzfew/Quran-Online/refs/heads/main/source/translation/ur/t_surah_${String(index).padStart(3, '0')}.json`);
const urduData = await urduResponse.json();
displaySurah(arabicData, translationData, urduData);
}
function saveToHistory(index) {
const history = JSON.parse(localStorage.getItem('surahHistory')) || [];
const currentSurah = {
index: index,
link: `surah?index=${index}`,
name: `Surah ${index}` // Placeholder, replace with actual Surah name if available
};
// Remove existing entry if it already exists
const existingIndex = history.findIndex(item => item.index === index);
if (existingIndex !== -1) {
history.splice(existingIndex, 1);
}
history.unshift(currentSurah); // Add the current Surah to the beginning
// Keep only the last 5 entries
if (history.length > 5) {
history.pop();
}
localStorage.setItem('surahHistory', JSON.stringify(history));
}
function displayHistory() {
const history = JSON.parse(localStorage.getItem('surahHistory')) || [];
const historyList = document.getElementById('history-list');
historyList.innerHTML = '';
history.forEach(item => {
const div = document.createElement('div');
div.classList.add('history-item');
div.innerHTML = `<a href="${item.link}">${item.name}</a>`;
historyList.appendChild(div);
});
}
function displaySurah(arabicData, translationData, urduData) {
const surahHeading = document.getElementById('surah-heading');
const firstVerse = document.getElementById('first-verse');
const content = document.getElementById('content');
const count = arabicData.count;
const arabicVerses = arabicData.verse;
const translationVerses = translationData.verse;
const urduVerses = urduData.data;
surahHeading.style.display = 'block';
firstVerse.style.display = 'block';
content.innerHTML = '';
surahHeading.innerText = arabicData.name;
firstVerse.innerText = arabicVerses['verse_0'];
for (let i = 1; i <= count; i++) {
const arabicVerse = arabicVerses[`verse_${i}`];
const translatedVerse = translationVerses[`verse_${i}`];
const urduVerse = urduVerses.find(v => v.aya == i.toString())?.text || '';
const verseDiv = document.createElement('div');
verseDiv.classList.add('verse');
verseDiv.setAttribute('id', `verse-${i}`);
let verseContent = `
<div class="arabic-text">${arabicVerse}
<span class="verse-number">${i}</span>
</div>
<div class="translation-text">${translatedVerse}</div>
<div class="urdu-text">${urduVerse}</div>
<button class="share-btn" onclick="shareVerse(${i})">Share</button>
<button class="view-btn" onclick="viewVerse(${i})">View</button>
`;
verseDiv.innerHTML = verseContent;
verseDiv.onclick = () => toggleHighlight(i);
content.appendChild(verseDiv);
}
}
function toggleHighlight(verseId) {
const allVerses = document.querySelectorAll('.verse');
allVerses.forEach(verse => {
verse.classList.remove('selected');
const shareButton = verse.querySelector('.share-btn');
const viewButton = verse.querySelector('.view-btn');
if (shareButton) shareButton.style.display = 'none';
if (viewButton) viewButton.style.display = 'none';
});
const verseElement = document.getElementById(`verse-${verseId}`);
verseElement.classList.add('selected');
const shareButton = verseElement.querySelector('.share-btn');
const viewButton = verseElement.querySelector('.view-btn');
if (shareButton) shareButton.style.display = 'inline-block';
if (viewButton) viewButton.style.display = 'inline-block';
}
function scrollToTop() {
window.scrollTo({ top: 0, behavior: 'smooth' });
}
function toggleTheme() {
const isDark = document.body.classList.toggle('dark-mode');
localStorage.setItem('darkMode', isDark);
}
function changeTextSize(increment) {
const newSize = parseInt(document.body.style.fontSize) + increment;
document.body.style.fontSize = newSize + 'px';
localStorage.setItem('textSize', newSize);
}
let currentSurahIndex = 1;
function navigateSurah(direction) {
currentSurahIndex += direction;
if (currentSurahIndex < 1) {
currentSurahIndex = 1;
} else if (currentSurahIndex > 114) {
currentSurahIndex = 114;
}
const newUrl = `https://quran-online.pages.dev/surah?index=${currentSurahIndex}`;
window.history.pushState({ path: newUrl }, '', newUrl);
window.location.reload();
}
function shareVerse(verseId) {
const verseText = document.getElementById(`verse-${verseId}`).innerText;
if (navigator.share) {
navigator.share({
title: 'Quran Verse',
text: verseText,
url: window.location.href
}).catch((error) => console.log('Error sharing: ', error));
} else {
navigator.clipboard.writeText(verseText).then(() => {
alert('Verse copied to clipboard!');
}).catch((error) => {
console.log('Error copying to clipboard: ', error);
});
}
}
function viewVerse(verseId) {
const surahIndex = getQueryParam('index') || 1;
window.location.href = `verse.html?surah=${surahIndex}&verse=${verseId}`;
}
function navigateToWordToWord() {
// Get the current Surah index from the query parameter or fallback to the default
const surahIndex = getQueryParam('index') || currentSurahIndex;
// Navigate to the Word-to-Word page with the correct Surah number and append #1
if (surahIndex) {
window.location.href = `wordtoword.html?index=${surahIndex}#1`;
} else {
console.error("Unable to determine Surah index.");
}
}
function navigateToRead() {
const surahIndex = getQueryParam('index') || currentSurahIndex;
const surahNumber = surahIndex.split('/')[0];
const pageNumber = 1;
window.location.href = `read?index=${surahNumber}/${pageNumber}`;
}
</script>
</body>
</html>