Skip to content

Commit

Permalink
feat: bookmarklet
Browse files Browse the repository at this point in the history
  • Loading branch information
sorax committed Nov 29, 2023
1 parent 50de3c4 commit f4df036
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/radiator_web/live/admin_live/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
<p>Tools to create and manage your prodcasts</p>
</header>

<section class="my-12">
<.link href={~p"/admin/accounts"} class="flex my-6 bg-[#f0f4f4]">
<section class="grid grid-cols-1 gap-6 my-12">
<.link href={~p"/admin/accounts"} class="flex bg-[#f0f4f4]">
<div class="bg-[#f0f4f4] p-2">
<.icon name="hero-users" class="w-12 h-12" />
</div>
<div class="p-2 my-auto">
Accounts
</div>
</.link>
<.link href={~p"/admin/outline"} class="flex my-6 bg-[#f0f4f4]">
<.link href={~p"/admin/outline"} class="flex bg-[#f0f4f4]">
<div class="bg-[#f0f4f4] p-2">
<.icon name="hero-list-bullet" class="w-12 h-12" />
</div>
Expand Down
15 changes: 15 additions & 0 deletions lib/radiator_web/live/outline_live/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ defmodule RadiatorWeb.OutlineLive.Index do

socket
|> assign(:page_title, "Outline")
|> assign(:bookmarklet, get_bookmarklet(Endpoint.url() <> "/api/v1/outline"))
|> assign(:node, node)
|> assign(:form, to_form(changeset))
|> stream_configure(:nodes, dom_id: &"node-#{&1.uuid}")
Expand Down Expand Up @@ -68,4 +69,18 @@ defmodule RadiatorWeb.OutlineLive.Index do
|> stream_delete(:nodes, node)
|> reply(:noreply)
end

defp get_bookmarklet(api_uri) do
"""
javascript:(function(){
s=window.getSelection().toString();
c=s!=""?s:window.location.href;
xhr=new XMLHttpRequest();
xhr.open('POST','#{api_uri}',true);
xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xhr.send('content='+encodeURIComponent(c));
})()
"""
|> String.replace(["\n", " "], "")
end
end
8 changes: 8 additions & 0 deletions lib/radiator_web/live/outline_live/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
<p>Collect and structure links and content for your prodcast</p>
</header>

<section class="my-12">
<h2 class="text-2xl">Bookmarklet</h2>
<p>
Drag & Drop this link in your Browser-Bookmarks:
<a href={@bookmarklet} class="underline">Save in Radiator</a>
</p>
</section>

<section class="my-12">
<h2 class="text-2xl">Inbox</h2>

Expand Down

0 comments on commit f4df036

Please sign in to comment.