From 2b4afa456132bce6463c390a8104620afdb11edc Mon Sep 17 00:00:00 2001 From: Irtesaam Date: Sun, 27 Oct 2024 08:47:48 +0530 Subject: [PATCH] Restore script.js file --- script.js | 597 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 597 insertions(+) create mode 100644 script.js diff --git a/script.js b/script.js new file mode 100644 index 00000000..5a0c0266 --- /dev/null +++ b/script.js @@ -0,0 +1,597 @@ +// // Get the toggle button and the body element +// const themeToggle = document.getElementById('theme-toggle'); +// const bodyElement = document.body; + +// // Function to update the button text +// function updateButtonText(isDarkMode) { +// themeToggle.textContent = isDarkMode ? 'Switch to Bright Mode' : 'Switch to Dark Mode'; +// } + +// // Check if the user has a preferred theme +// const userPrefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches; +// if (userPrefersDark) { +// bodyElement.classList.add('dark-mode'); +// updateButtonText(true); +// } + +// // Toggle the theme on button click +// themeToggle.addEventListener('click', () => { +// const isDarkMode = bodyElement.classList.toggle('dark-mode'); +// updateButtonText(isDarkMode); + +// // Save the user's preference in localStorage +// localStorage.setItem('theme', isDarkMode ? 'dark' : 'bright'); +// }); + +// // Apply the saved theme on page load +// const savedTheme = localStorage.getItem('theme'); +// if (savedTheme) { +// const isDarkMode = savedTheme === 'dark'; +// bodyElement.classList.toggle('dark-mode', isDarkMode); +// updateButtonText(isDarkMode); +// } + + +// function initMap() { +// // Initialize the map centered around India +// var map = new google.maps.Map(document.getElementById('map'), { +// zoom: 5, // Zoom level to cover most of India +// center: {lat: 20.5937, lng: 78.9629} // Center of India (lat, lng) +// }); + +// // Delhi marker +// var delhi = new google.maps.Marker({ +// position: {lat: 28.6139, lng: 77.2090}, +// map: map, +// title: 'Delhi, India' +// }); + +// var delhiInfo = new google.maps.InfoWindow({ +// content: '

Delhi

Capital of India, known for its rich history and monuments.

' +// }); + +// delhi.addListener('click', function() { +// delhiInfo.open(map, delhi); +// }); + +// // Mumbai marker +// var mumbai = new google.maps.Marker({ +// position: {lat: 19.0760, lng: 72.8777}, +// map: map, +// title: 'Mumbai, India' +// }); + +// var mumbaiInfo = new google.maps.InfoWindow({ +// content: '

Mumbai

The financial capital of India, famous for Bollywood.

' +// }); + +// mumbai.addListener('click', function() { +// mumbaiInfo.open(map, mumbai); +// }); + +// // Jaipur marker +// var jaipur = new google.maps.Marker({ +// position: {lat: 26.9124, lng: 75.7873}, +// map: map, +// title: 'Jaipur, India' +// }); + +// var jaipurInfo = new google.maps.InfoWindow({ +// content: '

Jaipur

The Pink City, known for its palaces and forts.

' +// }); + +// jaipur.addListener('click', function() { +// jaipurInfo.open(map, jaipur); +// }); + +// // Goa marker +// var goa = new google.maps.Marker({ +// position: {lat: 15.2993, lng: 74.1240}, +// map: map, +// title: 'Goa, India' +// }); + +// var goaInfo = new google.maps.InfoWindow({ +// content: '

Goa

Famous for its beaches, nightlife, and Portuguese heritage.

' +// }); + +// goa.addListener('click', function() { +// goaInfo.open(map, goa); +// }); + +// // Kolkata marker +// var kolkata = new google.maps.Marker({ +// position: {lat: 22.5726, lng: 88.3639}, +// map: map, +// title: 'Kolkata, India' +// }); + +// var kolkataInfo = new google.maps.InfoWindow({ +// content: '

Kolkata

Known for its colonial architecture, art galleries, and cultural festivals.

' +// }); + +// kolkata.addListener('click', function() { +// kolkataInfo.open(map, kolkata); +// }); + +// // Jammu & Kashmir marker +// var jammuKashmir = new google.maps.Marker({ +// position: {lat: 34.0837, lng: 74.7973}, +// map: map, +// title: 'Jammu & Kashmir, India' +// }); + +// var jammuKashmirInfo = new google.maps.InfoWindow({ +// content: '

Jammu & Kashmir

Famous for its stunning landscapes and beautiful valleys.

' +// }); + +// jammuKashmir.addListener('click', function() { +// jammuKashmirInfo.open(map, jammuKashmir); +// }); + +// // Kerala marker +// var kerala = new google.maps.Marker({ +// position: {lat: 10.8505, lng: 76.2711}, +// map: map, +// title: 'Kerala, India' +// }); + +// var keralaInfo = new google.maps.InfoWindow({ +// content: '

Kerala

Known as "God\'s Own Country," famous for its backwaters and lush greenery.

' +// }); + +// kerala.addListener('click', function() { +// keralaInfo.open(map, kerala); +// }); + +// // Odisha marker +// var odisha = new google.maps.Marker({ +// position: {lat: 20.9517, lng: 85.0985}, +// map: map, +// title: 'Odisha, India' +// }); + +// var odishaInfo = new google.maps.InfoWindow({ +// content: '

Odisha

Known for its ancient temples and cultural heritage.

' +// }); + +// odisha.addListener('click', function() { +// odishaInfo.open(map, odisha); +// }); + +// // Gujarat marker +// var gujarat = new google.maps.Marker({ +// position: {lat: 22.2587, lng: 71.1924}, +// map: map, +// title: 'Gujarat, India' +// }); + +// var gujaratInfo = new google.maps.InfoWindow({ +// content: '

Gujarat

Known for its diverse culture, vibrant festivals, and historical sites.

' +// }); + +// gujarat.addListener('click', function() { +// gujaratInfo.open(map, gujarat); +// }); + +// // Another Indian Place (e.g., Rishikesh) +// var rishikesh = new google.maps.Marker({ +// position: {lat: 30.0869, lng: 78.2676}, +// map: map, +// title: 'Rishikesh, India' +// }); + +// var rishikeshInfo = new google.maps.InfoWindow({ +// content: '

Rishikesh

Known as the Yoga Capital of the World and for its spiritual significance.

' +// }); + +// rishikesh.addListener('click', function() { +// rishikeshInfo.open(map, rishikesh); +// }); + +// // Add markers for international destinations + +// // Dubai marker +// var dubai = new google.maps.Marker({ +// position: {lat: 25.276987, lng: 55.296249}, +// map: map, +// title: 'Dubai, UAE' +// }); + +// var dubaiInfo = new google.maps.InfoWindow({ +// content: '

Dubai

Known for its modern architecture, luxury shopping, and vibrant nightlife.

' +// }); + +// dubai.addListener('click', function() { +// dubaiInfo.open(map, dubai); +// }); + +// // Paris marker +// var paris = new google.maps.Marker({ +// position: {lat: 48.8566, lng: 2.3522}, +// map: map, +// title: 'Paris, France' +// }); + +// var parisInfo = new google.maps.InfoWindow({ +// content: '

Paris

The City of Light, famous for its art, fashion, and the iconic Eiffel Tower.

' +// }); + +// paris.addListener('click', function() { +// parisInfo.open(map, paris); +// }); + +// // New York marker +// var newYork = new google.maps.Marker({ +// position: {lat: 40.7128, lng: -74.0060}, +// map: map, +// title: 'New York, USA' +// }); + +// var newYorkInfo = new google.maps.InfoWindow({ +// content: '

New York

The Big Apple, known for its skyscrapers, Broadway, and Central Park.

' +// }); + +// newYork.addListener('click', function() { +// newYorkInfo.open +// newYorkInfo.open(map, newYork); +// }); + +// // London marker +// var london = new google.maps.Marker({ +// position: {lat: 51.5074, lng: -0.1278}, +// map: map, +// title: 'London, UK' +// }); + +// var londonInfo = new google.maps.InfoWindow({ +// content: '

London

Known for its history, culture, and landmarks like Big Ben and the London Eye.

' +// }); + +// london.addListener('click', function() { +// londonInfo.open(map, london); +// }); + +// // Bali marker +// var bali = new google.maps.Marker({ +// position: {lat: -8.3405, lng: 115.0920}, +// map: map, +// title: 'Bali, Indonesia' +// }); + +// var baliInfo = new google.maps.InfoWindow({ +// content: '

Bali

A tropical paradise known for its beaches, temples, and vibrant culture.

' +// }); + +// bali.addListener('click', function() { +// baliInfo.open(map, bali); +// }); + +// // Singapore marker +// var singapore = new google.maps.Marker({ +// position: {lat: 1.3521, lng: 103.8198}, +// map: map, +// title: 'Singapore' +// }); + +// var singaporeInfo = new google.maps.InfoWindow({ +// content: '

Singapore

A global financial hub known for its cleanliness, Marina Bay Sands, and the Merlion.

' +// }); + +// singapore.addListener('click', function() { +// singaporeInfo.open(map, singapore); +// }); + +// // Sydney marker +// var sydney = new google.maps.Marker({ +// position: {lat: -33.8688, lng: 151.2093}, +// map: map, +// title: 'Sydney, Australia' +// }); + +// var sydneyInfo = new google.maps.InfoWindow({ +// content: '

Sydney

Famous for the Sydney Opera House, Harbour Bridge, and beautiful beaches.

' +// }); + +// sydney.addListener('click', function() { +// sydneyInfo.open(map, sydney); +// }); + +// // Tokyo marker +// var tokyo = new google.maps.Marker({ +// position: {lat: 35.6762, lng: 139.6503}, +// map: map, +// title: 'Tokyo, Japan' +// }); + +// var tokyoInfo = new google.maps.InfoWindow({ +// content: '

Tokyo

A bustling metropolis known for its skyscrapers, shopping, and cherry blossoms.

' +// }); + +// tokyo.addListener('click', function() { +// tokyoInfo.open(map, tokyo); +// }); + + + +// } + +/* Detect system default's theme */ + +document.addEventListener('DOMContentLoaded', function() { + const modeToggle = document.getElementById('modeToggle'); + const sunIcon = document.querySelector('.sun-icon'); + const moonIcon = document.querySelector('.moon-icon'); + const body = document.body; + + // Function to apply the theme + function applyTheme(isDarkMode) { + if (isDarkMode) { + body.classList.add('dark-mode'); + body.classList.remove('light-mode'); + sunIcon.style.display = 'none'; + moonIcon.style.display = 'inline-block'; + localStorage.setItem('theme', 'dark'); + } else { + body.classList.add('light-mode'); + body.classList.remove('dark-mode'); + sunIcon.style.display = 'inline-block'; + moonIcon.style.display = 'none'; + localStorage.setItem('theme', 'light'); + } + } + + // Check the system's color scheme preference + const userPrefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches; + const savedTheme = localStorage.getItem('theme'); + + if (savedTheme) { + applyTheme(savedTheme === 'dark'); + } else { + applyTheme(userPrefersDark); + } + + // Listen for changes to the system's color scheme + window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => { + applyTheme(event.matches); + }); + + // Toggle the theme on button click + modeToggle.addEventListener('click', () => { + const isDarkMode = body.classList.toggle('dark-mode'); + body.classList.toggle('light-mode', !isDarkMode); + localStorage.setItem('theme', isDarkMode ? 'dark' : 'light'); + applyTheme(isDarkMode); + }); +}); + + +/*SOS*/ + +function sendSOS() { + const statusDiv = document.getElementById("sos-status"); + + // Check if Geolocation is available + if ("geolocation" in navigator) { + navigator.geolocation.getCurrentPosition(function (position) { + const latitude = position.coords.latitude; + const longitude = position.coords.longitude; + + // Generate a message with location data + const sosMessage = `Emergency! My current location is: Latitude: ${latitude}, Longitude: ${longitude}. Please send help immediately.`; + + // Provide options to send the SOS message via Email or SMS + statusDiv.innerHTML = ` +

Location acquired. Send your emergency message:

+ + + + + + + `; + }, function (error) { + statusDiv.innerHTML = `

Error retrieving location: ${error.message}

`; + }); + } else { + statusDiv.innerHTML = "

Geolocation is not supported by your browser.

"; + } +} + +document.getElementById('postForm').addEventListener('submit', function (e) { + e.preventDefault(); + + const postContent = document.getElementById('postContent').value; + if (postContent.trim() === '') return; + + const postContainer = document.getElementById('posts'); + const newPost = document.createElement('div'); + newPost.classList.add('post'); + newPost.textContent = postContent; + + postContainer.appendChild(newPost); + document.getElementById('postContent').value = ''; // Clear the textarea +}); +const fileInput = document.getElementById('file-input'); +const uploadForm = document.getElementById('upload-form'); +const contentList = document.getElementById('content-list'); + +uploadForm.addEventListener('submit', async (event) => { + event.preventDefault(); + + const file = fileInput.files[0]; + + if (!file) { + alert('Please select a file to upload.'); + return; + } + + const formData = new FormData(); + formData.append('file', file); + + try { + const response = await fetch('/upload', { + method: 'POST', + body: formData + }); + + if (!response.ok) { + throw new Error('Error uploading file: ' + response.statusText); + } + + const data = await response.json(); + console.log('File uploaded:', data.filename); + + // Update content list with the new file + const listItem = document.createElement('li'); + listItem.textContent = data.filename; + contentList.appendChild(listItem); + } catch (error) { + console.error('Error uploading file:', error); + alert('An error occurred while uploading the file.'); + } +}); + +window.addEventListener("scroll", function () { + let navbar = document.getElementById("main-head"); + if (window.scrollY > 100) navbar.classList.add("shadow"); + else navbar.classList.remove("shadow"); +}); + +function initMap() { + var map = new google.maps.Map(document.getElementById('map'), { + zoom: 2, + center: {lat: 20.5937, lng: 78.9629} + }); + + var destinations = [ + {lat: 28.6139, lng: 77.2090, title: 'Delhi, India', content: '

Delhi

Capital of India, known for its rich history and monuments.

'}, + {lat: 19.0760, lng: 72.8777, title: 'Mumbai, India', content: '

Mumbai

The financial capital of India, famous for Bollywood.

'}, + {lat: 26.9124, lng: 75.7873, title: 'Jaipur, India', content: '

Jaipur

The Pink City, known for its palaces and forts.

'}, + {lat: 15.2993, lng: 74.1240, title: 'Goa, India', content: '

Goa

Famous for its beaches, nightlife, and Portuguese heritage.

'}, + {lat: 22.5726, lng: 88.3639, title: 'Kolkata, India', content: '

Kolkata

Known for its colonial architecture, art galleries, and cultural festivals.

'}, + {lat: 34.0837, lng: 74.7973, title: 'Jammu & Kashmir, India', content: '

Jammu & Kashmir

Famous for its stunning landscapes and beautiful valleys.

'}, + {lat: 10.8505, lng: 76.2711, title: 'Kerala, India', content: '

Kerala

Known as "God\'s Own Country," famous for its backwaters and lush greenery.

'}, + {lat: 20.9517, lng: 85.0985, title: 'Odisha, India', content: '

Odisha

Known for its ancient temples and cultural heritage.

'}, + {lat: 22.2587, lng: 71.1924, title: 'Gujarat, India', content: '

Gujarat

Known for its diverse culture, vibrant festivals, and historical sites.

'}, + {lat: 25.276987, lng: 55.296249, title: 'Dubai, UAE', content: '

Dubai

Known for its modern architecture, luxury shopping, and vibrant nightlife.

'}, + {lat: 48.8566, lng: 2.3522, title: 'Paris, France', content: '

Paris

The City of Light, famous for its art, fashion, and the iconic Eiffel Tower.

'}, + {lat: 40.7128, lng: -74.0060, title: 'New York, USA', content: '

New York

The Big Apple, known for its skyscrapers, Broadway, and Central Park.

'}, + {lat: 51.5074, lng: -0.1278, title: 'London, UK', content: '

London

Known for its history, culture, and landmarks like Big Ben and the London Eye.

'}, + {lat: -8.3405, lng: 115.0920, title: 'Bali, Indonesia', content: '

Bali

A tropical paradise known for its beaches, temples, and vibrant culture.

'}, + {lat: 1.3521, lng: 103.8198, title: 'Singapore', content: '

Singapore

A global financial hub known for its cleanliness, Marina Bay Sands, and the Merlion.

'}, + {lat: -33.8688, lng: 151.2093, title: 'Sydney, Australia', content: '

Sydney

Famous for the Sydney Opera House, Harbour Bridge, and beautiful beaches.

'}, + {lat: 35.6762, lng: 139.6503, title: 'Tokyo, Japan', content: '

Tokyo

A bustling metropolis known for its skyscrapers, shopping, and cherry blossoms.

'} + ]; + + destinations.forEach(function(destination) { + var marker = new google.maps.Marker({ + position: {lat: destination.lat, lng: destination.lng}, + map: map, + title: destination.title + }); + + var infoWindow = new google.maps.InfoWindow({ + content: destination.content + }); + + marker.addListener('click', function() { + infoWindow.open(map, marker); + }); + }); +} + +// Toggle dark and bright mode +// modeToggle.addEventListener('click', function() { +// console.log('Toggle clicked'); // Log when the button is clicked +// document.body.classList.toggle('dark-mode'); +// document.body.classList.toggle('light-mode'); + +// if (document.body.classList.contains('dark-mode')) { +// console.log('Switching to dark mode'); +// sunIcon.style.display = 'none'; // Hide sun icon +// moonIcon.style.display = 'inline-block'; // Show moon icon +// localStorage.setItem('theme', 'dark'); +// } else { +// console.log('Switching to light mode'); +// sunIcon.style.display = 'inline-block'; // Show sun icon +// moonIcon.style.display = 'none'; // Hide moon icon +// localStorage.setItem('theme', 'light'); +// } +// }); + + + +document.getElementById('contactForm').addEventListener('submit', function(e) { + e.preventDefault(); + alert('Thank you for your message! We will get back to you soon.'); + this.reset(); +}); +// discount pop_up +document.addEventListener('DOMContentLoaded', function() { + // Show the popup after a slight delay + setTimeout(function() { + document.getElementById('dealsPopup').style.display = 'flex'; + }, 1000); // Adjust the delay as needed (1000 ms = 1 second) + + // Close the popup when the close button is clicked + document.getElementById('closePopup').addEventListener('click', function() { + document.getElementById('dealsPopup').style.display = 'none'; + }); + + // Close the popup when the user clicks anywhere outside of the popup content + window.addEventListener('click', function(event) { + if (event.target === document.getElementById('dealsPopup')) { + document.getElementById('dealsPopup').style.display = 'none'; + } + }); +}); +// adaptive background +const modeToggle = document.getElementById('modeToggle'); +const body = document.body; + +modeToggle.addEventListener('click', () => { + body.classList.toggle('dark-mode'); + body.classList.toggle('light-mode'); + + // Toggle the icon + if (body.classList.contains('dark-mode')) { + modeToggle.innerHTML = ''; + } else { + modeToggle.innerHTML = ''; + } +}); +// google translator +document.getElementById('languageToggle').addEventListener('click', function() { + var translateElement = document.getElementById('google_translate_element'); + + // Toggle visibility of the Google Translate element + if (translateElement.style.display === 'none' || translateElement.style.display === '') { + translateElement.style.display = 'block'; + googleTranslateElementInit(); // Ensure it's initialized + } else { + translateElement.style.display = 'none'; + } +}); + + +function googleTranslateElementInit() { + new google.translate.TranslateElement({ + pageLanguage: 'en', + includedLanguages: 'en,es,fr,de,it,pt,ja,zh-CN,hi,bn,ml,te,ta,gu,kn,or', + layout: google.translate.TranslateElement.InlineLayout.SIMPLE + }, 'google_translate_element'); +} + +// Script to detect service workers for enabling PWA +if ('serviceWorker' in navigator) { + window.addEventListener('load', () => { + navigator.serviceWorker.register('/service-worker.js') + .then((registration) => { + console.log('ServiceWorker registration successful with scope: ', registration.scope); + }) + .catch((error) => { + console.log('ServiceWorker registration failed: ', error); + }); + }); + }