Skip to content

Commit 379f7a7

Browse files
Update index.js
1 parent 0463c4d commit 379f7a7

1 file changed

Lines changed: 81 additions & 81 deletions

File tree

‎Wether Report web site/index.js‎

Lines changed: 81 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const weatherHumidity = document.getElementById("Weather_humidity_accoding_to_th
2323
const uvIndexElement = document.getElementById("UV_Index_accoding_to_the_weather");
2424
const uvIndexDescription = document.getElementById("UV_Index_description_accoding_to_the_weather");
2525
const uvIndexLowToday = document.getElementById("UV_Index_Today_Low_accoding_to_the_weather");
26-
const uvIndexMediumToday = document.getElementById("UV_Index_Today_Medium_accoding_to_the_weather");
26+
const uvIndexMediumToday = document.getElementById("UV_Index_Today_Medium_accoding_to_the_weather");
2727
const uvIndexHighToday = document.getElementById("UV_Index_Today_High_accoding_to_the_weather");
2828

2929
// Current Air Index Elements In Air Card
@@ -81,7 +81,7 @@ function clock() {
8181
// display user machine time and date
8282
if (hours < 10) {
8383
currentTime.innerHTML = `0${hours}:${minutes}:${seconds}`;
84-
}
84+
}
8585

8686
if (minutes < 10) {
8787
currentTime.innerHTML = `${hours}:0${minutes}:${seconds}`;
@@ -95,17 +95,17 @@ function clock() {
9595
// get user machine time and date and display WellCome Text in the page
9696
if (hours >= 0 && hours < 12) {
9797
Good_Wellcome_text = "Good Morning 👋";
98-
}
98+
}
9999
else if (hours >= 12 && hours < 15) {
100100
Good_Wellcome_text = "Good Afternoon 👋";
101-
}
102-
else if (hours >= 15 && hours < 18){
101+
}
102+
else if (hours >= 15 && hours < 18) {
103103
Good_Wellcome_text = "Good Evening 👋";
104104
}
105105
else {
106106
Good_Wellcome_text = "Good Night 👋";
107-
}
108-
107+
}
108+
109109
// display WellCome Text in the page
110110
goodWelcomeText.innerHTML = Good_Wellcome_text;
111111

@@ -128,7 +128,7 @@ setInterval(clock, 1000);
128128

129129
geoFindMe();
130130

131-
function geoFindMe() {
131+
function geoFindMe() {
132132

133133
function success(position) {
134134
latitude = position.coords.latitude;
@@ -146,7 +146,7 @@ function geoFindMe() {
146146

147147
if (!navigator.geolocation) {
148148
alert("Geolocation is not supported by your browser");
149-
}
149+
}
150150
else {
151151
navigator.geolocation.getCurrentPosition(success, error);
152152
}
@@ -158,11 +158,11 @@ function geoFindMe() {
158158
// ==============================================================================================================================================================//
159159
// ==============================================================================================================================================================//
160160

161-
161+
162162

163163
// Call The API
164-
const api = {
165-
key: "701c8c6e75143284523611d549c79661",
164+
const api = {
165+
key: "",
166166
}
167167

168168

@@ -185,7 +185,7 @@ function getWeather(lan, lon) {
185185
function displayWeather(weather) {
186186
locationDisplay.innerHTML = `${weather.name}, ${weather.sys.country}`;
187187

188-
weatherTemperature.innerHTML = `${Math.round ( (weather.main.temp) - 273.15 ) }°C`;
188+
weatherTemperature.innerHTML = `${Math.round((weather.main.temp) - 273.15)}°C`;
189189
weatherDescription.innerHTML = weather.weather[0].description;
190190

191191
// if (weather.weather[0].description == "mist || Few clouds || Scattered clouds || Broken clouds || Overcast clouds || Clear sky") {
@@ -204,8 +204,8 @@ function displayWeather(weather) {
204204
weatherVisibility.innerHTML = `${weather.visibility / 1000} km`;
205205
weatherHumidity.innerHTML = `${weather.main.humidity}%`;
206206

207-
const feelsTemperature = Math.round ( (weather.main.feels_like) - 273.15 );
208-
sunTemperature.innerHTML = `${feelsTemperature}°C`;
207+
const feelsTemperature = Math.round((weather.main.feels_like) - 273.15);
208+
sunTemperature.innerHTML = `${feelsTemperature}°C`;
209209

210210
const sunrise = weather.sys.sunrise;
211211
const date = new Date(sunrise * 1000);
@@ -253,20 +253,20 @@ function displayUVIndex(uvIndex) {
253253
}
254254

255255

256-
const date = new Date();
257-
const localTime = date.toISOString().split('T')[0];
258-
const data = uvIndex;
259-
const filteredForecast = data.forecast.filter(entry => entry.time.startsWith(localTime));
260-
const uviArray = filteredForecast.map(entry => entry.uvi);
256+
const date = new Date();
257+
const localTime = date.toISOString().split('T')[0];
258+
const data = uvIndex;
259+
const filteredForecast = data.forecast.filter(entry => entry.time.startsWith(localTime));
260+
const uviArray = filteredForecast.map(entry => entry.uvi);
261261

262-
const uviMin = Math.min(...uviArray);
263-
uvIndexLowToday.innerHTML = uviMin;
262+
const uviMin = Math.min(...uviArray);
263+
uvIndexLowToday.innerHTML = uviMin;
264264

265-
const uviMax = Math.max(...uviArray);
266-
uvIndexHighToday.innerHTML = uviMax;
265+
const uviMax = Math.max(...uviArray);
266+
uvIndexHighToday.innerHTML = uviMax;
267267

268-
const uviAvg = Math.round(uviArray.reduce((sum, currentElement) => sum + currentElement, 0) / uviArray.length);
269-
uvIndexMediumToday.innerHTML = uviAvg;
268+
const uviAvg = Math.round(uviArray.reduce((sum, currentElement) => sum + currentElement, 0) / uviArray.length);
269+
uvIndexMediumToday.innerHTML = uviAvg;
270270

271271

272272
// This Part is only for Sri Lanka UV Index History.
@@ -276,36 +276,36 @@ uvIndexMediumToday.innerHTML = uviAvg;
276276

277277
var UVMorningTotal = 0;
278278
var UVMorning = [];
279-
for (let i = 6; i < 10; i++) {
280-
UVMorning.push(uvIndex.forecast[i].uvi);
281-
UVMorningTotal += uvIndex.forecast[i].uvi;
282-
}
279+
for (let i = 6; i < 10; i++) {
280+
UVMorning.push(uvIndex.forecast[i].uvi);
281+
UVMorningTotal += uvIndex.forecast[i].uvi;
282+
}
283283
var UVMorningAvg = Math.round(UVMorningTotal / UVMorning.length);
284284
if (UVMorningAvg == 0) {
285-
UVMorningAvg = Math.max(...UVMorning);
286-
UVMorningAvg = UVMorningAvg * 10;
285+
UVMorningAvg = Math.max(...UVMorning);
286+
UVMorningAvg = UVMorningAvg * 10;
287287
}
288288

289289

290290
var UVAfternoonTotal = 0;
291291
var UVAfternoon = [];
292-
for (let i = 10; i < 14; i++) {
293-
UVAfternoon.push(uvIndex.forecast[i].uvi);
294-
UVAfternoonTotal += uvIndex.forecast[i].uvi;
295-
}
292+
for (let i = 10; i < 14; i++) {
293+
UVAfternoon.push(uvIndex.forecast[i].uvi);
294+
UVAfternoonTotal += uvIndex.forecast[i].uvi;
295+
}
296296
var UVAfternoonAvg = Math.round(UVAfternoonTotal / UVAfternoon.length);
297297
if (UVAfternoonAvg == 0) {
298-
UVAfternoonAvg = Math.max(...UVAfternoon);
299-
UVAfternoonAvg = UVAfternoonAvg * 10;
298+
UVAfternoonAvg = Math.max(...UVAfternoon);
299+
UVAfternoonAvg = UVAfternoonAvg * 10;
300300
}
301301

302302

303303
var UVEveningTotal = 0;
304304
var UVEvening = [];
305-
for (let i = 14; i < 18; i++) {
306-
UVEvening.push(uvIndex.forecast[i].uvi);
307-
UVEveningTotal += uvIndex.forecast[i].uvi;
308-
}
305+
for (let i = 14; i < 18; i++) {
306+
UVEvening.push(uvIndex.forecast[i].uvi);
307+
UVEveningTotal += uvIndex.forecast[i].uvi;
308+
}
309309
var UVEveningAvg = Math.round(UVEveningTotal / UVEvening.length);
310310
if (UVEveningAvg == 0) {
311311
UVEveningAvg = Math.max(...UVEvening);
@@ -315,18 +315,18 @@ uvIndexMediumToday.innerHTML = uviAvg;
315315

316316
var UVNightTotal = 0;
317317
var UVNight = [];
318-
for (let i = 18; i < 22; i++) {
319-
UVNight.push(uvIndex.forecast[i].uvi);
320-
UVNightTotal += uvIndex.forecast[i].uvi;
321-
}
318+
for (let i = 18; i < 22; i++) {
319+
UVNight.push(uvIndex.forecast[i].uvi);
320+
UVNightTotal += uvIndex.forecast[i].uvi;
321+
}
322322
var UVNightAvg = Math.round(UVNightTotal / UVNight.length);
323323
if (UVNightAvg == 0) {
324324
UVNightAvg = Math.max(...UVNight);
325325
UVNightAvg = UVNightAvg * 10;
326326
}
327327

328328

329-
uvIndexTodayMorning.innerHTML = UVMorningAvg;
329+
uvIndexTodayMorning.innerHTML = UVMorningAvg;
330330
uvIndexTodayAfternoon.innerHTML = UVAfternoonAvg;
331331
uvIndexTodayEvening.innerHTML = UVEveningAvg;
332332
uvIndexTodayNight.innerHTML = UVNightAvg;
@@ -338,39 +338,39 @@ uvIndexMediumToday.innerHTML = uviAvg;
338338
gradient.addColorStop(1, 'rgba(255, 255, 255, 0)');
339339

340340
new Chart(ctx, {
341-
type: 'line',
342-
data: {
343-
labels: ['Morning', 'Afternoon', 'Evening', 'Night'],
344-
datasets: [{
345-
data: [UVMorningAvg, UVAfternoonAvg, UVEveningAvg, UVNightAvg],
346-
borderColor: '#FF9421',
347-
borderWidth: 2,
348-
fill: true,
349-
backgroundColor: gradient,
350-
tension: 0.4, // Smooth the line
351-
pointBackgroundColor: '#FF9421',
352-
pointBorderColor: '#FFFFFF',
353-
pointBorderWidth: 2,
354-
pointRadius: 5,
355-
}]
341+
type: 'line',
342+
data: {
343+
labels: ['Morning', 'Afternoon', 'Evening', 'Night'],
344+
datasets: [{
345+
data: [UVMorningAvg, UVAfternoonAvg, UVEveningAvg, UVNightAvg],
346+
borderColor: '#FF9421',
347+
borderWidth: 2,
348+
fill: true,
349+
backgroundColor: gradient,
350+
tension: 0.4, // Smooth the line
351+
pointBackgroundColor: '#FF9421',
352+
pointBorderColor: '#FFFFFF',
353+
pointBorderWidth: 2,
354+
pointRadius: 5,
355+
}]
356+
},
357+
options: {
358+
responsive: true,
359+
maintainAspectRatio: false,
360+
plugins: {
361+
legend: {
362+
display: false,
363+
}
356364
},
357-
options: {
358-
responsive: true,
359-
maintainAspectRatio: false,
360-
plugins: {
361-
legend: {
362-
display: false,
363-
}
364-
},
365-
scales: {
366-
x: {
367-
display: false,
368-
},
369-
y: {
370-
display: false,
371-
}
372-
}
365+
scales: {
366+
x: {
367+
display: false,
368+
},
369+
y: {
370+
display: false,
371+
}
373372
}
373+
}
374374
});
375375

376376
}
@@ -410,7 +410,7 @@ function displayAirIndex(airIndex) {
410410
airIndexQualitativeName.innerHTML = "Hazardous";
411411
}
412412

413-
airIndexCarbonMonoxide.innerHTML = `${Math.round(airIndex.list[0].components.co / 10)} %`;
413+
airIndexCarbonMonoxide.innerHTML = `${Math.round(airIndex.list[0].components.co / 10)} %`;
414414
airIndexNitrogenMonoxide.innerHTML = `${Math.round([airIndex.list[0].components.no2 / 10] * 10)} %`;
415415
airIndexOzone.innerHTML = `${Math.round(airIndex.list[0].components.o3 / 10)} %`;
416416
}
@@ -430,15 +430,15 @@ const time = Math.floor(tomorrow.getTime() / 1000);
430430
// Get The Tomorrow Weather Data
431431
function getTomorrowWeather(lan, lon) {
432432
fetch(`https://api.openweathermap.org/data/3.0/onecall?lat=${lan}&lon=${lon}&appid=${api.key}`)
433-
433+
434434
.then(tomorrowWeather => {
435435
return tomorrowWeather.json();
436436
}).then(displayTomorrowWeather);
437437
}
438438

439439
// Display The Tomorrow Weather Data
440440
function displayTomorrowWeather(tomorrowWeather) {
441-
tomorrowWeatherTemperature.innerHTML = `${Math.round(tomorrowWeather.daily[0].temp.min - 273.15 )}°C`;
441+
tomorrowWeatherTemperature.innerHTML = `${Math.round(tomorrowWeather.daily[0].temp.min - 273.15)}°C`;
442442
tomorrowWeatherDescription.innerHTML = tomorrowWeather.daily[0].summary;
443443
}
444444

0 commit comments

Comments
 (0)