hava-durumu/public/js/app.js

37 lines
1.2 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

async function havaGuncelle() {
try {
const response = await fetch('/api/hava');
const data = await response.json();
data.forEach(function(item) {
const sicaklikElement = document.getElementById(item.id + '-sicaklik');
const nemElement = document.getElementById(item.id + '-nem');
const ruzgarElement = document.getElementById(item.id + '-ruzgar');
if (sicaklikElement) {
sicaklikElement.textContent = Math.round(item.sicaklik) + '°C';
}
if (nemElement) {
nemElement.textContent = '%' + Math.round(item.nem);
}
if (ruzgarElement) {
ruzgarElement.textContent = Math.round(item.ruzgar) + ' km/s';
}
});
const now = new Date();
const timeStr = now.toLocaleTimeString('tr-TR');
document.getElementById('son-guncelleme').textContent = timeStr;
} catch (error) {
console.error('Hava durumu güncelleme hatası:', error);
}
}
window.addEventListener('DOMContentLoaded', function() {
havaGuncelle();
setInterval(havaGuncelle, 3000);
});