Delete utils.js

This commit is contained in:
风之暇想
2025-07-20 11:52:57 +08:00
committed by GitHub
parent 36413c5ff4
commit 3eaed825bf

View File

@@ -1,8 +0,0 @@
const DEFAULT_PASSWORD='a184f7b849ffffed24d266a30298c72ef2f5ad040db73bf37151fac767630728';const STORAGE_KEYS={THEME_MODE:'theme_mode',OUTPUT_MODE:'output_mode'};async function handleStream(stream,writerData){const writer=stream.writable.getWriter();writer.write(writerData);writer.close();const reader=stream.readable.getReader();const chunks=[];while(true){const{done,value}=await reader.read();if(done)break;chunks.push(value);}
return new Blob(chunks).arrayBuffer();}
const utils={arrayBufferToBase64(buffer){let binary='';const bytes=new Uint8Array(buffer);for(let i=0;i<bytes.byteLength;i++){binary+=String.fromCharCode(bytes[i]);}
return btoa(binary);},base64ToArrayBuffer(base64){const binaryString=atob(base64);const bytes=new Uint8Array(binaryString.length);for(let i=0;i<binaryString.length;i++){bytes[i]=binaryString.charCodeAt(i);}
return bytes.buffer;},stringToArrayBuffer(str){return new TextEncoder().encode(str).buffer;},arrayBufferToString(buffer){return new TextDecoder().decode(buffer);},generateRandomBytes(length){return crypto.getRandomValues(new Uint8Array(length));},async compressData(data,method='deflate'){if(!window.CompressionStream)throw new Error('当前浏览器不支持CompressionStream API');const cs=new CompressionStream(method);return handleStream(cs,data);},async decompressData(data,method='deflate'){if(!window.DecompressionStream)throw new Error('当前浏览器不支持DecompressionStream API');const ds=new DecompressionStream(method);return handleStream(ds,data);},generatePassword(length){const charset='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+~`|}{[]:;?><,./-=';let password='';for(let i=0;i<length;i++){const randomIndex=Math.floor(Math.random()*charset.length);password+=charset.charAt(randomIndex);}
return password;},copyToClipboard(text){navigator.clipboard.writeText(text).catch(err=>{console.error('复制失败:',err);showNotification('复制到剪贴板失败,请手动复制',false);});},detectCiphertextType(ciphertext){if(/^[A-Za-z0-9+/=]+$/.test(ciphertext)){return'base64';}
const emojiRegex=/[\u{1F600}-\u{1F64F}\u{1F300}-\u{1F5FF}\u{1F680}-\u{1F6FF}\u{1F1E0}-\u{1F1FF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}]/u;if(emojiRegex.test(ciphertext)){return'emoji';}
return'chinese';},saveThemeMode(mode){if(['light','dark'].includes(mode)){localStorage.setItem(STORAGE_KEYS.THEME_MODE,mode);}},getSavedThemeMode(){return localStorage.getItem(STORAGE_KEYS.THEME_MODE)||null;},saveOutputMode(mode){if(['chinese','base64','emoji'].includes(mode)){localStorage.setItem(STORAGE_KEYS.OUTPUT_MODE,mode);}},getSavedOutputMode(){return localStorage.getItem(STORAGE_KEYS.OUTPUT_MODE)||'chinese';}};