Skip to content

Commit

Permalink
modified: chrome/newtab.html
Browse files Browse the repository at this point in the history
  • Loading branch information
wish13yt committed Oct 13, 2024
1 parent 0756c3c commit 36de810
Showing 1 changed file with 306 additions and 3 deletions.
309 changes: 306 additions & 3 deletions chrome/newtab.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<meta content="Placeholder" property="og:image" />
<meta content="#006b79" data-react-helmet="true" name="theme-color" />
<link rel="icon" type="image/x-icon" href="logo.ico">
<link rel="stylesheet" href="css/index.css">
<link rel="stylesheet" href="../css/index.css">
</head>
<body>

Expand Down Expand Up @@ -66,7 +66,7 @@ <h2>Configurations</h2>
</div>


<img src="logo.webp" alt="FreakySearch Logo" id="logo">
<img src="../logo.webp" alt="FreakySearch Logo" id="logo">


<div class="search-box">
Expand All @@ -86,7 +86,310 @@ <h2>Configurations</h2>
<button id="next-button">></button>
</div>
<p class="privacy">Our Privacy Policy is listed <a href="privacy">here</a>. By using anything on this webpage, you agree to these terms.</p>
<script src="js/index.js"></script>
<script>
// code by the Freakybob Team
// 10/13/2024
// Please leave this note in here if you are using this code in your project!
// ❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️
const body = document.body;
const backgrounds = [
"../bg.png",
"../idk.jpg",
"../ocean.jpg"
];

let currentIndex = 0;

function setCookie(name, value, days) {
const date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
const expires = "; expires=" + date.toUTCString();
document.cookie = name + "=" + (value || "") + expires + "; path=/";
}

function getCookie(name) {
const nameEQ = name + "=";
const ca = document.cookie.split(';');
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) === ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
}
return null;
}

const savedIndex = getCookie('backgroundIndex');
if (savedIndex) {
currentIndex = parseInt(savedIndex);
body.style.backgroundImage = `url(${backgrounds[currentIndex]})`;
} else {
body.style.backgroundImage = `url(${backgrounds[currentIndex]})`;
}

function changeBackground() {
currentIndex = (currentIndex + 1) % backgrounds.length;
body.style.backgroundImage = `url(${backgrounds[currentIndex]})`;
setCookie('backgroundIndex', currentIndex, 7);
}

function updateClock() {
const now = new Date();
const options = { hour: 'numeric', minute: 'numeric', hour12: true };
const timeString = now.toLocaleString('en-US', options);
document.getElementById('clock').textContent = timeString;
}

updateClock();
setInterval(updateClock, 60000);


function setBackground(index) {
body.style.backgroundImage = `url('${backgrounds[index]}')`;
}

document.getElementById('next-button').addEventListener('click', function() {
currentIndex = (currentIndex + 1) % backgrounds.length;
setBackground(currentIndex);
});

document.getElementById('prev-button').addEventListener('click', function() {
currentIndex = (currentIndex - 1 + backgrounds.length) % backgrounds.length;
setBackground(currentIndex);
});

setBackground(currentIndex);

document.addEventListener('DOMContentLoaded', function () {
const overlay = document.querySelector('.overlay');
const topOverlay = document.querySelector('.top-overlay');
const modals = document.querySelectorAll('.modal');

function openModal(modalId) {
document.getElementById(modalId).classList.add('active');
overlay.classList.add('active');
topOverlay.classList.add('active');
}

function closeModal() {
modals.forEach(modal => modal.classList.remove('active'));
overlay.classList.remove('active');
topOverlay.classList.remove('active');
}


document.querySelector('.weathera').addEventListener('click', function (e) {
e.preventDefault();
openModal('weather-modal');
});

document.querySelector('.creditsa').addEventListener('click', function (e) {
e.preventDefault();
openModal('credits-modal');
});

document.querySelector('.abouta').addEventListener('click', function (e) {
e.preventDefault();
openModal('about-modal');
});


document.querySelectorAll('.close-btn').forEach(btn => {
btn.addEventListener('click', closeModal);
});


overlay.addEventListener('click', closeModal);
topOverlay.addEventListener('click', closeModal);
});


const apiKey = '9fb72ce4a247b16999ba8df85db1b357';
const apiUrl = 'https://api.openweathermap.org/data/2.5/weather';


const locationInput = document.getElementById('locationInput');
const searchButton = document.getElementById('searchButton');
const geoButton = document.getElementById('geoButton');
const locationElement = document.getElementById('location');
const temperatureElement = document.getElementById('temperature');
const descriptionElement = document.getElementById('description');
const humidityElement = document.getElementById('humidity');
const windElement = document.getElementById('wind');
const errorMessage = document.getElementById('errorMessage');
const loadingElement = document.getElementById('loading');
const weatherIcon = document.getElementById('weatherIcon');


searchButton.addEventListener('click', () => {
const location = locationInput.value.trim();
if (location) {
fetchWeather(location);
} else {
displayError('Please enter a city and state.');
}
});

locationInput.addEventListener('keyup', (event) => {
if (event.key === 'Enter') {
searchButton.click();
}
});

geoButton.addEventListener('click', () => {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
position => {
const { latitude, longitude } = position.coords;
fetchWeatherByCoords(latitude, longitude);
},
error => {
switch (error.code) {
case error.PERMISSION_DENIED:
displayError('User denied the request for Geolocation.');
break;
case error.POSITION_UNAVAILABLE:
displayError('Location information is unavailable.');
break;
case error.TIMEOUT:
displayError('The request to get user location timed out.');
break;
case error.UNKNOWN_ERROR:
displayError('An unknown error occurred.');
break;
}
}
);
} else {
displayError('Geolocation is not supported by your browser.');
}
});


function fetchWeather(location) {
const url = `${apiUrl}?q=${encodeURIComponent(location)}&appid=${apiKey}&units=imperial`;

showLoading();
clearWeatherInfo();

fetch(url)
.then(response => {
if (!response.ok) {
return response.json().then(error => {
throw new Error(error.message || 'City not found');
});
}
return response.json();
})
.then(data => {
hideLoading();
displayWeather(data);
})
.catch(error => {
hideLoading();
console.error('Error fetching weather data:', error);
displayError(`Unable to retrieve weather data. ${error.message}`);
});
}


function fetchWeatherByCoords(lat, lon) {
const url = `${apiUrl}?lat=${lat}&lon=${lon}&appid=${apiKey}&units=imperial`;

showLoading();
clearWeatherInfo();

fetch(url)
.then(response => {
if (!response.ok) {
return response.json().then(error => {
throw new Error(error.message || 'Could not fetch weather data');
});
}
return response.json();
})
.then(data => {
hideLoading();
displayWeather(data);
})
.catch(error => {
hideLoading();
console.error('Error fetching weather data:', error);
displayError(`Unable to retrieve weather data. ${error.message}`);
});
}


function displayWeather(data) {
const { name, sys, main, weather, wind } = data;
locationElement.textContent = `${name}, ${sys.country}`;
temperatureElement.textContent = `Temperature: ${Math.round(main.temp)}°F`;
descriptionElement.textContent = `Condition: ${capitalizeFirstLetter(weather[0].description)}`;
humidityElement.textContent = `Humidity: ${main.humidity}%`;
windElement.textContent = `Wind Speed: ${wind.speed} mph`;


const iconCode = weather[0].icon;
weatherIcon.src = `https://openweathermap.org/img/wn/${iconCode}@2x.png`;
weatherIcon.alt = weather[0].description;
weatherIcon.style.display = 'block';
}


function displayError(message) {
errorMessage.textContent = message;
errorMessage.style.display = 'block';
loadingElement.style.display = 'none';
}


function showLoading() {
loadingElement.style.display = 'block';
errorMessage.style.display = 'none';
clearWeatherInfoDisplay();
}


function hideLoading() {
loadingElement.style.display = 'none';
}


function clearWeatherInfo() {
locationElement.textContent = '';
temperatureElement.textContent = '';
descriptionElement.textContent = '';
humidityElement.textContent = '';
windElement.textContent = '';
weatherIcon.style.display = 'none';
errorMessage.textContent = '';
errorMessage.style.display = 'none';
}


function clearWeatherInfoDisplay() {
locationElement.textContent = '';
temperatureElement.textContent = '';
descriptionElement.textContent = '';
humidityElement.textContent = '';
windElement.textContent = '';
weatherIcon.style.display = 'none';
}


function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}


window.addEventListener('resize', adjustModalHeight);
function adjustModalHeight() {
const weatherModal = document.getElementById('weather-modal');
weatherModal.style.maxHeight = `${window.innerHeight * 0.9}px`;
}


adjustModalHeight();
</script>
<!--I absulutly cooked at the weather stuff. Everyone should now gibe me a cookie cause I am fatass! -Squirrel-->
<!-- here, take it! 🍪 - wish-->
</body>
Expand Down

0 comments on commit 36de810

Please sign in to comment.