Single bookmarklet
This commit is contained in:
14
main.go
14
main.go
@@ -69,6 +69,7 @@ func NewShortLinks(db *sql.DB, domainAliases map[string]string, writableDomains
|
||||
}
|
||||
|
||||
sl.mux.HandleFunc("GET /{$}", sl.serveRoot)
|
||||
sl.mux.HandleFunc("GET /_help", sl.serveHelp)
|
||||
sl.mux.HandleFunc("GET /{short}", sl.serveShort)
|
||||
sl.mux.HandleFunc("POST /{$}", sl.serveSet)
|
||||
sl.mux.HandleFunc("QUERY /{$}", sl.serveSuggest)
|
||||
@@ -136,11 +137,6 @@ func (sl *ShortLinks) serveShort(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
short := r.PathValue("short")
|
||||
|
||||
if sl.isWritable(r.Host) && short == "_help" {
|
||||
sl.serveHelp(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
long, err := sl.getLong(short, sl.getDomain(r.Host))
|
||||
if err != nil {
|
||||
sl.serveRootWithPath(w, r, short)
|
||||
@@ -236,12 +232,18 @@ func (sl *ShortLinks) serveSuggest(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (sl *ShortLinks) serveHelp(w http.ResponseWriter, r *http.Request) {
|
||||
err := sl.initRequest(w, r)
|
||||
if err != nil {
|
||||
sendError(w, http.StatusBadRequest, "init request: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if !sl.isWritable(r.Host) {
|
||||
sendError(w, http.StatusNotFound, "not found")
|
||||
return
|
||||
}
|
||||
|
||||
err := sl.help.Execute(w, map[string]any{
|
||||
err = sl.help.Execute(w, map[string]any{
|
||||
"writeHost": r.Host,
|
||||
"readHost": sl.getDomain(r.Host),
|
||||
})
|
||||
|
||||
@@ -201,31 +201,7 @@ a {
|
||||
|
||||
<sl-tab-panel name="browser">
|
||||
<sl-card class="card-basic">
|
||||
Drag links to bookmark bar:
|
||||
<br />
|
||||
<br />
|
||||
|
||||
<sl-tag pill variant="primary">
|
||||
<a href="javascript:(async function() {
|
||||
try {
|
||||
const response = await fetch('https://{{ .writeHost }}/', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ long: location.href }),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(response.statusText);
|
||||
}
|
||||
|
||||
await navigator.clipboard.writeText((await response.json()).url);
|
||||
} catch (err) {
|
||||
alert(err);
|
||||
}
|
||||
})();">{{ .readHost }} (Copy)</a>
|
||||
</sl-tag>
|
||||
Drag link to bookmark bar:
|
||||
<br />
|
||||
<br />
|
||||
|
||||
@@ -235,7 +211,7 @@ a {
|
||||
params.set('long', location.href);
|
||||
|
||||
window.open(`https://{{ .writeHost }}/?${params.toString()}`);
|
||||
})();">{{ .readHost }} (Custom)</a>
|
||||
})();">{{ .readHost }}</a>
|
||||
</sl-tag>
|
||||
</sl-card>
|
||||
</sl-tab-panel>
|
||||
|
||||
Reference in New Issue
Block a user