Spaces:
Running
Running
File size: 739 Bytes
e58f3c4 15615aa e58f3c4 6cb4b46 e58f3c4 6cb4b46 e58f3c4 6cb4b46 e58f3c4 15615aa ad37578 6cb4b46 ad37578 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
import { browser } from "$app/environment";
import { isDesktop } from "./isDesktop";
export async function share(url: string, title: string, appendLeafId: boolean = false) {
if (!browser) return;
// Retrieve the leafId from localStorage
const leafId = localStorage.getItem("leafId");
if (appendLeafId && leafId) {
// Use URL and URLSearchParams to add the leafId parameter
const shareUrl = new URL(url);
shareUrl.searchParams.append("leafId", leafId);
url = shareUrl.toString();
}
if (navigator.share && !isDesktop(window)) {
navigator.share({ url, title });
} else {
if (document.hasFocus()) {
await navigator.clipboard.writeText(url);
} else {
alert("Document is not focused. Please try again.");
}
}
}
|