Allow bookmarklet to be shared (#5)

This commit is contained in:
Gert Goet 2021-05-27 22:37:51 +02:00 committed by GitHub
parent 1eabb65c4c
commit c5fdaf4a02
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 8 deletions

View file

@ -1,6 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="css/style.css">
<script src="https://borkdude.github.io/scittle/js/scittle.js" type="application/javascript"></script>

View file

@ -62,7 +62,7 @@
(def *initial-code (r/atom nil))
;; Initialize code
(let [{:keys [gist]} (query-params)]
(let [{:keys [gist code name]} (query-params)]
(cond gist
(do
(reset! *initial-name "---")
@ -74,7 +74,10 @@
(when bookmark-name
(reset! *initial-name bookmark-name))
(reset! *initial-code code)))))
code
(do
(reset! *initial-name (or name "My first bookmarklet"))
(reset! *initial-code code))
:else
(do
(reset! *initial-name "My first bookmarklet")
@ -124,11 +127,13 @@
[editor *code]
[:br]
[:br]
"Click the link below"[:br]
"or"[:br]
"Drag the link to the bookmarks bar" [:br]
"Click the following link or drag it to the bookmarks bar: "
[(fn []
[(fn [] [:a {:href (bookmarklet-href @*code)} @*bookmark-name])])
*code]]))
*code]
[:br]
[(fn []
[:a {:href (str "?name=" (js/encodeURIComponent @*bookmark-name)
"&code=" (js/encodeURIComponent @*code))} "Copy this link to share ⤴️"])]]))
(rdom/render [workspace] (.getElementById js/document "app"))