From 7d8025372c4bb94c39cbe98df0db4ddb14b97fa0 Mon Sep 17 00:00:00 2001 From: Jesse Hasty <134172009+JesseWx2011@users.noreply.github.com> Date: Fri, 29 Mar 2024 11:49:17 -0400 Subject: [PATCH] V2.2 Build 1 --- index.html | 3 +- notification.js | 50 ++++++++---------- scriptcc.js | 105 ++++++++++++++++++------------------- stylecurrentconditions.css | 2 +- 4 files changed, 78 insertions(+), 82 deletions(-) diff --git a/index.html b/index.html index e441ca1..a08828c 100644 --- a/index.html +++ b/index.html @@ -26,6 +26,7 @@

Dec 31 1969 11:59 PM

+
@@ -190,7 +191,7 @@

Radar Unav

- +
diff --git a/notification.js b/notification.js index cb4dba5..7a1a6bf 100644 --- a/notification.js +++ b/notification.js @@ -5,31 +5,27 @@ function notifyMe() { Notification.requestPermission().then((permission) => { if (permission === "granted") { // Do nothing - } - }); - } - -litening(); -const alerts = `https://api.aerisapi.com/lightning/flash/${city}?format=json&radius=25mi&minradius=0mi&limit=10&client_id=${client_id}&client_secret=${client_secret} ` -async function litening() { - const responsee = await fetch(alerts) - const data = await responsee.json() - const {response} = data - console.log(data) - var liteningaudio = "lightning.mp3" - if (response[0].relativeTo.distanceMI !== null) { - const notification = new Notification("Alert:", { - body: `Lightning struck ${response[0].relativeTo.distanceMI} miles (${response[0].relativeTo.distanceKM} km) ${response[0].relativeTo.bearingENG} of this Location in ${city}.`, - icon: "lightning.svg", - }); - setTimeout(() => { notification.close() }, 5000); - alertaudio.innerHTML = `` - if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)){ - alert(`Lightning struck ${response[0].relativeTo.distanceMI} miles (${response[0].relativeTo.distanceKM} km) ${response[0].relativeTo.bearingENG} of this Location in ${city}.`) - } - -litening() + }})}; + litening(); + const alerts = `https://api.aerisapi.com/lightning/flash/${city}?format=json&radius=25mi&minradius=0mi&limit=10&client_id=${client_id}&client_secret=${client_secret} ` + async function litening() { + const responsee = await fetch(alerts) + const data = await responsee.json() + const {response} = data + console.log(data) + var liteningaudio = "lightning.mp3" + if (response[0].relativeTo.distanceMI !== null) { + const notification = new Notification("Lightning Alert:", { + body: `Lightning struck ${response[0].relativeTo.distanceMI} miles (${response[0].relativeTo.distanceKM} km) ${response[0].relativeTo.bearingENG} of this Location in ${city}.`, + icon: "lightning.svg", + audio: new Audio('lightning.mp3'), + }); + document.getElementById("lightningbutton").style.display = "block" + alertaudio.innerHTML = `` + if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)){ + // true for mobile device + alert(`Lightning struck ${response[0].relativeTo.distanceMI} miles (${response[0].relativeTo.distanceKM} km) ${response[0].relativeTo.bearingENG} of this Location in ${city}.`) + }}}; + litening() } -} -} -notifyMe() +notifyMe() \ No newline at end of file diff --git a/scriptcc.js b/scriptcc.js index c7f503c..fb05d26 100644 --- a/scriptcc.js +++ b/scriptcc.js @@ -1,15 +1,3 @@ -navigator.geolocation.getCurrentPosition(function(location) { - console.log(location.coords.latitude); - console.log(location.coords.longitude); - console.log(location.coords.accuracy); - var newlocs = { - nlat: location.coords.latitude, - nlon: location.coords.longitude, - } - console.log(newlocs) - }); - - // Get Params // Function for Parameters @@ -32,7 +20,7 @@ const api_url = `https://api.aerisapi.com/conditions/${city}?format=json&plimit= async function getWx() { const responsee = await fetch(api_url); const data = await responsee.json(); - const {response} = data; + const { response } = data; console.log(data); var lat = `${response[0].loc.lat}`; var lon = `${response[0].loc.long}`; @@ -43,12 +31,13 @@ async function getWx() { function error() { if (error.code = "maxhits_daily") { var client_id = `wgE96YE3scTQLKjnqiMsv`; // This is your client id from aeris weather. -var client_secret = `SVG2gQFV8y9DjKR0BRY9wPoSLvrMrIqF9Lq2IYaY` // This is your client secret from aeris weather. + var client_secret = `SVG2gQFV8y9DjKR0BRY9wPoSLvrMrIqF9Lq2IYaY` // This is your client secret from aeris weather. } } error() console.log(cordinates) - document.getElementById('cityname').innerHTML = `
Weather for ${response[0].place.name}, ${response[0].place.state}, ${response[0].place.country}
`; + const rainr = (response[0].periods[0].precipRateIN ).toFixed(3) + document.getElementById('cityname').innerHTML = `
Weather for ${city}
`; document.getElementById('temp').innerHTML = `${response[0].periods[0].tempF}°F (${response[0].periods[0].tempC}°C)`; document.getElementById('title').innerHTML = `Deluge - Weather for ${response[0].place.name}, ${response[0].place.state}` document.getElementById('icon').innerHTML = ``; @@ -60,11 +49,11 @@ var client_secret = `SVG2gQFV8y9DjKR0BRY9wPoSLvrMrIqF9Lq2IYaY` // This is your c document.getElementById('dewvalue').innerHTML = `${response[0].periods[0].dewpointF}°F`; document.getElementById('visibilityvalue').innerHTML = `${response[0].periods[0].visibilityMI} mi`; document.getElementById('snowdepthvalue').innerHTML = `${response[0].periods[0].snowDepthIN} in.`; - document.getElementById('rainrvalue').innerHTML = `${response[0].periods[0].precipRateIN}in./hr`; + document.getElementById('rainrvalue').innerHTML = `${rainr} in./hr`; document.getElementById('solarvalue').innerHTML = `${response[0].periods[0].solradWM2} watts/m²`; document.getElementById("windmetric").innerHTML = `${response[0].periods[0].windSpeedKPH} km/h`; document.getElementById("radarimage").innerHTML = `` -// Function to get the UV Value + // Function to get the UV Value if (response[0].periods[0].uvi < 1) { uvvalue.innerHTML = `${response[0].periods[0].uvi} - Very Low` } if (response[0].periods[0].uvi >= 1) { @@ -80,31 +69,31 @@ var client_secret = `SVG2gQFV8y9DjKR0BRY9wPoSLvrMrIqF9Lq2IYaY` // This is your c } // Function to get the visibility function visibility() { - var visibility = response[0].periods[0].visibilityMI - if (visibility === 9.942) { - visibilitytext.innerHTML = "Clear Skies"; - visibilityvalue.innerHTML = `10 mi` - } if (visibility <= 7.5) { - visibilitytext.innerHTML = "Light Haze, Patchy Clouds" - } if (visibility <= 2.485) { - visibilitytext.innerHTML = "Haze" - } if (visibility <= 1.24) { - visibilitytext.innerHTML = `Thin Fog` - } if (visibility <= 0.621) { - visibilitytext.innerHTML = `Light Fog` - } if (visibility <= 0.310) { - visibilitytext.innerHTML = `Moderate Fog` - } if (visibility <= 0.124274) { - visibilitytext.innerHTML = `Thick Fog` - } if (visibility < 0.031) { - visibilitytext.innerHTML = `Extremely Dense Fog` -} + var visibility = response[0].periods[0].visibilityMI + if (visibility === 9.942) { + visibilitytext.innerHTML = "Clear Skies"; + visibilityvalue.innerHTML = `10 mi` + } if (visibility <= 7.5) { + visibilitytext.innerHTML = "Light Haze, Patchy Clouds" + } if (visibility <= 2.485) { + visibilitytext.innerHTML = "Haze" + } if (visibility <= 1.24) { + visibilitytext.innerHTML = `Thin Fog` + } if (visibility <= 0.621) { + visibilitytext.innerHTML = `Light Fog` + } if (visibility <= 0.310) { + visibilitytext.innerHTML = `Moderate Fog` + } if (visibility <= 0.124274) { + visibilitytext.innerHTML = `Thick Fog` + } if (visibility < 0.031) { + visibilitytext.innerHTML = `Extremely Dense Fog` + } } visibility() -// Function for UV + // Function for UV if (response[0].periods[0].uvi >= 5) { uvvaluedesc.innerHTML = "Put on Sunscreen when outdoors." - } + } document.getElementById('feelslike').innerHTML = `Feels Like ${response[0].periods[0].feelslikeF}°F (${response[0].periods[0].feelslikeC}°C)`; } getWx(); @@ -162,30 +151,31 @@ async function getForecast() { // Extra information for ice, rain, snow, or sleet accumulation. + if (accumulation0 === undefined) { + var accumulation0 = "" + var chanceof = "" + } if (accumulation1 === undefined) { + var accumulation1 = "" + var chanceof1 = "" + } if (response[0].periods[0].iceaccumIN !== 0) { var accumulation0 = `Ice Accumulation around ${response[0].periods[0].iceaccumIN} in.` - var chanceof = `Chance of Precipiation ${100 - response[0].periods[0].sky}.` + var chanceof = `Chance of Precipiation ${ response[0].periods[0].sky}%.` } if (response[0].periods[1].iceaccumIN !== 0) { var accumulation1 = `Ice Accumulation around ${response[0].periods[1].iceaccumIN} in.` - var chanceof1 = `Chance of Precipiation ${100 - response[0].periods[0].sky}.` + var chanceof1 = `Chance of Precipiation ${ response[0].periods[0].sky}%.` } if (response[0].periods[0].precipIN !== 0) { var accumulation0 = `Rain Accumulation around ${response[0].periods[0].precipIN} in.` - var chanceof = `Chance of Rain ${100 - response[0].periods[0].sky}.` + var chanceof = `Chance of Rain ${ response[0].periods[0].sky}%.` } if (response[0].periods[1].precipIN !== 0) { var accumulation1 = `Rain Accumulation around ${response[0].periods[1].precipIN} in.` - var chanceof1 = `Chance of Precipiation ${100 - response[0].periods[1].sky}.` + var chanceof1 = `Chance of Precipiation ${ response[0].periods[1].sky}%.` } if (response[0].periods[0].snowIN !== 0) { accumulation0 = `Snow Accumulation around ${response[0].periods[0].snowIN} in.` - var chanceof = `Chance of Snow ${100 - response[0].periods[0].sky}.` + var chanceof = `Chance of Snow ${ response[0].periods[0].sky}%.` } if (response[0].periods[1].snowIN !== 0) { var accumulation1 = `Snow Accumulation around ${response[0].periods[1].snowIN} in.` - var chanceof1 = `Chance of Snow ${100 - response[0].periods[1].sky}.` - } if (accumulation0 = "undenfined") { - var accumulation0 = "" - var chanceof = "" - } if (accumulation1 = "undenfined") { - var accumulation1 = "" - var chanceof1 = "" + var chanceof1 = `Chance of Snow ${ response[0].periods[1].sky}%.` } console.log(chanceof) // Detailed Information Container @@ -224,8 +214,8 @@ async function getAlert() { } getAlert(); function getSearch() { -const search = document.getElementById('searchButton') -const searchForm = document.getElementById('searchInput'); + const search = document.getElementById('searchButton') + const searchForm = document.getElementById('searchInput'); searchButton.addEventListener("click", function () { window.location = `./index.html?city=${searchInput.value}` @@ -239,4 +229,13 @@ getSearch(); function lightningredirect() { window.location = `./lightning.html?city=${city}` } -lightningredirect() \ No newline at end of file +lightningredirect() +function updateveryminute() { + setInterval(getWx, 60000) + document.getElementById("linkd").innerHTML = `Change to archived updates.` + document.getElementById("linkd").id = "changeme" + + changeme.addEventListener("click", function() { + window.location = `./index.html?city=${city}` + }) +} \ No newline at end of file diff --git a/stylecurrentconditions.css b/stylecurrentconditions.css index 6e2f1ff..6f477c9 100644 --- a/stylecurrentconditions.css +++ b/stylecurrentconditions.css @@ -113,7 +113,7 @@ body { .daycontainer { align-content: center; - margin-top: 130px; + margin-top: 123px; width: 1300px; height: fit-content; background-color: skyblue;