s1llyw0rdz/web/handler/widget_show.go

34 lines
1 KiB
Go
Raw Normal View History

2021-11-28 21:38:08 +00:00
package handler
import (
"net/http"
)
func (h *Handler) showCurrentStatusJSView(w http.ResponseWriter, r *http.Request) {
name := r.URL.Query().Get("name")
w.Write([]byte(`
document.writeln('<div id="statuscafe"><div id="statuscafe-username"></div><div id="statuscafe-content"></div></div>');
fetch("https://status.cafe/users/` + name + `/status.json")
.then( r => r.json() )
.then( r => {
if (!r.content.length) {
document.getElementById("statuscafe-content").innerHTML = "No status yet."
return
}
2021-12-06 06:14:20 +00:00
document.getElementById("statuscafe-username").innerHTML = '<a href="https://status.cafe/users/` + name + `" target="_blank">' + r.author + '</a> ' + r.face + ' ' + r.timeAgo
2021-11-28 21:38:08 +00:00
document.getElementById("statuscafe-content").innerHTML = r.content
})
`))
}
func (h *Handler) showCurrentStatusView(w http.ResponseWriter, r *http.Request) {
logged, _ := h.getUser(r)
name := r.URL.Query().Get("name")
if name == "" {
name = logged
}
h.renderLayout(w, "current_status", map[string]interface{}{
"name": name,
}, logged)
}