s1llyw0rdz/web/handler/widget_show.go

42 lines
1.6 KiB
Go
Raw Normal View History

2021-11-28 21:38:08 +00:00
package handler
import (
"net/http"
2025-11-20 00:12:26 +00:00
"net/url"
2021-11-28 21:38:08 +00:00
)
func (h *Handler) showCurrentStatusJSView(w http.ResponseWriter, r *http.Request) {
name := r.URL.Query().Get("name")
2025-11-20 00:12:26 +00:00
escName := url.PathEscape(name)
w.Header().Set("Content-Type", "application/javascript")
2021-11-28 21:38:08 +00:00
w.Write([]byte(`
2025-11-20 00:12:26 +00:00
document.write('<script src="https://cdn.jsdelivr.net/npm/dompurify@3.0.6/dist/purify.min.js"><\/script>');
document.writeln('<div id="sillywordz"><div id="sillywordz-username"></div><div id="sillywordz-number"></div><div id="sillywordz-content"></div></div>');
fetch("https://sillywordz.kissing.computer/users/` + escName + `/status.json")
2021-11-28 21:38:08 +00:00
.then( r => r.json() )
.then( r => {
2025-11-20 00:45:43 +00:00
if (!r.number || !r.content.length || r.number <1) {
2025-11-20 00:12:26 +00:00
document.getElementById("sillywordz-content").innerHTML = "No updates yet."
2021-11-28 21:38:08 +00:00
return
}
2025-11-20 00:12:26 +00:00
let safeAuthor = DOMPurify.sanitize(r.author);
let safeContent = DOMPurify.sanitize(r.content);
document.getElementById("sillywordz-username").innerHTML= '<a href="https://sillywordz.kissing.computer/users/` + escName + `status.json" target="_blank">' + safeAuthor + '</a> ' + r.face + ' ' + r.timeAgo
document.getElementById("sillywordz-number").innerHTML = "I wrote " + r.number + " words on my project!"
2025-11-20 00:45:43 +00:00
if (r.number >= 1) {
2025-11-20 00:12:26 +00:00
document.getElementById("sillywordz-content").innerHTML = "And I had this to say about it:" + safeContent
} })
2021-11-28 21:38:08 +00:00
`))
}
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)
}