mirror of
				https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
				synced 2025-11-04 08:13:43 +08:00 
			
		
		
		
	fix(utils): 修复复制问题
This commit is contained in:
		
							
								
								
									
										28
									
								
								app/utils.ts
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								app/utils.ts
									
									
									
									
									
								
							@@ -6,17 +6,23 @@ export function trimTopic(topic: string) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export async function copyToClipboard(text: string) {
 | 
			
		||||
  try {
 | 
			
		||||
    await navigator.clipboard.writeText(text);
 | 
			
		||||
  } catch (error) {
 | 
			
		||||
    const textarea = document.createElement("textarea");
 | 
			
		||||
    textarea.value = text;
 | 
			
		||||
    document.body.appendChild(textarea);
 | 
			
		||||
    textarea.select();
 | 
			
		||||
    document.execCommand("copy");
 | 
			
		||||
    document.body.removeChild(textarea);
 | 
			
		||||
  } finally {
 | 
			
		||||
    showToast(Locale.Copy.Success);
 | 
			
		||||
  if (navigator.clipboard) {
 | 
			
		||||
    navigator.clipboard.writeText(text).catch(err => {
 | 
			
		||||
      console.error('Failed to copy: ', err);
 | 
			
		||||
    });
 | 
			
		||||
  } else {
 | 
			
		||||
    const textArea = document.createElement('textarea');
 | 
			
		||||
    textArea.value = text;
 | 
			
		||||
    document.body.appendChild(textArea);
 | 
			
		||||
    textArea.focus();
 | 
			
		||||
    textArea.select();
 | 
			
		||||
    try {
 | 
			
		||||
      document.execCommand('copy');
 | 
			
		||||
      console.log('Text copied to clipboard');
 | 
			
		||||
    } catch (err) {
 | 
			
		||||
      console.error('Failed to copy: ', err);
 | 
			
		||||
    }
 | 
			
		||||
    document.body.removeChild(textArea);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user