-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprayer.html
367 lines (315 loc) · 12.9 KB
/
prayer.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Prayer Times</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 20px;
text-align: center;
}
#location-info {
font-size: 16px;
margin-bottom: 20px;
color: #00796b;
font-weight: bold;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
table, th, td {
border: 1px solid #ddd;
padding: 10px;
text-align: left;
}
th {
background-color: #00796b;
color: #fff;
}
td {
background-color: #fff;
}
.prayer-time-row {
background-color: #f8f8f8;
}
.current-prayer {
background-color: #ffeb3b;
color: #000;
font-weight: bold;
}
#date-info {
margin-top: 20px;
font-size: 16px;
color: #00796b;
padding: 15px;
border: 2px solid #00796b;
background-color: #e0f2f1;
border-radius: 5px;
}
#method-select, #time-format-select {
font-size: 16px;
padding: 8px;
margin: 20px 0;
border: 2px solid #00796b;
border-radius: 5px;
background-color: #ffffff;
color: #00796b;
cursor: pointer;
width: auto;
max-width: 250px;
}
.prayer-time-row:hover {
background-color: #c8e6c9;
cursor: pointer;
}
/* Responsive Styles */
@media (max-width: 768px) {
#location-info {
font-size: 14px;
}
#method-select, #time-format-select {
width: 100%;
max-width: 100%;
}
#date-info {
font-size: 14px;
padding: 10px;
}
table, th, td {
padding: 8px;
font-size: 14px;
}
table {
margin-top: 10px;
}
th {
font-size: 16px;
}
td {
font-size: 14px;
}
}
@media (max-width: 480px) {
#location-info {
font-size: 12px;
}
#method-select, #time-format-select {
padding: 6px;
}
#date-info {
font-size: 12px;
padding: 8px;
}
table, th, td {
padding: 6px;
font-size: 12px;
}
th {
font-size: 14px;
}
td {
font-size: 12px;
}
}
</style>
</head>
<body>
<div id="location-info">Fetching your location...</div>
<!-- Method Selection Dropdown -->
<div>
<label for="method-select">Select Calculation Method:</label>
<select id="method-select" onchange="getPrayerTimes()">
<option value="0">Jafari / Shia Ithna-Ashari</option>
<option value="1">University of Islamic Sciences, Karachi</option>
<option value="2">Islamic Society of North America</option>
<option value="3" selected>Muslim World League</option>
<option value="4">Umm Al-Qura University, Makkah</option>
<option value="5">Egyptian General Authority of Survey</option>
<option value="7">Institute of Geophysics, University of Tehran</option>
<option value="8">Gulf Region</option>
<option value="9">Kuwait</option>
<option value="10">Qatar</option>
<option value="12">Majlis Ugama Islam Singapura, Singapore</option>
<option value="12">Union Organization Islamic de France</option>
<option value="13">Diyanet İşleri Başkanlığı, Turkey</option>
<option value="14">Spiritual Administration of Muslims of Russia</option>
<option value="15">Moonsighting Committee Worldwide</option>
</select>
</div>
<!-- Time Format Selection Dropdown -->
<div>
<label for="time-format-select">Select Time Format:</label>
<select id="time-format-select" onchange="updateTimeFormat()">
<option value="12" selected>12-hour</option>
<option value="24">24-hour</option>
</select>
</div>
<div id="date-info"></div>
<div id="prayer-times">
<h2>Prayer Times (Daily):</h2>
<table>
<thead>
<tr>
<th>Prayer</th>
<th>Time</th>
</tr>
</thead>
<tbody id="times-list">
<!-- Prayer times will be inserted here -->
</tbody>
</table>
</div>
<div id="monthly-prayer-times">
<h2>Prayer Times (Monthly):</h2>
<table>
<thead>
<tr>
<th>Date</th>
<th>Fajr</th>
<th>Dhuhr</th>
<th>Asr</th>
<th>Maghrib</th>
<th>Isha</th>
</tr>
</thead>
<tbody id="monthly-times-list">
<!-- Monthly prayer times will be inserted here -->
</tbody>
</table>
</div>
<script>
let timeFormat = 12; // Default time format (12-hour)
// Automatically fetch prayer times when the page loads
window.onload = function() {
getPrayerTimes();
};
function getPrayerTimes() {
const method = document.getElementById("method-select").value;
// Check if geolocation is available
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
const latitude = position.coords.latitude;
const longitude = position.coords.longitude;
const date = new Date().toISOString().split('T')[0].split('-').reverse().join('-'); // Current date in DD-MM-YYYY format
// Display location info
const geocodeUrl = `https://api.bigdatacloud.net/data/reverse-geocode-client?latitude=${latitude}&longitude=${longitude}&localityLanguage=en`;
fetch(geocodeUrl)
.then(response => response.json())
.then(locationData => {
const address = locationData.locality || 'Address not available';
document.getElementById('location-info').innerHTML = `Your Location: ${address}, Latitude: ${latitude.toFixed(2)}, Longitude: ${longitude.toFixed(2)}`;
// Get prayer times for today
const prayerTimesUrl = `https://api.aladhan.com/v1/timings/${date}?latitude=${latitude}&longitude=${longitude}&method=${method}`;
fetch(prayerTimesUrl)
.then(response => response.json())
.then(data => {
if (data.code === 200) {
const timings = data.data.timings;
const dateData = data.data.date;
displayDateInfo(dateData);
displayPrayerTimes(timings);
} else {
alert('Error fetching prayer times. Please try again.');
}
})
.catch(error => {
console.error('Error:', error);
alert('An error occurred. Please try again.');
});
// Get monthly prayer times
const currentMonth = new Date().getMonth() + 1; // Current month (1-12)
const currentYear = new Date().getFullYear(); // Current year
const monthlyPrayerTimesUrl = `https://api.aladhan.com/v1/calendar/${currentYear}/${currentMonth}?latitude=${latitude}&longitude=${longitude}&method=${method}`;
fetch(monthlyPrayerTimesUrl)
.then(response => response.json())
.then(monthlyData => {
if (monthlyData.code === 200) {
displayMonthlyPrayerTimes(monthlyData.data);
} else {
alert('Error fetching monthly prayer times. Please try again.');
}
})
.catch(error => {
console.error('Error:', error);
alert('An error occurred. Please try again.');
});
});
}, function(error) {
alert('Error fetching location. Please enable location services.');
});
} else {
alert('Geolocation is not supported by this browser.');
}
}
function displayDateInfo(dateData) {
const gregorianDate = dateData.gregorian;
const hijriDate = dateData.hijri;
const gregorianDateStr = `${gregorianDate.day} ${gregorianDate.month.en} ${gregorianDate.year} (${gregorianDate.weekday.en})`;
const hijriDateStr = `${hijriDate.day} ${hijriDate.month.en} ${hijriDate.year} (${hijriDate.weekday.en})`;
document.getElementById('date-info').innerHTML = `
<strong>Gregorian Date:</strong> ${gregorianDateStr}<br>
<strong>Hijri Date:</strong> ${hijriDateStr}
`;
}
function displayPrayerTimes(timings) {
const timesList = document.getElementById('times-list');
timesList.innerHTML = ''; // Clear previous times
const prayers = ['Fajr', 'Dhuhr', 'Asr', 'Maghrib', 'Isha'];
prayers.forEach(prayer => {
const time = timings[prayer];
const formattedTime = timeFormat === 12 ? convertTo12Hour(time) : time;
const row = document.createElement('tr');
row.classList.add('prayer-time-row');
row.innerHTML = `<td>${prayer}</td><td>${formattedTime}</td>`;
timesList.appendChild(row);
});
}
function displayMonthlyPrayerTimes(monthlyData) {
const monthlyTimesList = document.getElementById('monthly-times-list');
monthlyTimesList.innerHTML = ''; // Clear previous monthly times
monthlyData.forEach(item => {
const date = item.date.gregorian.date;
const fajr = item.timings.Fajr;
const dhuhr = item.timings.Dhuhr;
const asr = item.timings.Asr;
const maghrib = item.timings.Maghrib;
const isha = item.timings.Isha;
const formattedFajr = timeFormat === 12 ? convertTo12Hour(fajr) : fajr;
const formattedDhuhr = timeFormat === 12 ? convertTo12Hour(dhuhr) : dhuhr;
const formattedAsr = timeFormat === 12 ? convertTo12Hour(asr) : asr;
const formattedMaghrib = timeFormat === 12 ? convertTo12Hour(maghrib) : maghrib;
const formattedIsha = timeFormat === 12 ? convertTo12Hour(isha) : isha;
const row = document.createElement('tr');
row.classList.add('prayer-time-row');
row.innerHTML = `
<td>${date}</td>
<td>${formattedFajr}</td>
<td>${formattedDhuhr}</td>
<td>${formattedAsr}</td>
<td>${formattedMaghrib}</td>
<td>${formattedIsha}</td>
`;
monthlyTimesList.appendChild(row);
});
}
function convertTo12Hour(time) {
let [hour, minute] = time.split(':');
hour = parseInt(hour, 10);
const suffix = hour >= 12 ? 'PM' : 'AM';
if (hour > 12) hour -= 12;
if (hour === 0) hour = 12;
return `${hour}:${minute} ${suffix}`;
}
function updateTimeFormat() {
timeFormat = document.getElementById("time-format-select").value;
getPrayerTimes();
}
</script>
</body>
</html>