mirror of
https://github.com/Tony0410/readlater.git
synced 2026-05-24 22:01:41 +08:00
Fix clipboard copy with fallback for iOS/older browsers
- Add try-catch around navigator.clipboard.writeText - Add fallback using textarea + execCommand for older browsers - Add final fallback using prompt() to show URL if all else fails Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -91,9 +91,28 @@ export default function SettingsPage() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const copyToClipboard = async (text: string) => {
|
const copyToClipboard = async (text: string) => {
|
||||||
await navigator.clipboard.writeText(text);
|
try {
|
||||||
setCopied(true);
|
await navigator.clipboard.writeText(text);
|
||||||
setTimeout(() => setCopied(false), 2000);
|
setCopied(true);
|
||||||
|
setTimeout(() => setCopied(false), 2000);
|
||||||
|
} catch {
|
||||||
|
// Fallback for older browsers or permission denied
|
||||||
|
const textArea = document.createElement("textarea");
|
||||||
|
textArea.value = text;
|
||||||
|
textArea.style.position = "fixed";
|
||||||
|
textArea.style.left = "-9999px";
|
||||||
|
document.body.appendChild(textArea);
|
||||||
|
textArea.select();
|
||||||
|
try {
|
||||||
|
document.execCommand("copy");
|
||||||
|
setCopied(true);
|
||||||
|
setTimeout(() => setCopied(false), 2000);
|
||||||
|
} catch {
|
||||||
|
// If all else fails, show the URL in a prompt
|
||||||
|
window.prompt("Copy this URL:", text);
|
||||||
|
}
|
||||||
|
document.body.removeChild(textArea);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleImport = async () => {
|
const handleImport = async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user