Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix location 'Delhi' in India and added no background image alert #245

Merged
merged 1 commit into from
Dec 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,14 @@ window.addEventListener('DOMContentLoaded', async () => {
const geoLocation = 'https://ipinfo.io/json/';
const locationData = await fetch(geoLocation);
const parsedLocation = await locationData.json();
currentUserLocation = parsedLocation.city; // Update to user's city from IP

// If the country is India and the location is 'Delhi', update to 'New Delhi'
if (parsedLocation.country === "IN" && parsedLocation.city === "Delhi") {
currentUserLocation = "New Delhi";
} else {
currentUserLocation = parsedLocation.city; // Update to user's city from IP
}

localStorage.setItem("weatherLocation", currentUserLocation); // Save and show the fetched location
} catch (error) {
currentUserLocation = "auto:ip"; // Fallback if fetching location fails
Expand Down Expand Up @@ -1241,13 +1248,24 @@ document.getElementById('imageUpload').addEventListener('change', function (even

// Event listener for Clear button
document.getElementById('clearImage').addEventListener('click', function () {
if (confirm('Are you sure you want to clear the background image?')) {
clearImageFromIndexedDB()
.then(() => {
document.body.style.removeProperty('--bg-image');
})
.catch((error) => console.error(error));
}
// Check if there is an existing background image
loadImageFromIndexedDB()
.then((savedImage) => {
if (savedImage) {
// If an image exists, ask for confirmation
if (confirm('Are you sure you want to clear the background image?')) {
clearImageFromIndexedDB()
.then(() => {
document.body.style.removeProperty('--bg-image');
})
.catch((error) => console.error(error));
}
} else {
// No image exists, do nothing
alert('No background image is currently set.');
}
})
.catch((error) => console.error(error));
});

// Load saved background image on page load
Expand Down