feat: add ability to shorten url

This commit is contained in:
2025-07-08 03:35:27 +00:00
parent bc34966fbc
commit 6498dcb2ba
4 changed files with 172 additions and 8 deletions

36
src/utils/clipboard.ts Normal file
View File

@@ -0,0 +1,36 @@
export function copyToClipboard(text: string): Promise<void> {
if (navigator.clipboard && window.isSecureContext) {
// ✅ Modern way
return navigator.clipboard.writeText(text);
} else {
// 🚨 Fallback for insecure context or unsupported browsers
const textArea = document.createElement('textarea');
textArea.value = text;
// Avoid scrolling to bottom
textArea.style.position = 'fixed';
textArea.style.top = '0';
textArea.style.left = '0';
textArea.style.width = '2em';
textArea.style.height = '2em';
textArea.style.padding = '0';
textArea.style.border = 'none';
textArea.style.outline = 'none';
textArea.style.boxShadow = 'none';
textArea.style.background = 'transparent';
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
document.execCommand('copy');
} catch (err) {
console.error('Fallback: Oops, unable to copy', err);
}
document.body.removeChild(textArea);
return Promise.resolve();
}
}