-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsurah1.html
304 lines (251 loc) · 10.7 KB
/
surah1.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
<!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;
}
</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="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 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>
<button class="image-btn" onclick="generateVerseImage(${i}, '${arabicVerse.replace(/'/g, "\\'")}')">Generate Image</button>
`;
verseDiv.innerHTML = verseContent;
verseDiv.onclick = () => toggleHighlight(i);
content.appendChild(verseDiv);
}
}
function generateVerseImage(verseId, arabicText, englishText = '', urduText = '') {
// Create a canvas for the image
const canvas = document.createElement('canvas');
canvas.width = 512;
canvas.height = 512;
const ctx = canvas.getContext('2d');
// Set black background
ctx.fillStyle = 'black';
ctx.fillRect(0, 0, canvas.width, canvas.height);
// White text settings
ctx.fillStyle = 'white';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
// Ask user what to include in the image
let choice = prompt("What should the image contain?\n1. Arabic only\n2. Arabic & English\n3. Arabic & Urdu");
// Ensure a valid choice is made (default to Arabic only)
if (!["1", "2", "3"].includes(choice)) {
alert("Invalid choice! Defaulting to Arabic only.");
choice = "1";
}
// Initialize text lines
let lines = [];
// Arabic text (always included)
ctx.font = 'bold 38px "Amiri", "Scheherazade New", serif';
lines = splitText(ctx, arabicText, 450);
// English text (if selected)
if (choice === "2" && englishText) {
ctx.font = 'bold 22px "Cairo", sans-serif';
lines = lines.concat(splitText(ctx, englishText, 450));
}
// Urdu text (if selected)
if (choice === "3" && urduText) {
ctx.font = 'bold 22px "Cairo", sans-serif';
lines = lines.concat(splitText(ctx, urduText, 450));
}
// Calculate Y position for centered text
let yPosition = 180 - (lines.length * 20);
lines.forEach((line, index) => {
ctx.fillText(line, canvas.width / 2, yPosition + index * 50);
});
// Convert canvas to image and download
const image = canvas.toDataURL('image/png');
const link = document.createElement('a');
link.href = image;
link.download = `verse_${verseId}.png`;
link.click();
}
// Helper function to split text into multiple lines
function splitText(ctx, text, maxWidth) {
const words = text.split(' ');
let lines = [];
let currentLine = words[0];
for (let i = 1; i < words.length; i++) {
let testLine = currentLine + ' ' + words[i];
let testWidth = ctx.measureText(testLine).width;
if (testWidth > maxWidth) {
lines.push(currentLine);
currentLine = words[i];
} else {
currentLine = testLine;
}
}
lines.push(currentLine);
return lines;
}
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>