Skip to content

Commit

Permalink
Update script.js (XengShi#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
prem-k-r authored Dec 1, 2024
1 parent c8965da commit 4d9603a
Showing 1 changed file with 26 additions and 8 deletions.
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

0 comments on commit 4d9603a

Please sign in to comment.