honk/views/honkpage.html

112 lines
2.9 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>
2019-08-19 09:21:53 +02:00
var topxid = "{{ .TopXID }}"
2019-08-20 03:03:44 +02:00
function refreshhonks(btn) {
btn.innerHTML = "refreshing"
btn.disabled = true
get("/?topxid=" + escape(topxid), function(xhr) {
var doc = xhr.responseXML
2019-08-19 09:21:53 +02:00
topxid = doc.children[0].children[1].children[0].innerText
var honks = doc.children[0].children[1].children
var mebox = document.getElementById("refreshbox")
2019-08-20 03:03:44 +02:00
var newhonks = honks.length - 1
for (var i = honks.length; i > 1; i--) {
mebox.insertAdjacentElement('afterend', honks[i-1])
}
2019-08-20 03:03:44 +02:00
btn.innerHTML = "refresh"
btn.disabled = false
btn.parentElement.children[1].innerHTML = " " + newhonks + " new"
})
}
</script>
2019-08-20 03:03:44 +02:00
<p><button onclick="refreshhonks(this)">refresh</button><span></span>
</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
}
function unbonk(el, xid) {
2019-08-24 02:43:30 +02:00
el.innerHTML = "unbonked"
el.disabled = true
post("/zonkit", "CSRF={{ $BonkCSRF }}&wherefore=unbonk&what=" + escape(xid))
}
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 }}