Change variable name to prevent conflicts

This commit is contained in:
2021-05-22 17:16:05 -07:00
parent 062f329448
commit 61ed6e1872
4 changed files with 31 additions and 4 deletions

View File

@@ -29,5 +29,8 @@
document.getElementById("{{printf `APIElement%d_%s` $index $randID}}").innerHTML = `{{unescJS (trim $fmtStr)}}`
{{end}}
}
{{range $key, $value := .Data.headers}}
request.setRequestHeader("{{$key}}", "{{$value}}")
{{end}}
request.send()
</script>

View File

@@ -24,10 +24,10 @@
<span class="card-footer-item">Data from&nbsp;<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)
var wtrRequest = new XMLHttpRequest()
wtrRequest.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 () {
wtrRequest.onload = function () {
const data = JSON.parse(this.response)
document.getElementById('weatherLoading_{{$randID}}').classList.add("is-hidden")
document.getElementById('weatherStateText_{{$randID}}').innerText = data["consolidated_weather"][0]["weather_state_name"]
@@ -40,5 +40,6 @@
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()
wtrRequest.setRequestHeader("Content-Type", "text/plain")
wtrRequest.send()
</script>