-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwordtoword.html
236 lines (196 loc) · 9.52 KB
/
wordtoword.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
<!DOCTYPE html>
<html lang="en" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Quran Viewer</title>
<link href="https://fonts.googleapis.com/css2?family=Amiri+Quran&display=swap" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" rel="stylesheet">
<!-- External CSS file -->
<link rel="stylesheet" href="style/style.css">
<style>
/* You can add additional custom styles here if needed */
</style>
</head>
<body>
<div id="bookmarked-verses">
<ul id="bookmark-list"></ul>
</div>
<h1 id="surah-name">Loading...</h1>
<div id="controls">
<i id="next-surah" class="fas fa-arrow-right nav-button">Next</i>
<span id="current-surah"></span>
<i id="previous-surah" class="fas fa-arrow-left nav-button">Previous</i>
</div>
<div id="quran">
<!-- Quranic verses will be dynamically displayed here -->
</div>
<script>
const metadataUrl = 'https://raw.githubusercontent.com/itzfew/Quran-Online/refs/heads/main/source/words/word.json';
const wordsUrl = 'https://raw.githubusercontent.com/itzfew/Quran-Online/refs/heads/main/source/words/nastaliq-quranwbw.json';
const englishTranslationsUrl = 'https://raw.githubusercontent.com/itzfew/Quran-Online/refs/heads/main/source/words/en-quranwbw.json';
const urduTranslationsUrl = 'https://raw.githubusercontent.com/itzfew/Quran-Online/refs/heads/main/source/words/ur-quranwbw.json';
async function fetchData(url) {
try {
const response = await fetch(url);
if (!response.ok) throw new Error(`Failed to fetch: ${url}`);
return response.json();
} catch (error) {
console.error(error);
alert(`Error loading data: ${error.message}`);
}
}
async function renderSurah(surahNumber, ayahNumber = null) {
const metadata = await fetchData(metadataUrl);
const words = await fetchData(wordsUrl);
const englishTranslations = await fetchData(englishTranslationsUrl);
const urduTranslations = await fetchData(urduTranslationsUrl);
// Fetch full English translations for the surah
const fullTranslationUrl = `https://raw.githubusercontent.com/itzfew/Quran-Online/refs/heads/main/source/translation/en/en_translation_${surahNumber}.json`;
const fullTranslation = await fetchData(fullTranslationUrl);
if (!metadata || !words || !englishTranslations || !urduTranslations || !fullTranslation) return;
const quranContainer = document.getElementById('quran');
quranContainer.innerHTML = '';
const surahName = fullTranslation.name || `Surah ${surahNumber}`;
const surahTitle = `${surahName} (Surah ${surahNumber})`;
document.getElementById('surah-name').textContent = surahTitle;
document.getElementById('current-surah').textContent = surahTitle;
const surahData = {};
for (const [wordId, meta] of Object.entries(metadata)) {
if (meta.surah === surahNumber && meta.ayah > 0) {
if (!surahData[meta.ayah]) surahData[meta.ayah] = [];
surahData[meta.ayah].push({
word: words[wordId],
englishTranslation: englishTranslations[wordId],
urduTranslation: urduTranslations[wordId]
});
}
}
const isSurah1 = surahNumber === 1;
const ayahCount = isSurah1 ? 7 : fullTranslation.count; // Limit Surah 1 to 7 ayahs
// Iterate over ayahs
for (let ayah = 1; ayah <= ayahCount; ayah++) {
const ayahDiv = document.createElement('div');
ayahDiv.className = 'ayah';
ayahDiv.id = `${surahNumber}#${ayah}`;
const ayahHeader = document.createElement('div');
ayahHeader.className = 'ayah-header';
ayahHeader.textContent = `Verse ${ayah}`;
ayahDiv.appendChild(ayahHeader);
if (surahData[ayah]) {
surahData[ayah].forEach(wordData => {
const wordSpan = document.createElement('span');
wordSpan.className = 'word';
wordSpan.innerHTML = `
<span>${wordData.word}</span>
<span class="translation">${wordData.englishTranslation}</span>
<span class="translation urdu">${wordData.urduTranslation}</span>
`;
ayahDiv.appendChild(wordSpan);
});
}
// Map verse numbers for Surah 1
const verseIndex = isSurah1 ? ayah - 1 : ayah; // Subtract 1 for Surah 1 (0-based indexing)
const verseKey = `verse_${verseIndex}`;
// Add full English translation for the verse
const fullTranslationDiv = document.createElement('div');
fullTranslationDiv.className = 'full-translation';
fullTranslationDiv.textContent = fullTranslation.verse[verseKey] || 'Translation not available';
ayahDiv.appendChild(fullTranslationDiv);
// Buttons for Bookmark, Share, and Tafsir
const buttonsDiv = document.createElement('div');
buttonsDiv.className = 'ayah-buttons';
buttonsDiv.innerHTML = `
<button class="bookmark-button" onclick="bookmarkAyah(${surahNumber}, ${ayah})"><i class="fas fa-bookmark"></i> Bookmark</button>
<button class="share-button" onclick="shareAyah(${surahNumber}, ${ayah})"><i class="fas fa-share"></i> Share</button>
<button class="tafsir-button" onclick="openTafsir(${surahNumber}, ${ayah})"><i class="fas fa-book-open"></i> Tafsir</button>
`;
ayahDiv.appendChild(buttonsDiv);
quranContainer.appendChild(ayahDiv);
}
if (ayahNumber) {
const ayahDiv = document.getElementById(`${surahNumber}#${ayahNumber}`);
if (ayahDiv) ayahDiv.scrollIntoView({ behavior: 'smooth' });
highlightVerse(surahNumber, ayahNumber);
}
updateUrl(surahNumber, ayahNumber || 1);
}
function updateUrl(surah, ayah) {
const newUrl = `${window.location.origin}${window.location.pathname}?index=${surah}#${ayah}`;
window.history.pushState({}, '', newUrl);
}
function highlightVerse(surah, ayah) {
const verseElement = document.getElementById(`${surah}#${ayah}`);
if (verseElement) {
verseElement.classList.add('highlight');
setTimeout(() => {
verseElement.classList.remove('highlight');
}, 3000); // Remove highlight after 3 seconds
}
}
function bookmarkAyah(surah, ayah) {
const bookmarks = JSON.parse(localStorage.getItem('bookmarks')) || [];
bookmarks.unshift({ surah, ayah });
if (bookmarks.length > 7) bookmarks.pop(); // Keep only the latest 7
localStorage.setItem('bookmarks', JSON.stringify(bookmarks));
alert(`Ayah ${ayah} bookmarked.`);
renderBookmarks();
}
function renderBookmarks() {
const bookmarkList = document.getElementById('bookmark-list');
bookmarkList.innerHTML = '';
const bookmarks = JSON.parse(localStorage.getItem('bookmarks')) || [];
bookmarks.forEach(({ surah, ayah }) => {
const listItem = document.createElement('li');
listItem.textContent = `Surah ${surah}, Ayah ${ayah}`;
listItem.style.cursor = 'pointer';
listItem.addEventListener('click', () => {
renderSurah(surah, ayah);
});
bookmarkList.appendChild(listItem);
});
}
function shareAyah(surah, ayah) {
const url = `${window.location.origin}${window.location.pathname}?index=${surah}#${ayah}`;
if (navigator.share) {
navigator.share({
title: `Surah ${surah}, Ayah ${ayah}`,
url
}).catch(console.error);
} else {
navigator.clipboard.writeText(url).then(() => {
alert('Link copied to clipboard.');
});
}
}
function openTafsir(surah, ayah) {
window.location.href = `/verse?surah=${surah}&verse=${ayah}`;
}
document.getElementById('next-surah').addEventListener('click', async () => {
const surahNumber = parseInt(new URLSearchParams(window.location.search).get('index') || 1);
renderSurah(surahNumber + 1);
});
document.getElementById('previous-surah').addEventListener('click', async () => {
const surahNumber = parseInt(new URLSearchParams(window.location.search).get('index') || 1);
if (surahNumber > 1) renderSurah(surahNumber - 1);
});
window.addEventListener('DOMContentLoaded', () => {
const surahNumber = parseInt(new URLSearchParams(window.location.search).get('index') || 1);
renderSurah(surahNumber);
renderBookmarks();
});
</script>
<!-- Service Worker for Offline Capabilities -->
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/service-worker.js')
.then(registration => {
console.log('Service Worker registered with scope: ', registration.scope);
})
.catch(error => {
console.log('Service Worker registration failed: ', error);
});
}
</script>
</body>
</html>