diff --git a/main.go b/main.go index 4c91f6b..a5dda15 100644 --- a/main.go +++ b/main.go @@ -7,7 +7,6 @@ import ( "embed" "encoding/json" "flag" - "fmt" "html/template" "io" "log" @@ -17,12 +16,10 @@ import ( "strings" ) -const VERSION = "v2" - var ( - flagVerbose bool - flagVersion bool - flagDebuggingPort int + flagVerbose bool + flagWsURL string + flagWatch string //go:embed static fs embed.FS @@ -30,15 +27,10 @@ var ( func main() { flag.BoolVar(&flagVerbose, "v", false, "verbose") - flag.BoolVar(&flagVersion, "version", false, "Print version and exit") - flag.IntVar(&flagDebuggingPort, "port", 9222, "Chrome debugging port") + flag.StringVar(&flagWsURL, "ws", "ws://127.0.0.1:9222", "devtools url") + flag.StringVar(&flagWatch, "watch", "", "Files to watch") flag.Parse() - if flagVersion { - fmt.Println(VERSION) - return - } - http.HandleFunc("/", pageIndex) http.HandleFunc("/css/main.css", pageCSS) @@ -52,7 +44,7 @@ func main() { http.ListenAndServe("[::]:5123", nil) } -func replaceTilde(str string) string { // {{{ +func replaceTilde(str string) string {// {{{ homedir, err := os.UserHomeDir() if err != nil { log.Println(err) @@ -64,7 +56,7 @@ func replaceTilde(str string) string { // {{{ } return str -} // }}} +}// }}} func pageIndex(w http.ResponseWriter, r *http.Request) { // {{{ var tmpl *template.Template @@ -78,11 +70,7 @@ func pageIndex(w http.ResponseWriter, r *http.Request) { // {{{ return } - data := map[string]any{ - "Sites": sites, - "VERSION": VERSION, - } - tmpl.Execute(w, data) + tmpl.Execute(w, sites) } // }}} func pageCSS(w http.ResponseWriter, r *http.Request) { // {{{ w.Header().Add("Content-Type", "text/css") @@ -97,7 +85,7 @@ func pageCSS(w http.ResponseWriter, r *http.Request) { // {{{ } // }}} func actionSites(w http.ResponseWriter, r *http.Request) { // {{{ j, _ := json.Marshal(struct { - OK bool + OK bool Sites map[string]*Site }{ true, @@ -106,17 +94,17 @@ func actionSites(w http.ResponseWriter, r *http.Request) { // {{{ w.Write(j) } // }}} -func actionBrowserStart(w http.ResponseWriter, r *http.Request) { // {{{ +func actionBrowserStart(w http.ResponseWriter, r *http.Request) {// {{{ body, _ := io.ReadAll(r.Body) userDataDir := replaceTilde(string(body)) - browser := exec.Command("google-chrome", "--user-data-dir="+string(userDataDir), fmt.Sprintf("--remote-debugging-port=%d", flagDebuggingPort)) + browser := exec.Command("google-chrome", "--user-data-dir="+string(userDataDir), "--remote-debugging-port=9222") err := browser.Start() if err != nil { log.Println(err) } else { go browser.Wait() } -} // }}} +}// }}} func actionStart(w http.ResponseWriter, r *http.Request) { // {{{ var req struct { URL string @@ -139,8 +127,7 @@ func actionStart(w http.ResponseWriter, r *http.Request) { // {{{ var site Site expandedWatch := replaceTilde(req.Watch) - wsURL := fmt.Sprintf("ws://127.0.0.1:%d", flagDebuggingPort) - site, err = NewSite(wsURL, req.URL, expandedWatch) + site, err = NewSite(flagWsURL, req.URL, expandedWatch) if err != nil { log.Println(err) } diff --git a/static/css/main.css b/static/css/main.css index 2b0e032..5462b71 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -3,12 +3,6 @@ body { margin: 32px; } -#version { - position: absolute; - right: 16px; - top: 16px; -} - input { font-size: 1em; } diff --git a/static/html/index.html b/static/html/index.html index 030ff24..455fc8f 100644 --- a/static/html/index.html +++ b/static/html/index.html @@ -44,9 +44,8 @@ for (const uuid of Object.keys(json.Sites)) { const site = json.Sites[uuid] if (site.StopLoop) { - const els = document.querySelectorAll(`[data-uuid="${uuid}"]`) - for (const el of els) - el.remove() + document.querySelector(`.url[data-uuid="${uuid}"]`)?.classList.add('dead') + document.querySelector(`.watch[data-uuid="${uuid}"]`)?.classList.add('dead') } } }) @@ -65,7 +64,6 @@
-