diff --git a/playground/src/Editor/settings.ts b/playground/src/Editor/settings.ts index e67a584f9f..c6f58cd7d2 100644 --- a/playground/src/Editor/settings.ts +++ b/playground/src/Editor/settings.ts @@ -22,10 +22,13 @@ export function stringify(settings: Settings): string { /** * Persist the configuration to a URL. */ -export function persist(settingsSource: string, pythonSource: string) { - window.location.hash = lzstring.compressToEncodedURIComponent( +export async function persist(settingsSource: string, pythonSource: string) { + const hash = lzstring.compressToEncodedURIComponent( settingsSource + "$$$" + pythonSource, ); + await navigator.clipboard.writeText( + window.location.href.split("#")[0] + "#" + hash, + ); } /** diff --git a/playground/src/Editor/utils.ts b/playground/src/Editor/utils.ts new file mode 100644 index 0000000000..233b0dcc00 --- /dev/null +++ b/playground/src/Editor/utils.ts @@ -0,0 +1,7 @@ +export async function copyTextToClipboard(text: string) { + if ("clipboard" in navigator) { + return await navigator.clipboard.writeText(text); + } else { + return document.execCommand("copy", true, text); + } +}