From f4df03684d75f26f3e88cf64fbdfc3292900d6b4 Mon Sep 17 00:00:00 2001 From: sorax Date: Tue, 28 Nov 2023 22:24:40 +0100 Subject: [PATCH] feat: bookmarklet --- lib/radiator_web/live/admin_live/index.html.heex | 6 +++--- lib/radiator_web/live/outline_live/index.ex | 15 +++++++++++++++ .../live/outline_live/index.html.heex | 8 ++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/radiator_web/live/admin_live/index.html.heex b/lib/radiator_web/live/admin_live/index.html.heex index a5c23b10..2697b930 100644 --- a/lib/radiator_web/live/admin_live/index.html.heex +++ b/lib/radiator_web/live/admin_live/index.html.heex @@ -4,8 +4,8 @@

Tools to create and manage your prodcasts

-
- <.link href={~p"/admin/accounts"} class="flex my-6 bg-[#f0f4f4]"> +
+ <.link href={~p"/admin/accounts"} class="flex bg-[#f0f4f4]">
<.icon name="hero-users" class="w-12 h-12" />
@@ -13,7 +13,7 @@ Accounts - <.link href={~p"/admin/outline"} class="flex my-6 bg-[#f0f4f4]"> + <.link href={~p"/admin/outline"} class="flex bg-[#f0f4f4]">
<.icon name="hero-list-bullet" class="w-12 h-12" />
diff --git a/lib/radiator_web/live/outline_live/index.ex b/lib/radiator_web/live/outline_live/index.ex index afc1b4a5..1f6a78c0 100644 --- a/lib/radiator_web/live/outline_live/index.ex +++ b/lib/radiator_web/live/outline_live/index.ex @@ -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}") @@ -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 diff --git a/lib/radiator_web/live/outline_live/index.html.heex b/lib/radiator_web/live/outline_live/index.html.heex index d066f130..31fac109 100644 --- a/lib/radiator_web/live/outline_live/index.html.heex +++ b/lib/radiator_web/live/outline_live/index.html.heex @@ -4,6 +4,14 @@

Collect and structure links and content for your prodcast

+
+

Bookmarklet

+

+ Drag & Drop this link in your Browser-Bookmarks: + Save in Radiator +

+
+

Inbox