forked from Freakybob-Team/search.freakybob.site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.html
441 lines (353 loc) · 15.6 KB
/
test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
<!DOCTYPE html>
<html>
<head>
<title>FreakySearch</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="FreakySearch - A simple browser inside a browser">
<meta content="FreakySearch" property="og:title" />
<meta content="A simple 'browser inside a browser'! It has many features like searching, weather and much more!" property="og:description" />
<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">
</head>
<body onload="getUsername()">
<div class="menu">
<div id="username">
Welcome, <span id="user-name"></span>!
</div>
<a href="https://freakybob.site">Freakybob.site</a>
<a href="https://videos.freakybob.site" class="textnavbar">Videos</a>
<a href="https://blog.freakybob.site" class="textnavbar">Blog</a>
<a href="https://github.com/Freakybob-Team" class="textnavbar">GitHub</a>
<div id="clock" class="clock"></div>
</div>
<div class="overlay"></div>
<div class="top-overlay"></div>
<div id="weather-modal" class="modal">
<h1>FreakyWeather</h1>
<input type="text" id="locationInput" placeholder="Enter a city, state (e.g., Los Angeles, CA)">
<button id="searchButton">Search</button>
<button id="geoButton">Use My Location</button>
<p>We use <a href="https://openweathermap.org/">https://openweathermap.org/</a> to provide this service.</p>
<div class="weather-info">
<img id="weatherIcon" class="weather-icon" src="" alt="Weather Icon" style="display: none;">
<h2 id="location"></h2>
<p id="temperature"></p>
<p id="description"></p>
<p id="humidity"></p>
<p id="wind"></p>
<p id="errorMessage" class="error"></p>
<p id="loading" class="loading">Loading...</p>
<button class="close-btn">Close</button>
</div>
</div>
<div id="credits-modal" class="modal">
<h2>Credits</h2>
<p>Background image: scblurr on Wallpapers.com</p>
<button class="close-btn">Close</button>
</div>
<div id="about-modal" class="modal">
<h2>About</h2>
<p>FreakySearch 1.4</p>
<p>Last revision date: October 13th, 2024</p>
<br>
<h2>Configurations</h2>
<p>No items!</p>
<button id="change-name-button">Change Name</button>
<div id="change-name-input" style="display: none;">
<input type="text" id="new-username" placeholder="Enter your name">
</div>
<button class="close-btn">Close</button>
</div>
<img src="logo.webp" alt="FreakySearch Logo" id="logo">
<div class="search-box">
<script async src="https://cse.google.com/cse.js?cx=91650286aa42a4a77"></script>
<div class="gcse-search"></div>
</div>
<div class="options">
<a href="#weather" class="weathera">Weather</a>
<a href="#credits" class="creditsa">Credits</a>
<a href="#about" class="abouta">About</a>
</div>
<div class="button-container">
<button id="prev-button"><</button>
<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>
// code by the Freakybob Team
// 10/17/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();
function getUsername() {
const savedName = localStorage.getItem('username') || 'User';
document.getElementById('user-name').textContent = savedName;
}
document.getElementById('change-name-button').addEventListener('click', () => {
const nameInputDiv = document.getElementById('change-name-input');
nameInputDiv.style.display = 'block';
const nameInput = document.getElementById('new-username');
nameInput.value = localStorage.getItem('username') || 'User';
nameInput.focus();
nameInput.addEventListener('blur', saveUsername);
nameInput.addEventListener('keydown', function(event) {
if (event.key === 'Enter') {
saveUsername();
nameInput.blur();
}
});
});
function saveUsername() {
const newName = document.getElementById('new-username').value.trim();
if (newName) {
localStorage.setItem('username', newName);
document.getElementById('user-name').textContent = newName;
}
document.getElementById('change-name-input').style.display = 'none';
}
</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>
</html>