create post url parameters for bookmarklets

This commit is contained in:
Ryan Stafford 2023-09-03 13:11:53 -04:00
parent 6b2c902b3c
commit 5857148ec9
3 changed files with 18 additions and 3 deletions

View file

@ -648,6 +648,17 @@ func GetCreatePost(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
Render(w, "index.html", state) Render(w, "index.html", state)
return return
} }
m, _ := url.ParseQuery(r.URL.RawQuery)
if len(m["url"]) > 0 {
state.SubmitURL = m["url"][0]
}
if len(m["title"]) > 0 {
state.SubmitTitle = m["title"][0]
}
if len(m["body"]) > 0 {
state.SubmitBody = m["body"][0]
}
state.GetSite() state.GetSite()
state.GetCommunity("") state.GetCommunity("")
state.Op = "create_post" state.Op = "create_post"

View file

@ -105,6 +105,9 @@ type State struct {
ShowNSFW bool ShowNSFW bool
HideInstanceNames bool HideInstanceNames bool
HideThumbnails bool HideThumbnails bool
SubmitURL string
SubmitTitle string
SubmitBody string
} }
func (s State) UserBlocked() bool { func (s State) UserBlocked() bool {

View file

@ -3,17 +3,18 @@
<div> <div>
<label for="url">url</label> <label for="url">url</label>
<input type="text" name="url" id="url" <input type="text" name="url" id="url"
{{- if and $p (index $p 0).Post.URL.IsValid }} value="{{(index $p 0).Post.URL.String}}"{{end -}} {{- if and $p (index $p 0).Post.URL.IsValid }} value="{{(index $p 0).Post.URL.String}}"
{{- else if .SubmitURL }} value="{{ .SubmitURL}}"{{end -}}
> >
<input type="file" name="file" accept="image/*"> <input type="file" name="file" accept="image/*">
</div> </div>
<div> <div>
<label class="required" for="title">title</label> <label class="required" for="title">title</label>
<textarea required name="name" id="title">{{ if $p }}{{ (index $p 0).Post.Name }}{{end}}</textarea> <textarea required name="name" id="title">{{ if $p }}{{ (index $p 0).Post.Name }}{{ else if .SubmitTitle}}{{.SubmitTitle}}{{end}}</textarea>
</div> </div>
<div> <div>
<label for="body">body</label> <label for="body">body</label>
<textarea name="body" id="body">{{ if and $p (index $p 0).Post.Body.IsValid }}{{ (index $p 0).Post.Body.String }}{{end}}</textarea> <textarea name="body" id="body">{{ if and $p (index $p 0).Post.Body.IsValid }}{{ (index $p 0).Post.Body.String }}{{ else if .SubmitBody }}{{.SubmitBody}}{{end}}</textarea>
</div> </div>
<div> <div>
<label for="language">language</label> <label for="language">language</label>