diff --git a/views/honkform.html b/views/honkform.html index 13a6788..e593222 100644 --- a/views/honkform.html +++ b/views/honkform.html @@ -37,6 +37,14 @@
+
+
diff --git a/views/honkpage.js b/views/honkpage.js index 8bd648e..f0f9bdc 100644 --- a/views/honkpage.js +++ b/views/honkpage.js @@ -446,6 +446,24 @@ function playit(elem, word, wordlist, xid) { module.addguesscontrols(elem, word, wordlist, xid) }) } +function addemu(data){ + const box = document.getElementById("honknoise"); + box.value += data; +} +function loademus() { + div = document.getElementById("emupicker") + request = new XMLHttpRequest(); + request.open('GET', '/emus') + request.onload = function(){ + div.innerHTML = request.responseText + } + if (div.style.display === "none") { + div.style.display = "block"; + } else { + div.style.display = "none"; + } + request.send() +} // init (function() { @@ -490,6 +508,7 @@ function playit(elem, word, wordlist, xid) { return showhonkform() } document.getElementById("checkinbutton").onclick = fillcheckin + document.getElementById("emuload").onclick = loademus document.querySelector("#donker input").onchange = updatedonker document.querySelector("button[name=cancel]").onclick = cancelhonking })(); diff --git a/views/style.css b/views/style.css index d486b00..39229f2 100644 --- a/views/style.css +++ b/views/style.css @@ -253,6 +253,11 @@ input[type=file] { .honk details.actions summary { color: var(--fg-subtle); } + +#emupicker{height:300px;overflow-y:scroll;padding:3px;background:var(--bg-dark);border:solid 5px var(--fg-subtle);text-align:center;display:none;} +#emupicker img{margin:0;} +.emuload{background:var(--bg-page);padding:0.5em;} + .subtle .noise { color: var(--fg-subtle); font-size: 0.8em; diff --git a/web.go b/web.go index fd56b3a..f6b21d4 100644 --- a/web.go +++ b/web.go @@ -50,6 +50,8 @@ var honkSep = "h" var develMode = false +var allemus []Emu + func getuserstyle(u *login.UserInfo) template.HTMLAttr { if u == nil { return "" @@ -149,6 +151,15 @@ func homepage(w http.ResponseWriter, r *http.Request) { honkpage(w, u, honks, templinfo) } +func showemus(w http.ResponseWriter, r *http.Request) { + templinfo := getInfo(r) + templinfo["Emus"] = allemus + err := readviews.Execute(w, "emus.html", templinfo) + if err != nil { + elog.Print(err) + } +} + func showfunzone(w http.ResponseWriter, r *http.Request) { var emunames, memenames []string emuext := make(map[string]string) @@ -2422,6 +2433,30 @@ func addcspheaders(next http.Handler) http.Handler { }) } +func emuinit() { + var emunames []string + dir, err := os.Open(dataDir + "/emus") + if err == nil { + emunames, _ = dir.Readdirnames(0) + dir.Close() + } + for _, e := range emunames { + if len(e) <= 4 { + continue + } + ext := e[len(e)-4:] + emu := Emu{ + ID: fmt.Sprintf("/emu/%s", e), + Name: e[:len(e)-4], + Type: "image/" + ext[1:], + } + allemus = append(allemus, emu) + } + sort.Slice(allemus, func(i, j int) bool { + return allemus[i].Name < allemus[j].Name + }) +} + func serve() { db := opendatabase() login.Init(login.InitArgs{Db: db, Logger: ilog, Insecure: develMode, SameSiteStrict: !develMode}) @@ -2436,6 +2471,7 @@ func serve() { go tracker() go bgmonitor() loadLingo() + emuinit() readviews = templates.Load(develMode, viewDir+"/views/honkpage.html", @@ -2454,6 +2490,7 @@ func serve() { viewDir+"/views/msg.html", viewDir+"/views/header.html", viewDir+"/views/onts.html", + viewDir+"/views/emus.html", viewDir+"/views/honkpage.js", ) if !develMode { @@ -2555,6 +2592,7 @@ func serve() { loggedin.HandleFunc("/t", showconvoy) loggedin.HandleFunc("/q", showsearch) loggedin.HandleFunc("/hydra", webhydra) + loggedin.HandleFunc("/emus", showemus) loggedin.Handle("/submithonker", login.CSRFWrap("submithonker", http.HandlerFunc(submithonker))) err = http.Serve(listener, mux)