Refresh now happens X seconds after page finishes completely loading, not X seconds after the initial request is sent

This commit is contained in:
Seednode 2022-11-10 09:38:40 -06:00
parent b6a46a63b6
commit 28af94cba3
2 changed files with 9 additions and 8 deletions

View File

@ -10,7 +10,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var Version = "0.25.1" var Version = "0.25.2"
func init() { func init() {
rootCmd.AddCommand(versionCmd) rootCmd.AddCommand(versionCmd)

View File

@ -195,22 +195,23 @@ func serveHtml(w http.ResponseWriter, r *http.Request, filePath string, dimensio
dimensions.Width, dimensions.Width,
dimensions.Height)) dimensions.Height))
htmlBody.WriteString(`</head><body>`) htmlBody.WriteString(`</head><body>`)
htmlBody.WriteString(fmt.Sprintf(`<a href="/%v"><img src="%v" width="%v" height="%v" alt="Roulette selected: %v"></a>`,
queryParams,
generateFilePath(filePath),
dimensions.Width,
dimensions.Height,
fileName))
if refreshInterval != "0" { if refreshInterval != "0" {
r, err := strconv.Atoi(refreshInterval) r, err := strconv.Atoi(refreshInterval)
if err != nil { if err != nil {
return err return err
} }
refreshTimer := strconv.Itoa(r * 1000) refreshTimer := strconv.Itoa(r * 1000)
htmlBody.WriteString(fmt.Sprintf(`<script>setTimeout(function(){window.location.href = '/%v';},%v);</script>`,
htmlBody.WriteString(fmt.Sprintf("<script>window.onload = function(){setInterval(function(){window.location.href = '/%v';}, %v);};</script>",
queryParams, queryParams,
refreshTimer)) refreshTimer))
} }
htmlBody.WriteString(fmt.Sprintf(`<a href="/%v"><img src="%v" width="%v" height="%v" alt="Roulette selected: %v"></a>`,
queryParams,
generateFilePath(filePath),
dimensions.Width,
dimensions.Height,
fileName))
htmlBody.WriteString(`</body></html>`) htmlBody.WriteString(`</body></html>`)
_, err := io.WriteString(w, gohtml.Format(htmlBody.String())) _, err := io.WriteString(w, gohtml.Format(htmlBody.String()))