this is extremely messy, but allow hotswap between /home and /atme
This commit is contained in:
parent
688d6be957
commit
ed7e687370
3
honk.go
3
honk.go
|
@ -173,10 +173,10 @@ func homepage(w http.ResponseWriter, r *http.Request) {
|
||||||
} else {
|
} else {
|
||||||
honks = gethonksforuser(userid)
|
honks = gethonksforuser(userid)
|
||||||
honks = osmosis(honks, userid)
|
honks = osmosis(honks, userid)
|
||||||
|
}
|
||||||
if len(honks) > 0 {
|
if len(honks) > 0 {
|
||||||
templinfo["TopXID"] = honks[0].XID
|
templinfo["TopXID"] = honks[0].XID
|
||||||
}
|
}
|
||||||
}
|
|
||||||
templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
|
templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1715,6 +1715,7 @@ func serve() {
|
||||||
getters := mux.Methods("GET").Subrouter()
|
getters := mux.Methods("GET").Subrouter()
|
||||||
|
|
||||||
getters.HandleFunc("/", homepage)
|
getters.HandleFunc("/", homepage)
|
||||||
|
getters.HandleFunc("/home", homepage)
|
||||||
getters.HandleFunc("/front", homepage)
|
getters.HandleFunc("/front", homepage)
|
||||||
getters.HandleFunc("/robots.txt", nomoroboto)
|
getters.HandleFunc("/robots.txt", nomoroboto)
|
||||||
getters.HandleFunc("/rss", showrss)
|
getters.HandleFunc("/rss", showrss)
|
||||||
|
|
|
@ -14,9 +14,9 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<header>
|
<header>
|
||||||
<span><a href="/">honk</a></span>
|
<span><a id="homelink" href="/">honk</a></span>
|
||||||
{{ if .UserInfo }}
|
{{ if .UserInfo }}
|
||||||
<span><a href="/atme">@me</a></span>
|
<span><a id="atmelink" href="/atme">@me</a></span>
|
||||||
<span><a href="/{{ .UserSep }}/{{ .UserInfo.Username }}">{{ .UserInfo.Username }}</a></span>
|
<span><a href="/{{ .UserSep }}/{{ .UserInfo.Username }}">{{ .UserInfo.Username }}</a></span>
|
||||||
<span><a href="/honkers">honkers</a></span>
|
<span><a href="/honkers">honkers</a></span>
|
||||||
<span><a href="/c">combos</a></span>
|
<span><a href="/c">combos</a></span>
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
<div>{{ .TopXID }}</div>
|
<div>{{ .TopXID }}</div>
|
||||||
{{ $BonkCSRF := .HonkCSRF }}
|
{{ $BonkCSRF := .HonkCSRF }}
|
||||||
|
<div>
|
||||||
{{ range .Honks }}
|
{{ range .Honks }}
|
||||||
{{ template "honk.html" map "Honk" . "BonkCSRF" $BonkCSRF }}
|
{{ template "honk.html" map "Honk" . "BonkCSRF" $BonkCSRF }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
</div>
|
||||||
|
|
|
@ -14,31 +14,70 @@
|
||||||
{{ if .TopXID }}
|
{{ if .TopXID }}
|
||||||
<div class="info" id="refreshbox">
|
<div class="info" id="refreshbox">
|
||||||
<script>
|
<script>
|
||||||
var topxid = "{{ .TopXID }}"
|
var topxid = { "home" : "{{ .TopXID }}" }
|
||||||
|
var honksforpage = { }
|
||||||
|
var thispagename = "home"
|
||||||
|
function fillinhonks(xhr) {
|
||||||
|
var doc = xhr.responseXML
|
||||||
|
topxid[thispagename] = doc.children[0].children[1].children[0].innerText
|
||||||
|
var honks = doc.children[0].children[1].children[1].children
|
||||||
|
var honksonpage = document.getElementById("honksonpage")
|
||||||
|
var lenhonks = honks.length
|
||||||
|
for (var i = honks.length; i > 0; i--) {
|
||||||
|
honksonpage.prepend(honks[i-1])
|
||||||
|
}
|
||||||
|
return lenhonks
|
||||||
|
}
|
||||||
function refreshhonks(btn) {
|
function refreshhonks(btn) {
|
||||||
btn.innerHTML = "refreshing"
|
btn.innerHTML = "refreshing"
|
||||||
btn.disabled = true
|
btn.disabled = true
|
||||||
get("/?topxid=" + escape(topxid), function(xhr) {
|
get("/" + thispagename + "?topxid=" + escape(topxid[thispagename]), function(xhr) {
|
||||||
var doc = xhr.responseXML
|
var lenhonks = fillinhonks(xhr)
|
||||||
topxid = doc.children[0].children[1].children[0].innerText
|
|
||||||
var honks = doc.children[0].children[1].children
|
|
||||||
var mebox = document.getElementById("refreshbox")
|
|
||||||
var newhonks = honks.length - 1
|
|
||||||
for (var i = honks.length; i > 1; i--) {
|
|
||||||
mebox.insertAdjacentElement('afterend', honks[i-1])
|
|
||||||
}
|
|
||||||
btn.innerHTML = "refresh"
|
btn.innerHTML = "refresh"
|
||||||
btn.disabled = false
|
btn.disabled = false
|
||||||
btn.parentElement.children[1].innerHTML = " " + newhonks + " new"
|
btn.parentElement.children[1].innerHTML = " " + lenhonks + " new"
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
function pageswitcher(name) {
|
||||||
|
return function(evt) {
|
||||||
|
if (name == thispagename) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var honksonpage = document.getElementById("honksonpage")
|
||||||
|
var holder = document.createElement("div");
|
||||||
|
while (honksonpage.children.length) {
|
||||||
|
holder.prepend(honksonpage.children[0])
|
||||||
|
}
|
||||||
|
honksforpage[thispagename] = holder
|
||||||
|
thispagename = name
|
||||||
|
holder = honksforpage[name]
|
||||||
|
if (holder) {
|
||||||
|
while (holder.children.length) {
|
||||||
|
honksonpage.prepend(holder.children[0])
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
get("/" + name + "?topxid=" + escape(topxid[thispagename]), function(xhr) {
|
||||||
|
fillinhonks(xhr)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(function() {
|
||||||
|
var el = document.getElementById("homelink")
|
||||||
|
el.onclick = pageswitcher("home")
|
||||||
|
var el = document.getElementById("atmelink")
|
||||||
|
el.onclick = pageswitcher("atme")
|
||||||
|
})();
|
||||||
</script>
|
</script>
|
||||||
<p><button onclick="refreshhonks(this)">refresh</button><span></span>
|
<p><button onclick="refreshhonks(this)">refresh</button><span></span>
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
<div id="honksonpage">
|
||||||
{{ range .Honks }}
|
{{ range .Honks }}
|
||||||
{{ template "honk.html" map "Honk" . "BonkCSRF" $BonkCSRF }}
|
{{ template "honk.html" map "Honk" . "BonkCSRF" $BonkCSRF }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
</div>
|
||||||
</main>
|
</main>
|
||||||
{{ if $BonkCSRF }}
|
{{ if $BonkCSRF }}
|
||||||
<script>
|
<script>
|
||||||
|
|
Loading…
Reference in New Issue