-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
592 lines (515 loc) · 23.2 KB
/
Copy pathindex.html
File metadata and controls
592 lines (515 loc) · 23.2 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
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
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Anlık Hava Durumu</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #FF6F61, #DE425B, #A23B72); /* Red gradient */
background-size: 400% 400%;
animation: redGradientAnimation 15s ease infinite;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
color: #333;
overflow: hidden;
position: relative; /* Needed for absolute positioned snowflakes */
}
@keyframes redGradientAnimation {
0% { background-position: 0% 50%; }
50% { background-position: 100% 50%; }
100% { background-position: 0% 50%; }
}
.card {
background-color: rgba(255, 255, 255, 0.8); /* Semi-transparent white */
backdrop-filter: blur(10px); /* Frosted glass effect */
-webkit-backdrop-filter: blur(10px); /* For Safari */
padding: 40px; /* Daha fazla padding */
border-radius: 25px; /* Daha yuvarlak köşeler */
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2); /* Daha belirgin gölge */
text-align: center;
max-width: 450px; /* Biraz daha geniş */
width: 90%;
position: relative;
z-index: 10; /* Ensure card is above background and snowflakes */
border: 2px solid rgba(224, 122, 95, 0.7); /* Kırmızı tonlarında hafif bir çerçeve */
transition: all 0.3s ease; /* Hover efekti için */
}
.card:hover {
transform: translateY(-5px);
box-shadow: 0 15px 50px rgba(0, 0, 0, 0.3);
}
h1 {
color: #e07a5f; /* Ana kırmızı tonu */
margin-top: 0;
font-size: 2em; /* Biraz daha büyük başlık */
}
h2 {
color: #ce4257; /* Daha koyu bir kırmızı tonu */
font-size: 1.6em;
}
.message {
padding: 15px;
background-color: #f8d7da; /* Açık kırmızı arka plan */
color: #721c24; /* Koyu kırmızı yazı */
border: 1px solid #f5c6cb; /* Açık kırmızı çerçeve */
border-radius: 5px;
margin-top: 20px;
}
.hidden {
display: none !important;
}
.main-display {
display: flex;
justify-content: center;
align-items: center;
margin: 25px 0; /* Boşluk artışı */
color: #555;
}
#weather-icon {
font-size: 4.5em; /* İkonu büyüt */
margin-right: 20px;
color: #e07a5f; /* Ana kırmızı tonu */
}
#temperature {
font-size: 4.5em; /* Sıcaklığı büyüt */
font-weight: bold;
}
#description {
font-style: italic;
color: #666; /* Renk biraz koyulaştı */
margin-bottom: 35px;
font-size: 1.1em; /* Yazı boyutunu artır */
}
.details {
display: flex;
flex-wrap: wrap; /* Küçük ekranlarda alt alta gelmesi için */
justify-content: space-around;
padding: 15px;
border-top: 1px solid #eee;
margin-top: 20px;
font-size: 1em; /* Biraz daha büyük yazı */
color: #666;
}
.details > div {
flex: 1 1 45%; /* İkişerli satırlara bölmek için */
margin: 5px 0;
text-align: left;
padding-left: 10px;
}
.details i {
margin-right: 8px; /* İkon boşluğunu artır */
color: #e07a5f; /* Ana kırmızı tonu */
}
.search-container {
display: flex;
justify-content: center;
margin-bottom: 25px; /* Boşluğu artır */
}
#city-input {
padding: 12px 18px; /* Padding artır */
border: 1px solid #ccc;
border-radius: 25px; /* Yuvarlak köşeler */
margin-right: 12px;
width: 70%;
font-size: 1.1em; /* Yazı boyutunu artır */
outline: none;
transition: border-color 0.3s ease;
}
#city-input:focus {
border-color: #e07a5f; /* Focus rengi */
}
#search-button {
background-color: #ce4257; /* Koyu kırmızı düğme */
color: white;
border: none;
border-radius: 25px; /* Yuvarlak köşeler */
padding: 12px 20px; /* Padding artır */
cursor: pointer;
font-size: 1.1em; /* Yazı boyutunu artır */
transition: background-color 0.3s ease, transform 0.2s ease;
}
#search-button:hover {
background-color: #bc3908; /* Hover için daha koyu kırmızı */
transform: translateY(-2px); /* Hafif yukarı kalkma efekti */
}
.famous-cities-button {
background-color: #a23b72; /* Daha morumsu bir kırmızı tonu */
color: white;
border: none;
border-radius: 25px;
padding: 12px 20px;
cursor: pointer;
font-size: 1.1em;
margin-top: 15px; /* Arama butonundan sonra biraz boşluk */
transition: background-color 0.3s ease, transform 0.2s ease;
width: calc(100% - 80px); /* Karta göre genişlik ayarlaması */
max-width: 300px; /* Maksimum genişlik */
}
.famous-cities-button:hover {
background-color: #7b2c5d;
transform: translateY(-2px);
}
/* Snowflake animation */
.snowflakes {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
overflow: hidden;
z-index: 1; /* Below the card */
}
.snowflake {
position: absolute;
background: white;
border-radius: 50%;
animation: fall linear infinite;
opacity: 0.8;
box-shadow: 0 0 5px rgba(255, 255, 255, 0.5);
}
.snowflake.dark {
background: #333;
opacity: 0.6;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
}
@keyframes fall {
0% {
transform: translateY(-10%) translateX(0px) scale(1);
opacity: 0;
}
10% {
opacity: 0.8;
}
100% {
transform: translateY(100vh) translateX(50px) scale(0.5);
opacity: 0;
}
}
#copyright {
position: fixed; /* Ekranın altından kaybolmaması için */
bottom: 10px;
width: 100%;
text-align: center;
color: rgba(255, 255, 255, 0.7); /* Açık renk, arka planla uyumlu */
font-size: 0.8em;
z-index: 5; /* Kartın altında ama arka planın üstünde */
}
/* Modal Styles */
#famous-cities-modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 100; /* Sit on top */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgba(0,0,0,0.6); /* Black w/ opacity */
display: flex;
justify-content: center;
align-items: center;
}
.modal-content {
background-color: rgba(255, 255, 255, 0.95); /* Nearly opaque white */
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
margin: auto;
padding: 30px;
border-radius: 20px;
box-shadow: 0 5px 15px rgba(0,0,0,0.3);
width: 80%;
max-width: 400px;
text-align: center;
position: relative;
}
.modal-content h3 {
color: #e07a5f;
margin-bottom: 20px;
font-size: 1.5em;
}
#city-list {
list-style: none;
padding: 0;
margin: 0;
}
#city-list li {
background-color: #f8d7da; /* Açık kırmızı */
color: #721c24;
padding: 10px 15px;
margin-bottom: 10px;
border-radius: 15px;
cursor: pointer;
transition: background-color 0.3s ease, transform 0.2s ease;
}
#city-list li:hover {
background-color: #e07a5f; /* Hover rengi */
color: white;
transform: translateX(5px);
}
.close-button {
color: #ce4257;
position: absolute;
top: 15px;
right: 25px;
font-size: 28px;
font-weight: bold;
cursor: pointer;
transition: color 0.3s ease;
}
.close-button:hover,
.close-button:focus {
color: #bc3908;
text-decoration: none;
cursor: pointer;
}
</style>
</head>
<body>
<div class="snowflakes"></div>
<div id="weather-app" class="card">
<h1>Anlık Hava Durumu</h1>
<div class="search-container">
<input type="text" id="city-input" placeholder="Şehir Adı Girin">
<button id="search-button"><i class="fas fa-search"></i></button>
</div>
<button id="famous-cities-button" class="famous-cities-button">Ünlü Şehirler Hava Durumu</button>
<div id="loading" class="message">Konumunuz (IP Adresinden Tahmini) Alınıyor...</div>
<div id="error" class="message hidden" style="background-color: #f8d7da; color: #721c24; border-color: #f5c6cb;">Konum veya Hava Durumu Bilgisi Alınamadı.</div>
<div id="weather-info" class="hidden">
<h2 id="location-name"></h2>
<div class="main-display">
<i id="weather-icon" class="fas fa-sun"></i>
<span id="temperature"></span>
</div>
<p id="description"></p>
<div class="details">
<div><i class="fas fa-wind"></i> Rüzgar: <span id="wind-speed"></span></div>
<div><i class="fas fa-tint"></i> Nem: <span id="humidity"></span></div>
<div><i class="fas fa-thermometer-half"></i> Hissedilen: <span id="feels-like"></span></div>
<div><i class="fas fa-sun"></i> UV İndeksi: <span id="uv-index"></span></div>
<div><i class="fas fa-eye"></i> Görüş: <span id="visibility"></span></div>
</div>
</div>
</div>
<!-- Famous Cities Modal -->
<div id="famous-cities-modal" class="hidden">
<div class="modal-content">
<span class="close-button">×</span>
<h3>Ünlü Şehirler</h3>
<ul id="city-list">
<li data-city="Istanbul">İstanbul</li>
<li data-city="London">Londra</li>
<li data-city="Paris">Paris</li>
<li data-city="New York">New York</li>
<li data-city="Tokyo">Tokyo</li>
</ul>
</div>
</div>
<div id="copyright">© 2025 Hüseyin Çelikel. Tüm Hakları Saklıdır.</div>
<script>
// Weather API ikon kodlarını Font Awesome ikonlarıyla eşleştirme
function getWeatherIconClass(conditionCode, isDay) {
// Weather API, durumu bir kod ile belirtir. Bu kodlara göre en uygun Font Awesome ikonunu seçiyoruz.
// Bu sadece popüler kodların bir kısmıdır. Kapsamlı liste için Weather API dokümantasyonuna bakılabilir.
const iconMap = {
// Güneşli / Açık
1000: isDay ? 'fas fa-sun' : 'fas fa-moon',
// Parçalı bulutlu
1003: isDay ? 'fas fa-cloud-sun' : 'fas fa-cloud-moon',
// Bulutlu
1006: 'fas fa-cloud',
// Kapalı / Çok bulutlu
1009: 'fas fa-cloud',
// Sisli / Puslu
1030: 'fas fa-smog',
1135: 'fas fa-smog',
// Hafif Çiseleme
1063: 'fas fa-cloud-sun-rain',
1150: 'fas fa-cloud-sun-rain',
1153: 'fas fa-cloud-sun-rain',
1180: 'fas fa-cloud-sun-rain',
1183: 'fas fa-cloud-showers-heavy',
// Orta / Yoğun Yağmur
1186: 'fas fa-cloud-showers-heavy',
1189: 'fas fa-cloud-showers-heavy',
1192: 'fas fa-cloud-rain',
1195: 'fas fa-cloud-rain',
1240: 'fas fa-cloud-rain',
1243: 'fas fa-cloud-rain',
// Kar / Sulu Kar
1069: 'fas fa-cloud-meatball', // Hafif sulu kar
1072: 'fas fa-cloud-meatball', // Hafif donan çiseleme
1114: 'fas fa-snowflake', // Kar yağışı
1117: 'fas fa-snowflake', // Yoğun kar
1210: 'fas fa-snowflake', // Hafif kar
1213: 'fas fa-snowflake', // Orta kar
1216: 'fas fa-snowflake', // Yoğun kar
1219: 'fas fa-snowflake', // Çok yoğun kar
1222: 'fas fa-snowflake', // Buz kristalleri
1225: 'fas fa-snowflake', // Buz topakları
1237: 'fas fa-snowflake', // Buzlu yağmur
1255: 'fas fa-snowflake', // Hafif kar yağışı
1258: 'fas fa-snowflake', // Yoğun kar yağışı
// Gök Gürültüsü / Fırtına
1087: 'fas fa-bolt',
1273: 'fas fa-bolt', // Hafif gök gürültüsü
1276: 'fas fa-bolt', // Şiddetli gök gürültüsü
default: 'fas fa-cloud'
};
return iconMap[conditionCode] || iconMap.default;
}
function displayWeather(data) {
document.getElementById('loading').classList.add('hidden');
document.getElementById('error').classList.add('hidden');
document.getElementById('weather-info').classList.remove('hidden');
const capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
const location = data.location;
const current = data.current;
const isDay = current.is_day === 1;
// Konum Adını Şehir ve Ülke olarak alıyoruz
document.getElementById('location-name').textContent = `${location.name}, ${location.country}`;
// Sıcaklık (Celsius)
document.getElementById('temperature').textContent = `${Math.round(current.temp_c)}°C`;
// Açıklama
document.getElementById('description').textContent = capitalize(current.condition.text);
// İkon güncelleme
const iconElement = document.getElementById('weather-icon');
iconElement.className = getWeatherIconClass(current.condition.code, isDay);
// Rüzgar ve Nem
document.getElementById('wind-speed').textContent = `${current.wind_kph} km/s`;
document.getElementById('humidity').textContent = `${current.humidity}%`;
document.getElementById('feels-like').textContent = `${Math.round(current.feelslike_c)}°C`;
document.getElementById('uv-index').textContent = current.uv;
document.getElementById('visibility').textContent = `${current.vis_km} km`;
}
function handleError(message) {
document.getElementById('loading').classList.add('hidden');
document.getElementById('error').classList.add('hidden');
document.getElementById('weather-info').classList.add('hidden');
document.getElementById('error').textContent = message;
document.getElementById('error').classList.remove('hidden');
}
function fetchWeatherData(query) {
// ! DİKKAT: Bu anahtar, GitHub Pages'te veya kaynak kodda herkese açık olacaktır.
const API_KEY = 'd55ccfaf5ae04b02a60220629252510';
// Weather API "current.json" endpoint'ini kullanıyoruz
// Query parametresi IP adresi veya konum adı olabilir
const API_URL = `https://api.weatherapi.com/v1/current.json?key=${API_KEY}&q=${query}&lang=tr`;
fetch(API_URL)
.then(response => {
if (!response.ok) {
throw new Error(`HTTP Hatası! Durum kodu: ${response.status}`);
}
return response.json();
})
.then(data => {
// Weather API'den hata gelirse (örneğin API anahtarı geçersizse)
if (data.error) {
throw new Error(`API Hatası: ${data.error.message}`);
}
displayWeather(data);
})
.catch(error => {
console.error('Hava durumu verisi çekilemedi:', error);
handleError(`Hata: Hava durumu verisi alınırken sorun oluştu. Lütfen API anahtarınızı kontrol edin.`);
});
}
// **********************************************
// IP Adresinden Konum Bilgisi Alma ve Hava Durumunu Çekme
// **********************************************
function getLocationAndWeather() {
document.getElementById('loading').textContent = 'IP Konumunuzdan Veri Alınıyor...';
// Weather API, sorgu (q) parametresine 'auto:ip' yazıldığında
// otomatik olarak gelen isteğin IP adresini algılayıp o konumu döndürür.
fetchWeatherData('auto:ip');
}
// Kar taneleri oluşturma ve animasyon
function generateSnowflakes() {
const snowflakesContainer = document.querySelector('.snowflakes');
const numberOfSnowflakes = 50; // Kar tanesi sayısı
for (let i = 0; i < numberOfSnowflakes; i++) {
const snowflake = document.createElement('div');
snowflake.classList.add('snowflake');
// Rastgele boyut
const size = Math.random() * 3 + 2; // 2px ile 5px arası
snowflake.style.width = `${size}px`;
snowflake.style.height = `${size}px`;
// Rastgele başlangıç konumu
snowflake.style.left = `${Math.random() * 100}%`;
snowflake.style.top = `${Math.random() * 100 - 10}%`; // Ekranın biraz üstünden başlasın
// Rastgele animasyon süresi ve gecikme
const animationDuration = Math.random() * 15 + 10; // 10s ile 25s arası
snowflake.style.animationDuration = `${animationDuration}s`;
snowflake.style.animationDelay = `${Math.random() * animationDuration}s`;
// Beyaz ve siyah kar taneleri için rastgele renk
if (Math.random() > 0.5) {
snowflake.classList.add('dark');
}
snowflakesContainer.appendChild(snowflake);
}
}
// Uygulamayı Başlat
document.addEventListener('DOMContentLoaded', () => {
// Kar tanelerini oluştur
generateSnowflakes();
// İlk yüklemede IP adresinden konum al
fetchWeatherData('auto:ip');
// Arama butonuna tıklama olayını dinle
document.getElementById('search-button').addEventListener('click', () => {
const city = document.getElementById('city-input').value.trim();
if (city) {
document.getElementById('loading').textContent = `${city} için Hava Durumu Alınıyor...`;
document.getElementById('loading').classList.remove('hidden');
document.getElementById('error').classList.add('hidden');
document.getElementById('weather-info').classList.add('hidden');
fetchWeatherData(city);
} else {
handleError('Lütfen bir şehir adı girin.');
}
});
// Ünlü şehirler butonuna tıklama olayını dinle
document.getElementById('famous-cities-button').addEventListener('click', () => {
document.getElementById('famous-cities-modal').classList.remove('hidden');
});
// Modal kapatma butonu
document.querySelector('.close-button').addEventListener('click', () => {
document.getElementById('famous-cities-modal').classList.add('hidden');
});
// Modal dışına tıklayınca kapatma
window.addEventListener('click', (event) => {
const modal = document.getElementById('famous-cities-modal');
if (event.target === modal) {
modal.classList.add('hidden');
}
});
// Şehir listesindeki elemanlara tıklama
document.getElementById('city-list').addEventListener('click', (event) => {
if (event.target.tagName === 'LI') {
const city = event.target.dataset.city;
if (city) {
document.getElementById('loading').textContent = `${city} için Hava Durumu Alınıyor...`;
document.getElementById('loading').classList.remove('hidden');
document.getElementById('error').classList.add('hidden');
document.getElementById('weather-info').classList.add('hidden');
fetchWeatherData(city);
document.getElementById('famous-cities-modal').classList.add('hidden');
}
}
});
// Enter tuşuna basıldığında da arama yap
document.getElementById('city-input').addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
document.getElementById('search-button').click();
}
});
});
</script>
</body>
</html>