Compare commits
No commits in common. "2098da3417695370598d21ae386be9af1fb90ea5" and "0c0811a5fced096497a1627f8a4d66da6344dca5" have entirely different histories.
2098da3417
...
0c0811a5fc
3 changed files with 23 additions and 45 deletions
39
main.go
39
main.go
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"embed"
|
"embed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
|
@ -17,12 +16,10 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const VERSION = "v2"
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
flagVerbose bool
|
flagVerbose bool
|
||||||
flagVersion bool
|
flagWsURL string
|
||||||
flagDebuggingPort int
|
flagWatch string
|
||||||
|
|
||||||
//go:embed static
|
//go:embed static
|
||||||
fs embed.FS
|
fs embed.FS
|
||||||
|
|
@ -30,15 +27,10 @@ var (
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.BoolVar(&flagVerbose, "v", false, "verbose")
|
flag.BoolVar(&flagVerbose, "v", false, "verbose")
|
||||||
flag.BoolVar(&flagVersion, "version", false, "Print version and exit")
|
flag.StringVar(&flagWsURL, "ws", "ws://127.0.0.1:9222", "devtools url")
|
||||||
flag.IntVar(&flagDebuggingPort, "port", 9222, "Chrome debugging port")
|
flag.StringVar(&flagWatch, "watch", "", "Files to watch")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if flagVersion {
|
|
||||||
fmt.Println(VERSION)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
http.HandleFunc("/", pageIndex)
|
http.HandleFunc("/", pageIndex)
|
||||||
http.HandleFunc("/css/main.css", pageCSS)
|
http.HandleFunc("/css/main.css", pageCSS)
|
||||||
|
|
||||||
|
|
@ -52,7 +44,7 @@ func main() {
|
||||||
http.ListenAndServe("[::]:5123", nil)
|
http.ListenAndServe("[::]:5123", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func replaceTilde(str string) string { // {{{
|
func replaceTilde(str string) string {// {{{
|
||||||
homedir, err := os.UserHomeDir()
|
homedir, err := os.UserHomeDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
|
|
@ -64,7 +56,7 @@ func replaceTilde(str string) string { // {{{
|
||||||
}
|
}
|
||||||
|
|
||||||
return str
|
return str
|
||||||
} // }}}
|
}// }}}
|
||||||
|
|
||||||
func pageIndex(w http.ResponseWriter, r *http.Request) { // {{{
|
func pageIndex(w http.ResponseWriter, r *http.Request) { // {{{
|
||||||
var tmpl *template.Template
|
var tmpl *template.Template
|
||||||
|
|
@ -78,11 +70,7 @@ func pageIndex(w http.ResponseWriter, r *http.Request) { // {{{
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data := map[string]any{
|
tmpl.Execute(w, sites)
|
||||||
"Sites": sites,
|
|
||||||
"VERSION": VERSION,
|
|
||||||
}
|
|
||||||
tmpl.Execute(w, data)
|
|
||||||
} // }}}
|
} // }}}
|
||||||
func pageCSS(w http.ResponseWriter, r *http.Request) { // {{{
|
func pageCSS(w http.ResponseWriter, r *http.Request) { // {{{
|
||||||
w.Header().Add("Content-Type", "text/css")
|
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) { // {{{
|
func actionSites(w http.ResponseWriter, r *http.Request) { // {{{
|
||||||
j, _ := json.Marshal(struct {
|
j, _ := json.Marshal(struct {
|
||||||
OK bool
|
OK bool
|
||||||
Sites map[string]*Site
|
Sites map[string]*Site
|
||||||
}{
|
}{
|
||||||
true,
|
true,
|
||||||
|
|
@ -106,17 +94,17 @@ func actionSites(w http.ResponseWriter, r *http.Request) { // {{{
|
||||||
w.Write(j)
|
w.Write(j)
|
||||||
} // }}}
|
} // }}}
|
||||||
|
|
||||||
func actionBrowserStart(w http.ResponseWriter, r *http.Request) { // {{{
|
func actionBrowserStart(w http.ResponseWriter, r *http.Request) {// {{{
|
||||||
body, _ := io.ReadAll(r.Body)
|
body, _ := io.ReadAll(r.Body)
|
||||||
userDataDir := replaceTilde(string(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()
|
err := browser.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
} else {
|
} else {
|
||||||
go browser.Wait()
|
go browser.Wait()
|
||||||
}
|
}
|
||||||
} // }}}
|
}// }}}
|
||||||
func actionStart(w http.ResponseWriter, r *http.Request) { // {{{
|
func actionStart(w http.ResponseWriter, r *http.Request) { // {{{
|
||||||
var req struct {
|
var req struct {
|
||||||
URL string
|
URL string
|
||||||
|
|
@ -139,8 +127,7 @@ func actionStart(w http.ResponseWriter, r *http.Request) { // {{{
|
||||||
|
|
||||||
var site Site
|
var site Site
|
||||||
expandedWatch := replaceTilde(req.Watch)
|
expandedWatch := replaceTilde(req.Watch)
|
||||||
wsURL := fmt.Sprintf("ws://127.0.0.1:%d", flagDebuggingPort)
|
site, err = NewSite(flagWsURL, req.URL, expandedWatch)
|
||||||
site, err = NewSite(wsURL, req.URL, expandedWatch)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,6 @@ body {
|
||||||
margin: 32px;
|
margin: 32px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#version {
|
|
||||||
position: absolute;
|
|
||||||
right: 16px;
|
|
||||||
top: 16px;
|
|
||||||
}
|
|
||||||
|
|
||||||
input {
|
input {
|
||||||
font-size: 1em;
|
font-size: 1em;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,9 +44,8 @@
|
||||||
for (const uuid of Object.keys(json.Sites)) {
|
for (const uuid of Object.keys(json.Sites)) {
|
||||||
const site = json.Sites[uuid]
|
const site = json.Sites[uuid]
|
||||||
if (site.StopLoop) {
|
if (site.StopLoop) {
|
||||||
const els = document.querySelectorAll(`[data-uuid="${uuid}"]`)
|
document.querySelector(`.url[data-uuid="${uuid}"]`)?.classList.add('dead')
|
||||||
for (const el of els)
|
document.querySelector(`.watch[data-uuid="${uuid}"]`)?.classList.add('dead')
|
||||||
el.remove()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -65,7 +64,6 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div id="version">{{ .VERSION }}</div>
|
|
||||||
<div class="browser">
|
<div class="browser">
|
||||||
<h1>Browser</h1>
|
<h1>Browser</h1>
|
||||||
<input type="text" class="user-data-dir" placeholder="~/.local/share/chrome-dev">
|
<input type="text" class="user-data-dir" placeholder="~/.local/share/chrome-dev">
|
||||||
|
|
@ -83,15 +81,14 @@
|
||||||
<input type="text" class="new watch" placeholder="~/example.com/css/">
|
<input type="text" class="new watch" placeholder="~/example.com/css/">
|
||||||
<button onclick="newSite()">Start</button>
|
<button onclick="newSite()">Start</button>
|
||||||
|
|
||||||
{{ range .Sites }}
|
{{ range . }}
|
||||||
{{ if .StopLoop }}
|
{{ if .StopLoop }}
|
||||||
{{ continue }}
|
{{ continue }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
<div class="line" data-uuid="{{ .UUID }}"></div>
|
<div class="line"></div>
|
||||||
<div class="url" data-uuid="{{ .UUID }}">{{ .URL }}</div>
|
<div class="url {{ if .StopLoop }}dead{{ end }}" data-uuid="{{ .UUID }}">{{ .URL }}</div>
|
||||||
<div class="watch" data-uuid="{{ .UUID }}">{{ .Watch }}</div>
|
<div class="watch {{ if .StopLoop }}dead{{ end }}" data-uuid="{{ .UUID }}">{{ .Watch }}</div>
|
||||||
<div class="stop" onclick="stopSite('{{ .UUID }}')" data-uuid="{{ .UUID }}">{{ if not .StopLoop }}❌{{
|
<div class="stop" onclick="stopSite('{{ .UUID }}')">{{ if not .StopLoop }}❌{{ end }}</div>
|
||||||
end }}</div>
|
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
<script>init()</script>
|
<script>init()</script>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue