|
import { browser } from "$app/environment"; |
|
import { isDesktop } from "./isDesktop"; |
|
|
|
export async function share(url: string, title: string, appendLeafId: boolean = false) { |
|
if (!browser) return; |
|
|
|
|
|
const leafId = localStorage.getItem("leafId"); |
|
|
|
if (appendLeafId && leafId) { |
|
|
|
const shareUrl = new URL(url); |
|
shareUrl.searchParams.append("leafId", leafId); |
|
url = shareUrl.toString(); |
|
} |
|
|
|
if (navigator.share && !isDesktop(window)) { |
|
navigator.share({ url, title }); |
|
} else { |
|
|
|
|
|
|
|
|
|
|
|
await new Promise((resolve) => setTimeout(resolve, 250)); |
|
await navigator.clipboard.writeText(url); |
|
} |
|
} |
|
|