honk/views/honkpage.html

103 lines
2.5 KiB
HTML
Raw Normal View History

2019-04-09 13:59:33 +02:00
{{ template "header.html" . }}
2019-04-29 01:16:24 +02:00
<main>
2019-04-23 17:22:31 +02:00
<div class="info" id="infobox">
2019-04-09 13:59:33 +02:00
{{ if .Name }}
<p>{{ .Name }} <span style="margin-left:1em;"><a href="/u/{{ .Name }}/rss">rss</a></span>
<p>{{ .WhatAbout }}
{{ end }}
2019-04-23 17:22:31 +02:00
<p>{{ .ServerMessage }}
{{ if .HonkCSRF }}
{{ template "honkform.html" . }}
{{ end }}
</div>
{{ $BonkCSRF := .HonkCSRF }}
{{ if .TopXID }}
<div class="info" id="refreshbox">
<script>
var topxid = {{ .TopXID }}
function refreshhonks() {
get("/?topxid=" + escape(topxid), function(xhr) {
var doc = xhr.responseXML
topel = doc.children[0].children[1].children[0]
topxid = topel.innerText
honks = doc.children[0].children[1].children
var mebox = document.getElementById("refreshbox")
for (var i = honks.length; i > 1; i--) {
mebox.insertAdjacentElement('afterend', honks[i-1])
}
})
}
</script>
<p><button onclick="refreshhonks()">refresh</button>
</div>
{{ end }}
2019-04-09 13:59:33 +02:00
{{ range .Honks }}
2019-04-26 15:07:13 +02:00
{{ template "honk.html" map "Honk" . "BonkCSRF" $BonkCSRF }}
2019-04-09 13:59:33 +02:00
{{ end }}
2019-04-29 01:16:24 +02:00
</main>
2019-04-23 17:22:31 +02:00
{{ if $BonkCSRF }}
<script>
2019-04-26 15:07:13 +02:00
function encode(hash) {
var s = []
for (var key in hash) {
var val = hash[key]
s.push(escape(key) + "=" + escape(val))
}
return s.join("&")
}
2019-04-23 17:22:31 +02:00
function post(url, data) {
var x = new XMLHttpRequest()
x.open("POST", url)
x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
x.send(data)
}
function get(url, whendone) {
var x = new XMLHttpRequest()
x.open("GET", url)
x.responseType = "document"
x.onload = function() { whendone(x) }
x.send()
}
2019-04-23 17:22:31 +02:00
function bonk(el, xid) {
el.innerHTML = "bonked"
el.disabled = true
2019-04-26 15:07:13 +02:00
post("/bonk", "CSRF={{ $BonkCSRF }}&xid=" + escape(xid))
2019-04-23 17:22:31 +02:00
}
2019-06-16 00:46:00 +02:00
function muteit(el, convoy) {
el.innerHTML = "muted"
2019-04-23 17:22:31 +02:00
el.disabled = true
2019-06-17 18:10:36 +02:00
post("/zonkit", "CSRF={{ $BonkCSRF }}&wherefore=zonvoy&what=" + escape(convoy))
2019-06-16 00:46:00 +02:00
var els = document.querySelectorAll('article.honk')
for (var i = 0; i < els.length; i++) {
var e = els[i]
if (e.getAttribute("data-convoy") == convoy) {
e.remove()
2019-04-26 15:07:13 +02:00
}
}
2019-06-16 00:46:00 +02:00
}
function zonkit(el, xid) {
el.innerHTML = "zonked"
el.disabled = true
2019-06-17 18:10:36 +02:00
post("/zonkit", "CSRF={{ $BonkCSRF }}&wherefore=zonk&what=" + escape(xid))
2019-06-16 00:46:00 +02:00
var p = el
while (p && p.tagName != "ARTICLE") {
p = p.parentElement
}
if (p) {
p.remove()
}
2019-04-23 17:22:31 +02:00
}
2019-08-16 21:35:12 +02:00
function ackit(el, xid) {
el.innerHTML = "acked"
el.disabled = true
post("/zonkit", "CSRF={{ $BonkCSRF }}&wherefore=ack&what=" + escape(xid))
}
2019-08-19 06:01:00 +02:00
function deackit(el, xid) {
el.innerHTML = "deacked"
el.disabled = true
post("/zonkit", "CSRF={{ $BonkCSRF }}&wherefore=deack&what=" + escape(xid))
}
2019-04-23 17:22:31 +02:00
</script>
{{ end }}