-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
223 lines (196 loc) · 7.05 KB
/
index.html
File metadata and controls
223 lines (196 loc) · 7.05 KB
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
<link rel="shortcut icon" type="image/png" href="https://i.ibb.co/tb4L16k/PVPN-WEATHER.png">
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PVPN Weather</title>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Roboto', sans-serif;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
background-color: #121212;
color: #ffffff;
transition: background-color 0.5s ease-in-out, background-image 0.5s ease-in-out;
background-image: url(''); /* Set default background image */
background-size: cover;
background-position: center;
}
h1 {
font-size: 2.5em;
margin-bottom: 15px;
font-weight: 700;
text-align: center;
opacity: 0;
transform: translateY(-20px);
animation: fadeIn 0.5s forwards 0.3s; /* Delay animation */
}
@keyframes fadeIn {
to {
opacity: 1;
transform: translateY(0);
}
}
.search {
display: flex;
justify-content: center;
margin-bottom: 20px;
width: 100%;
max-width: 400px;
}
input[type="text"] {
padding: 15px;
font-size: 1.2em;
border: none;
border-radius: 5px 0 0 5px;
outline: none;
flex: 1;
background-color: #1e1e1e;
color: white;
transition: background-color 0.3s;
}
input[type="text"]:focus {
background-color: #272727;
}
button {
padding: 15px;
font-size: 1.2em;
color: #ffffff;
background-color: #ff5722;
border: none;
border-radius: 0 5px 5px 0;
cursor: pointer;
transition: background-color 0.3s;
font-weight: 500;
}
button:hover {
background-color: #e64a19;
}
.weather-card {
display: none;
opacity: 0;
transform: translateY(20px);
transition: opacity 0.5s ease-in-out, transform 0.5s ease-in-out;
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
padding: 20px;
border-radius: 15px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
max-width: 400px;
width: 90%;
text-align: center;
}
.weather-card.show {
display: block;
opacity: 1;
transform: translateY(0);
}
.temp {
font-size: 4em;
margin: 10px 0;
transition: transform 0.5s ease-in-out;
}
.description {
font-size: 1.5em;
margin-bottom: 10px;
color: #bdbdbd;
}
.icon {
width: 100px;
height: 100px;
}
.location {
font-size: 1.5em;
font-weight: 500;
}
</style>
</head>
<body>
<div class="container">
<h1>PVPN Weather</h1>
<div class="search">
<input type="text" id="cityInput" placeholder="Enter city name" />
<button onclick="getWeather()">Search</button>
</div>
<div class="weather-card" id="weatherCard">
<img id="weatherIcon" class="icon" src="" alt="Weather Icon">
<div class="location" id="cityName"></div>
<div class="temp" id="temperature"></div>
<div class="description" id="weatherDescription"></div>
</div>
</div>
<script>
const apiKey = "765ab5a50d4b42520914a3c8b382ac40"; // Your provided OpenWeatherMap API key
function getWeather() {
const city = document.getElementById('cityInput').value;
if (!city) {
alert('Please enter a city name.');
return;
}
// Fetch weather data with imperial units for Fahrenheit
fetch(`https://api.openweathermap.org/data/2.5/weather?q=${city}&units=imperial&appid=${apiKey}`)
.then(response => {
if (!response.ok) {
throw new Error('City not found');
}
return response.json();
})
.then(data => {
displayWeather(data);
})
.catch(error => {
alert(error.message);
});
}
function displayWeather(data) {
document.getElementById('cityName').innerText = `${data.name}, ${data.sys.country}`;
document.getElementById('temperature').innerText = `${Math.round(data.main.temp)}°F`; // Display temperature in Fahrenheit
document.getElementById('weatherDescription').innerText = data.weather[0].description.charAt(0).toUpperCase() + data.weather[0].description.slice(1);
// Update weather icon
const iconCode = data.weather[0].icon;
document.getElementById('weatherIcon').src = `http://openweathermap.org/img/wn/${iconCode}@2x.png`;
// Change background image based on weather condition
const weatherCondition = data.weather[0].main.toLowerCase();
changeBackground(weatherCondition);
const weatherCard = document.getElementById('weatherCard');
weatherCard.classList.add('show');
// Add a slight zoom effect when updating the temperature
const temperatureElement = document.getElementById('temperature');
temperatureElement.style.transform = 'scale(1.2)'; // Scale up
setTimeout(() => {
temperatureElement.style.transform = 'scale(1)'; // Scale back
}, 500);
}
function changeBackground(condition) {
let backgroundImage;
switch (condition) {
case 'clear':
backgroundImage = '#000'; // Clear skies
break;
case 'clouds':
backgroundImage = '#000'; // Cloudy
break;
case 'rain':
backgroundImage = '#000'; // Rainy
break;
case 'snow':
backgroundImage = '#000'; // Snow
break;
case 'thunderstorm':
backgroundImage = '#000'; // Thunderstorm
break;
default:
backgroundImage = '#000'; // Fallback
}
document.body.style.backgroundImage = `url('${backgroundImage}')`;
}
</script>
</body>
</html>