-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
215 lines (205 loc) · 10.8 KB
/
script.js
File metadata and controls
215 lines (205 loc) · 10.8 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
// text box fetching
const ahnmetarbox = document.getElementById("ahnmetar")
const cnimetarbox = document.getElementById("cnimetar")
const ffcdiscussbox = document.getElementById("ffcdiscussion")
const ffchwobox = document.getElementById("ffchwo")
const ahncli = document.getElementById("ahncli")
const atlcli = document.getElementById("atlcli")
const alertbox = document.getElementById("alertbox")
const statewide = document.getElementById('alertstatewide');
const nationwide = document.getElementById('alertnationwide');
async function updateTextBoxes() {
try {
fetch('https://mesonet.agron.iastate.edu/cgi-bin/afos/retrieve.py?pil=AFDFFC').then(response => response.text()).then(data => {ffcdiscussbox.textContent = data})
} catch (error) {
ffcdiscussbox.textContent = "Discussion failed to load. Maybe that's not a bad thing :-)"
}
try {
fetch('https://mesonet.agron.iastate.edu/cgi-bin/afos/retrieve.py?pil=HWOFFC').then(response => response.text()).then(data => {ffchwobox.textContent = data})
} catch (error) {
ffchwobox.textContent = "HWO failed to load. Maybe that's not a bad thing :-)"
}
// pretty up the metars cause they are in csv
try {
fetch('https://mesonet.agron.iastate.edu/cgi-bin/request/asos.py?data=metar&station=AHN&hours=24').then(response => response.text())
.then(metarText => {
const rows = metarText.trim().split('\n');
const metar = rows.map(row => {
const columns = row.split(',');
return columns[2] ? columns[2].trim():'';
});
const metardata = metar.join('\n')
ahnmetarbox.textContent = metardata
})
} catch (error) {
ahnmetarbox.textContent = "AHN METAR failed to load. :-("
}
try {
fetch('https://mesonet.agron.iastate.edu/cgi-bin/request/asos.py?data=metar&station=CNI&hours=24').then(response => response.text())
.then(metarText => {
const rows = metarText.trim().split('\n');
const metar = rows.map(row => {
const columns = row.split(',');
return columns[2] ? columns[2].trim():'';
});
const metardata = metar.join('\n')
cnimetarbox.textContent = metardata
})
} catch (error) {
cninmetarbox.textContent = "CNI METAR failed to load. :-("
}
try {
fetch('https://mesonet.agron.iastate.edu/cgi-bin/afos/retrieve.py?pil=CLIAHN').then(response => response.text()).then(data => {ahncli.textContent = data})
} catch (error) {
ahncli.textContent = "AHN Climate Summary failed to load. :-("
}
try {
fetch('https://mesonet.agron.iastate.edu/cgi-bin/afos/retrieve.py?pil=CLIATL').then(response => response.text()).then(data => {atlcli.textContent = data})
} catch (error) {
atlcli.textContent = "ATL Climate Summary failed to load. :-("
}
}
async function updateAlertBox() {
try {
if (statewide.checked == true) {
var url = 'https://api.weather.gov/alerts/active?area=GA'
}
else if (nationwide.checked == true) {
var url = 'https://api.weather.gov/alerts/active'
}
else {
var url = 'https://api.weather.gov/alerts/active?point=33.94872107111243,-83.3752234533988'
}
const response = await fetch(url)
const data = await response.json();
if (data.features.length > 0) {
let alertMessages = data.features.map(alert => {
const properties = alert.properties;
return `<strong>${properties.event}</strong>: ${properties.parameters.NWSheadline}<br><details><summary>More:</summary><p class="alertdetail">Issuing office: ${properties.senderName}<br>${properties.description}</p></details>`;
});
alertbox.innerHTML = alertMessages.join('<br>');
} else {
alertbox.innerHTML = 'Nothing is happening! ...Really? That\'s boring.';
}
}
catch (error) {
alertbox.textContent = "Alerts failed to load. I sure hope nothing is happening today..."
console.log(`alertbox failure: ${error}`)
}
}
statewide.addEventListener('click', updateAlertBox)
nationwide.addEventListener('click', updateAlertBox)
// day selector for wpc/spc stuff
const wpcimage = document.getElementById("wpcimage")
const wpc1 = document.getElementById("wpc1")
wpc1.addEventListener('click', event => {event.preventDefault(); wpcimage.src = 'https://www.wpc.ncep.noaa.gov/NationalForecastChart/staticmaps/noaad1.png'})
const wpc2 = document.getElementById("wpc2")
wpc2.addEventListener('click', event => {event.preventDefault(); wpcimage.src = 'https://www.wpc.ncep.noaa.gov/NationalForecastChart/staticmaps/noaad2.png'})
const wpc3 = document.getElementById("wpc3")
wpc3.addEventListener('click', event => {event.preventDefault(); wpcimage.src = 'https://www.wpc.ncep.noaa.gov/NationalForecastChart/staticmaps/noaad3.png'})
const spcimage = document.getElementById("spcimage")
const spc1 = document.getElementById("spc1")
spc1.addEventListener('click', event => {event.preventDefault(); spcimage.src = 'https://www.spc.noaa.gov/products/outlook/day1otlk.png'})
const spc2 = document.getElementById("spc2")
spc2.addEventListener('click', event => {event.preventDefault(); spcimage.src = 'https://www.spc.noaa.gov/products/outlook/day2otlk.png'})
const spc3 = document.getElementById("spc3")
spc3.addEventListener('click', event => {event.preventDefault(); spcimage.src = 'https://www.spc.noaa.gov/products/outlook/day3otlk.png'})
const erainimage = document.getElementById("erainimage")
const rain1 = document.getElementById("rain1")
rain1.addEventListener('click', event => {event.preventDefault(); erainimage.src = 'https://www.wpc.ncep.noaa.gov/qpf/94ewbg.gif'})
const rain2 = document.getElementById("rain2")
rain2.addEventListener('click', event => {event.preventDefault(); erainimage.src = 'https://www.wpc.ncep.noaa.gov/qpf/98ewbg.gif'})
const rain3 = document.getElementById("rain3")
rain3.addEventListener('click', event => {event.preventDefault(); erainimage.src = 'https://www.wpc.ncep.noaa.gov/qpf/99ewbg.gif'})
// hour selector for skewts
const ahnskewt = document.getElementById("ahnwrfst")
const ahnst12 = document.getElementById("ahnst12")
ahnst12.addEventListener('click', event => {event.preventDefault(); ahnwrfst.src = 'https://storage.googleapis.com/uga-wrf-website/outputs/latest/skewt/ahn/hour_12.png'})
const ahnst24 = document.getElementById("ahnst24")
ahnst24.addEventListener('click', event => {event.preventDefault(); ahnwrfst.src = 'https://storage.googleapis.com/uga-wrf-website/outputs/latest/skewt/ahn/hour_24.png'})
const ahnst36 = document.getElementById("ahnst36")
ahnst36.addEventListener('click', event => {event.preventDefault(); ahnwrfst.src = 'https://storage.googleapis.com/uga-wrf-website/outputs/latest/skewt/ahn/hour_36.png'})
const ahnst48 = document.getElementById("ahnst48")
ahnst48.addEventListener('click', event => {event.preventDefault(); ahnwrfst.src = 'https://storage.googleapis.com/uga-wrf-website/outputs/latest/skewt/ahn/hour_48.png'})
const ffcskewt = document.getElementById("ffcwrfst")
const ffcst12 = document.getElementById("ffcst12")
ffcst12.addEventListener('click', event => {event.preventDefault(); ffcwrfst.src = 'https://storage.googleapis.com/uga-wrf-website/outputs/latest/skewt/ffc/hour_12.png'})
const ffcst24 = document.getElementById("ffcst24")
ffcst24.addEventListener('click', event => {event.preventDefault(); ffcwrfst.src = 'https://storage.googleapis.com/uga-wrf-website/outputs/latest/skewt/ffc/hour_24.png'})
const ffcst36 = document.getElementById("ffcst36")
ffcst36.addEventListener('click', event => {event.preventDefault(); ffcwrfst.src = 'https://storage.googleapis.com/uga-wrf-website/outputs/latest/skewt/ffc/hour_36.png'})
const ffcst48 = document.getElementById("ffcst48")
ffcst48.addEventListener('click', event => {event.preventDefault(); ffcwrfst.src = 'https://storage.googleapis.com/uga-wrf-website/outputs/latest/skewt/ffc/hour_48.png'})
// forecast generator
const forecastForm = document.getElementById('forecastForm')
forecastForm.addEventListener('submit', function (event){
event.preventDefault();
const floc = document.getElementById('floc')
const flo = document.getElementById('flo')
const fopop = document.getElementById('fopop')
const fhi = document.getElementById('fhi')
const fapop = document.getElementById('fapop')
const fstory = document.getElementById('fstory')
const submittedforecast = document.getElementById("submittedforecast")
submittedforecast.innerHTML = `Forecast for ${floc.value}<br>Lo: ${flo.value}<br>Early PoP: ${fopop.value}<br>Hi: ${fhi.value}<br>Late PoP: ${fapop.value}<br>${fstory.value}`
})
// autoplot refresh
const iemrefreshbutton = document.getElementById('iemrefresher')
const wwamap = document.getElementById('iemwwa')
const wwasemap = document.getElementById('iemwwase')
const tempmap = document.getElementById('iemtemp')
const dewpmap = document.getElementById('iemdewp')
iemrefreshbutton.addEventListener('click', function(event) {
console.log('refreshing iem plots')
wwamap.src = ""
wwasemap.src = ""
tempmap.src = ""
dewpmap.src = ""
wwamap.src = "https://mesonet.agron.iastate.edu/plotting/auto/plot/247/opt:active::csector:nws::add:stats::sc:yes::dpi:100::_cb:1.png"
wwasemap.src = "https://mesonet.agron.iastate.edu/plotting/auto/plot/247/opt:active::csector:southeast::add:stats::sc:yes::dpi:100::_cb:1.png"
tempmap.src = "https://mesonet.agron.iastate.edu/plotting/auto/plot/192/t:state::network:WFO::wfo:DMX::state:GA::v:tmpf::cmap:RdYlBu_r::_r:t::dpi:100::_cb:1.png"
dewpmap.src = "https://mesonet.agron.iastate.edu/plotting/auto/plot/192/t:state::network:WFO::wfo:DMX::state:GA::v:dwpf::below:-20::cmap:jet::_r:t::dpi:100::_cb:1.png"
})
// top button
let mybutton = document.getElementById("topBtn");
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 400 || document.documentElement.scrollTop > 400) {
mybutton.style.display = "block";
} else {
mybutton.style.display = "none";
}
}
function toTop() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
// start page
window.onload = function () {
updateTextBoxes()
updateAlertBox()
}
setTimeout(function() { window.location.reload(); }, 600000)
// rng
const seed = Math.floor(Math.random() * 50) + 1
if (seed == 1) {
document.title = "hi :3"
}
else if (seed == 3) {
document.title = "guys, i'm new to meteorology is this bad"
}
else if (seed == 5) {
document.title = "it's intuitive!"
}
else if (seed == 7) {
document.title = "we could all afford..."
}
else if (seed == 9) {
document.title = "don't bust the forecast!"
}
else if (seed == 11) {
document.title = "making forecasting TOO easy"
}
else {
document.title = "lucemapwall"
}