Use random ID values to prevent ID conflicts
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
{{- $format := splitList "\n" (trim .Data.format) -}}
|
||||
{{- $title := replace " " "" .Title -}}
|
||||
{{- $randID := randAlphaNum 10 -}}
|
||||
<div class="card-header">
|
||||
<a class="card-header-title" href="{{.URL}}">
|
||||
{{if ne .Icon ""}}
|
||||
@@ -9,10 +9,9 @@
|
||||
</a>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<p id="{{$title}}LoadingText">Loading...</p>
|
||||
{{range $_, $accessStr := $format}}
|
||||
{{- $id := printf `%s_%s` $title (b64enc $accessStr) -}}
|
||||
<p id="{{$id}}"></p>
|
||||
<p id="APILoadingText_{{$randID}}">Loading...</p>
|
||||
{{range $index, $fmtStr := $format}}
|
||||
<div id="{{printf `APIElement%d_%s` $index $randID}}"></div>
|
||||
{{end}}
|
||||
</div>
|
||||
{{if .Data.footer}}
|
||||
@@ -25,10 +24,9 @@
|
||||
request.open('GET', "{{proxy .URL}}", true)
|
||||
request.onload = function () {
|
||||
const data = JSON.parse(this.response)
|
||||
document.getElementById("{{$title}}LoadingText").classList.add("is-hidden")
|
||||
{{range $_, $accessStr := $format}}
|
||||
{{- $id := printf `%s_%s` $title (b64enc $accessStr) -}}
|
||||
document.getElementById("{{$id}}").innerHTML = `{{unescJS (trim $accessStr)}}`
|
||||
document.getElementById("APILoadingText_{{$randID}}").classList.add("is-hidden")
|
||||
{{range $index, $fmtStr := $format}}
|
||||
document.getElementById("{{printf `APIElement%d_%s` $index $randID}}").innerHTML = `{{unescJS (trim $fmtStr)}}`
|
||||
{{end}}
|
||||
}
|
||||
request.send()
|
||||
|
@@ -1,3 +1,4 @@
|
||||
{{- $randID := randAlphaNum 10 -}}
|
||||
<div class="card-header">
|
||||
<a class="card-header-title" href="{{.URL}}">
|
||||
{{if ne .Icon ""}}
|
||||
@@ -8,7 +9,7 @@
|
||||
<div class="card-header-icon">
|
||||
<div class="tags has-addons">
|
||||
<p class="tag">Status</p>
|
||||
<p class="tag is-warning" id="{{.Title}}Status">Loading...</p>
|
||||
<p class="tag is-warning" id="StatusTag_{{$randID}}">Loading...</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -26,13 +27,13 @@
|
||||
request.onload = function () {
|
||||
var data = JSON.parse(this.response)
|
||||
if (data.down === true || parseInt(data.code) > 500 && parseInt(data.code) < 600 ) {
|
||||
document.getElementById('{{.Title}}Status').classList.remove("is-warning")
|
||||
document.getElementById('{{.Title}}Status').classList.add("is-danger")
|
||||
document.getElementById('{{.Title}}Status').innerHTML = "Offline"
|
||||
document.getElementById('StatusTag_{{$randID}}').classList.remove("is-warning")
|
||||
document.getElementById('StatusTag_{{$randID}}').classList.add("is-danger")
|
||||
document.getElementById('StatusTag_{{$randID}}').innerHTML = "Offline"
|
||||
} else {
|
||||
document.getElementById('{{.Title}}Status').classList.remove("is-warning")
|
||||
document.getElementById('{{.Title}}Status').classList.add("is-success")
|
||||
document.getElementById('{{.Title}}Status').innerHTML = "Online"
|
||||
document.getElementById('StatusTag_{{$randID}}').classList.remove("is-warning")
|
||||
document.getElementById('StatusTag_{{$randID}}').classList.add("is-success")
|
||||
document.getElementById('StatusTag_{{$randID}}').innerHTML = "Online"
|
||||
}
|
||||
}
|
||||
request.send()
|
||||
|
@@ -1,43 +1,44 @@
|
||||
{{$randID := randAlphaNum 10}}
|
||||
<div class="card-header">
|
||||
<p class="card-header-title">{{.Title}}</p>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<p id="weatherLoadingText">Loading...</p>
|
||||
<p id="weatherLoadingText_{{$randID}}">Loading...</p>
|
||||
<div class="columns is-mobile">
|
||||
<div class="column is-half">
|
||||
<object type="image/svg+xml" id="weatherStateImg" style="width:45px; height: 45px"></object>
|
||||
<object type="image/svg+xml" id="weatherStateImg_{{$randID}}" style="width:45px; height: 45px"></object>
|
||||
</div>
|
||||
<div class="column is-half">
|
||||
<p id="weatherTempText" class="has-text-right subtitle"></p>
|
||||
<p id="weatherTempText_{{$randID}}" class="has-text-right subtitle"></p>
|
||||
</div>
|
||||
</div>
|
||||
<p class="subtitle is-marginless" id="weatherStateText"></p>
|
||||
<p id="weatherMinText"></p>
|
||||
<p id="weatherMaxText"></p>
|
||||
<p id="weatherWindSpeedText"></p>
|
||||
<p id="weatherHumidityText"></p>
|
||||
<p id="weatherVisibilityText"></p>
|
||||
<p id="weatherPredictabilityText"></p>
|
||||
<p class="subtitle is-marginless" id="weatherStateText_{{$randID}}"></p>
|
||||
<p id="weatherMinText_{{$randID}}"></p>
|
||||
<p id="weatherMaxText_{{$randID}}"></p>
|
||||
<p id="weatherWindSpeedText_{{$randID}}"></p>
|
||||
<p id="weatherHumidityText_{{$randID}}"></p>
|
||||
<p id="weatherVisibilityText_{{$randID}}"></p>
|
||||
<p id="weatherPredictabilityText_{{$randID}}"></p>
|
||||
</div>
|
||||
<div class="card-footer" style="margin-top: auto">
|
||||
<span class="card-footer-item">Data from <a href="https://www.metaweather.com" class="has-text-info">Metaweather</a></span>
|
||||
</div>
|
||||
<script>
|
||||
var request = new XMLHttpRequest()
|
||||
request.open('GET', "{{proxy (printf `https://www.metaweather.com/api/location/%s/` .Data.woeid) }}", true)
|
||||
request.open('GET', "{{proxy (printf `https://www.metaweather.com/api/location/%s/` .Data.woeid)}}", true)
|
||||
const round = function (flt){return Number.parseFloat(flt).toPrecision(3)}
|
||||
request.onload = function () {
|
||||
const data = JSON.parse(this.response)
|
||||
document.getElementById('weatherLoadingText').classList.add("is-hidden")
|
||||
document.getElementById('weatherStateText').innerText = data["consolidated_weather"][0]["weather_state_name"]
|
||||
document.getElementById('weatherTempText').innerHTML = round(data["consolidated_weather"][0]["the_temp"]*1.8+32) + " °F"
|
||||
document.getElementById('weatherStateImg').data = "/proxy/" + btoa("https://www.metaweather.com/static/img/weather/" + data["consolidated_weather"][0]["weather_state_abbr"] + ".svg")
|
||||
document.getElementById('weatherMinText').innerHTML = "Min: " + round(data["consolidated_weather"][0]["min_temp"]*1.8+32) + " °F"
|
||||
document.getElementById('weatherMaxText').innerHTML = "Max: " + round(data["consolidated_weather"][0]["max_temp"]*1.8+32) + " °F"
|
||||
document.getElementById('weatherWindSpeedText').innerText = "Wind Speed: " + round(data["consolidated_weather"][0]["wind_speed"]) + "mph"
|
||||
document.getElementById('weatherHumidityText').innerText = "Humidity: " + data["consolidated_weather"][0]["humidity"] + "%"
|
||||
document.getElementById('weatherVisibilityText').innerText = "Visibility: " + round(data["consolidated_weather"][0]["visibility"]) + "mi"
|
||||
document.getElementById('weatherPredictabilityText').innerText = "Predictability: " + data["consolidated_weather"][0]["predictability"] + "%"
|
||||
document.getElementById('weatherLoadingText_{{$randID}}').classList.add("is-hidden")
|
||||
document.getElementById('weatherStateText_{{$randID}}').innerText = data["consolidated_weather"][0]["weather_state_name"]
|
||||
document.getElementById('weatherTempText_{{$randID}}').innerHTML = round(data["consolidated_weather"][0]["the_temp"]*1.8+32) + " °F"
|
||||
document.getElementById('weatherStateImg_{{$randID}}').data = "/proxy/" + btoa("https://www.metaweather.com/static/img/weather/" + data["consolidated_weather"][0]["weather_state_abbr"] + ".svg")
|
||||
document.getElementById('weatherMinText_{{$randID}}').innerHTML = "Min: " + round(data["consolidated_weather"][0]["min_temp"]*1.8+32) + " °F"
|
||||
document.getElementById('weatherMaxText_{{$randID}}').innerHTML = "Max: " + round(data["consolidated_weather"][0]["max_temp"]*1.8+32) + " °F"
|
||||
document.getElementById('weatherWindSpeedText_{{$randID}}').innerText = "Wind Speed: " + round(data["consolidated_weather"][0]["wind_speed"]) + "mph"
|
||||
document.getElementById('weatherHumidityText_{{$randID}}').innerText = "Humidity: " + data["consolidated_weather"][0]["humidity"] + "%"
|
||||
document.getElementById('weatherVisibilityText_{{$randID}}').innerText = "Visibility: " + round(data["consolidated_weather"][0]["visibility"]) + "mi"
|
||||
document.getElementById('weatherPredictabilityText_{{$randID}}').innerText = "Predictability: " + data["consolidated_weather"][0]["predictability"] + "%"
|
||||
}
|
||||
request.send()
|
||||
</script>
|
||||
|
Reference in New Issue
Block a user