From 66fe7f47a22b5d585f294649bf592e13c9fe19d6 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Sat, 13 Apr 2024 12:51:48 +0100 Subject: [PATCH] get outer location and pass in to the iframe --- bskyembed/snippet/embed.ts | 10 +++++++++- bskyembed/src/components/link.tsx | 6 ++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/bskyembed/snippet/embed.ts b/bskyembed/snippet/embed.ts index f2b9b442eb..bd6912ccc7 100644 --- a/bskyembed/snippet/embed.ts +++ b/bskyembed/snippet/embed.ts @@ -59,9 +59,17 @@ function scan(node = document) { continue } + const ref_url = encodeURIComponent(location.origin + location.pathname) + + const searchParams = new URLSearchParams() + searchParams.set('id', id) + searchParams.set('ref_url', ref_url) + const iframe = document.createElement('iframe') iframe.setAttribute('data-bluesky-id', id) - iframe.src = `${EMBED_URL}/embed/${aturi.slice('at://'.length)}?id=${id}` + iframe.src = `${EMBED_URL}/embed/${aturi.slice( + 'at://'.length, + )}?${searchParams.toString()}` iframe.width = '100%' iframe.style.border = 'none' iframe.style.display = 'block' diff --git a/bskyembed/src/components/link.tsx b/bskyembed/src/components/link.tsx index db752542b5..64c2c9a83b 100644 --- a/bskyembed/src/components/link.tsx +++ b/bskyembed/src/components/link.tsx @@ -8,8 +8,14 @@ export function Link({ href: string className?: string } & h.JSX.HTMLAttributes) { + const searchParam = new URLSearchParams(window.location.search) + const ref_url = searchParam.get('ref_url') + const newSearchParam = new URLSearchParams() newSearchParam.set('ref_src', 'embed') + if (ref_url) { + newSearchParam.set('ref_url', ref_url) + } return (