正文
增加 39 行删除 39 行
65 行未改动6667686970717273746 行未改动818283848586878889909192939495969798991001011021031046 行未改动11111211311411511611711811918 行未改动13813914014114214314414514614714814915015115215315415550 行未改动20620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226312 行未改动27627727827928028128228328427 行未改动31231331431531631731831932019 行未改动3403413423433443453463473484 行未改动35335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939014 行未改动4054064074084094104114124134144154164174184194204214224234244252 行未改动42842943043143243343443543643743843944044116 行未改动45845946046146246346446546646746846947047113 行未改动65 行未改动<div class="glass-effect rounded-2xl shadow-xl p-6 card-hover"><h2 class="text-2xl font-semibold text-white mb-6"><i class="fas fa-keyboard mr-2"></i>压缩字符串输入</h2><div class="space-y-6"><!-- 格式说明 --><div class="bg-white/20 p-4 rounded-lg"><h3 class="text-white font-medium mb-2">支持的格式:</h3>6 行未改动<!-- 输入框 --><div><label class="block text-white font-medium mb-3">输入压缩字符串:</label><textareaid="inputString"class="w-full h-40 p-4 bg-white/90 border border-white/30 rounded-xl focus:ring-2 focus:ring-white focus:border-white resize-none transition-all duration-200"placeholder="请输入压缩字符串,如:3[abc]、2[3[a]b] 或 2[ab]3[cd]">2[3[a]b]</textarea></div><!-- 控制按钮 --><div class="flex gap-4"><buttonid="decompressBtn"class="flex-1 bg-white text-purple-600 hover:bg-white/90 font-semibold py-3 px-6 rounded-xl transition-all duration-200 flex items-center justify-center"><i class="fas fa-play-circle mr-2"></i>执行解压</button><buttonid="clearBtn"class="px-6 bg-white/20 text-white hover:bg-white/30 font-medium py-3 rounded-xl transition-all duration-200"><i class="fas fa-broom mr-2"></i>清空6 行未改动<div class="glass-effect rounded-2xl shadow-xl p-6 card-hover"><h2 class="text-2xl font-semibold text-white mb-6"><i class="fas fa-file-export mr-2"></i>解压结果与过程</h2><div class="space-y-6"><!-- 解压过程 --><div><label class="block text-white font-medium mb-3">解压过程追踪:</label>18 行未改动<span>输出长度: 0</span><span class="mx-3">|</span><span>压缩比: 0%</span></div><div class="flex gap-2"><buttonid="copyBtn"class="bg-white/20 text-white hover:bg-white/30 px-4 py-2 rounded-lg transition-colors duration-200 disabled:opacity-50 disabled:cursor-not-allowed"disabled><i class="fas fa-copy mr-1"></i>复制结果</button><buttonid="saveBtn"class="bg-white/20 text-white hover:bg-white/30 px-4 py-2 rounded-lg transition-colors duration-200"><i class="fas fa-save mr-1"></i>保存记录50 行未改动decompress(s) {this.processLog = [];this.processLog.push({type: 'info', message: `开始解压字符串: "${s}"`});const result = this._decompressRecursive(s, 0);this.processLog.push({type: 'success', message: `解压完成!最终结果: "${result}"`});this.saveToHistory(s, result);return result;}_decompressRecursive(s, depth) {let current = '';let num = 0;const indent = ' '.repeat(depth);this.processLog.push({type: 'process', message: `${indent}深度 ${depth}: 处理 "${s}"`});for (let i = 0; i < s.length; i++) {const char = s[i];if (this.isDigit(char)) {num = num * 10 + parseInt(char);this.processLog.push({type: 'number', message: `${indent}读取数字: ${num}`});} else if (char === '[') {this.processLog.push({type: 'bracket', message: `${indent}遇到 '[', 开始递归处理`});let j = i + 1;let bracketCount = 1;while (j < s.length && bracketCount > 0) {if (s[j] === '[') bracketCount++;if (s[j] === ']') bracketCount--;j++;}const innerStr = s.substring(i + 1, j - 1);const innerResult = this._decompressRecursive(innerStr, depth + 1);this.processLog.push({type: 'recursion', message: `${indent}递归返回: "${innerResult}" × ${num}`});current += innerResult.repeat(Math.max(1, num));this.processLog.push({type: 'current', message: `${indent}当前结果: "${current}"`});num = 0;i = j - 1;} else if (char === ']') {break;} else {current += char;this.processLog.push({type: 'character', message: `${indent}添加字符 "${char}", 当前: "${current}"`});}}return current;}isDigit(char) {12 行未改动inputLength: input.length,outputLength: output.length,compressionRatio: output.length > 0 ? ((1 - input.length / output.length) * 100).toFixed(1) : 0};this.history.unshift(record);this.history = this.history.slice(0, 20);localStorage.setItem('decompressHistory', JSON.stringify(this.history));}27 行未改动if (history.length === 0) {historyDisplay.innerHTML = '<div class="text-white/60 text-center py-4">暂无历史记录</div>';return;}historyDisplay.innerHTML = history.map(record => `<div class="bg-white/10 p-4 rounded-lg border border-white/20"><div class="flex justify-between items-start mb-2"><code class="text-white/90 bg-white/20 px-2 py-1 rounded text-sm">${record.input}</code>19 行未改动try {const result = decompressor.decompress(input);const processLog = decompressor.getProcessLog();// 显示解压过程processDisplay.innerHTML = processLog.map(log => {const colorClass = {info: 'text-blue-300',4 行未改动recursion: 'text-indigo-300',character: 'text-teal-300',current: 'text-orange-300'}[log.type] || 'text-white';return `<div class="py-1 border-b border-white/10 ${colorClass}">${log.message}</div>`;}).join('');// 显示最终结果resultDisplay.innerHTML = `<div class="text-green-300 font-mono text-lg break-all">${result}</div>`;// 更新统计信息const inputLen = input.length;const outputLen = result.length;const ratio = outputLen > 0 ? ((1 - inputLen / outputLen) * 100).toFixed(1) : 0;statsDisplay.innerHTML = `<span>输入长度: ${inputLen}</span><span class="mx-3">|</span><span>输出长度: ${outputLen}</span><span class="mx-3">|</span><span>压缩比: ${ratio}%</span>`;// 启用复制按钮copyBtn.disabled = false;copyBtn.classList.remove('bg-white/20');copyBtn.classList.add('bg-green-500/30', 'hover:bg-green-500/40');// 加载更新后的历史记录loadHistory();showNotification('解压成功!', 'success');} catch (error) {processDisplay.innerHTML = `<div class="text-red-300">错误: ${error.message}</div>`;resultDisplay.innerHTML = `<div class="text-red-300">解压失败</div>`;statsDisplay.innerHTML = `<span class="text-red-300">解析错误</span>`;14 行未改动if (!resultText || resultText === '解压结果将显示在这里') {showNotification('没有可复制的内容!', 'error');return;}navigator.clipboard.writeText(resultText).then(() => {const originalText = copyBtn.innerHTML;copyBtn.innerHTML = '<i class="fas fa-check mr-1"></i>已复制';copyBtn.classList.remove('bg-green-500/30', 'hover:bg-green-500/40');copyBtn.classList.add('bg-green-600', 'text-white');setTimeout(() => {copyBtn.innerHTML = originalText;copyBtn.classList.remove('bg-green-600', 'text-white');copyBtn.classList.add('bg-white/20');}, 2000);showNotification('结果已复制到剪贴板!', 'success');}).catch(() => {showNotification('复制失败!', 'error');});2 行未改动// 保存记录saveBtn.addEventListener('click', function() {const input = inputString.value.trim();const result = resultDisplay.textContent;if (!input || result === '解压结果将显示在这里') {showNotification('没有可保存的记录!', 'error');return;}showNotification('记录已保存!', 'success');});// 示例加载功能16 行未改动success: 'bg-green-500',error: 'bg-red-500',info: 'bg-blue-500'}[type];notification.className = `fixed top-4 right-4 ${bgColor} text-white px-6 py-3 rounded-xl shadow-lg transition-all duration-300 fade-in`;notification.innerHTML = `<i class="fas fa-${type === 'success' ? 'check' : type === 'error' ? 'exclamation-triangle' : 'info-circle'} mr-2"></i>${message}`;document.body.appendChild(notification);setTimeout(() => {notification.style.opacity = '0';notification.style.transform = 'translateX(100%)';setTimeout(() => {13 行未改动65 行未改动6667686970717273746 行未改动818283848586878889909192939495969798991001011021031046 行未改动11111211311411511611711811918 行未改动13813914014114214314414514614714814915015115215315415550 行未改动20620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226312 行未改动27627727827928028128228328427 行未改动31231331431531631731831932019 行未改动3403413423433443453463473484 行未改动35335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939014 行未改动4054064074084094104114124134144154164174184194204214224234244252 行未改动42842943043143243343443543643743843944044116 行未改动45845946046146246346446546646746846947047113 行未改动65 行未改动<div class="glass-effect rounded-2xl shadow-xl p-6 card-hover"><h2 class="text-2xl font-semibold text-white mb-6"><i class="fas fa-keyboard mr-2"></i>压缩字符串输入</h2><div class="space-y-6"><!-- 格式说明 --><div class="bg-white/20 p-4 rounded-lg"><h3 class="text-white font-medium mb-2">支持的格式:</h3>6 行未改动<!-- 输入框 --><div><label class="block text-white font-medium mb-3">输入压缩字符串:</label><textareaid="inputString"class="w-full h-40 p-4 bg-white/90 border border-white/30 rounded-xl focus:ring-2 focus:ring-white focus:border-white resize-none transition-all duration-200"placeholder="请输入压缩字符串,如:3[abc]、2[3[a]b] 或 2[ab]3[cd]">2[3[a]b]</textarea></div><!-- 控制按钮 --><div class="flex gap-4"><buttonid="decompressBtn"class="flex-1 bg-white text-purple-600 hover:bg-white/90 font-semibold py-3 px-6 rounded-xl transition-all duration-200 flex items-center justify-center"><i class="fas fa-play-circle mr-2"></i>执行解压</button><buttonid="clearBtn"class="px-6 bg-white/20 text-white hover:bg-white/30 font-medium py-3 rounded-xl transition-all duration-200"><i class="fas fa-broom mr-2"></i>清空6 行未改动<div class="glass-effect rounded-2xl shadow-xl p-6 card-hover"><h2 class="text-2xl font-semibold text-white mb-6"><i class="fas fa-file-export mr-2"></i>解压结果与过程</h2><div class="space-y-6"><!-- 解压过程 --><div><label class="block text-white font-medium mb-3">解压过程追踪:</label>18 行未改动<span>输出长度: 0</span><span class="mx-3">|</span><span>压缩比: 0%</span></div><div class="flex gap-2"><buttonid="copyBtn"class="bg-white/20 text-white hover:bg-white/30 px-4 py-2 rounded-lg transition-colors duration-200 disabled:opacity-50 disabled:cursor-not-allowed"disabled><i class="fas fa-copy mr-1"></i>复制结果</button><buttonid="saveBtn"class="bg-white/20 text-white hover:bg-white/30 px-4 py-2 rounded-lg transition-colors duration-200"><i class="fas fa-save mr-1"></i>保存记录50 行未改动decompress(s) {this.processLog = [];this.processLog.push({type: 'info', message: `开始解压字符串: "${s}"`});const result = this._decompressRecursive(s, 0);this.processLog.push({type: 'success', message: `解压完成!最终结果: "${result}"`});this.saveToHistory(s, result);return result;}_decompressRecursive(s, depth) {let current = '';let num = 0;const indent = ' '.repeat(depth);this.processLog.push({type: 'process', message: `${indent}深度 ${depth}: 处理 "${s}"`});for (let i = 0; i < s.length; i++) {const char = s[i];if (this.isDigit(char)) {num = num * 10 + parseInt(char);this.processLog.push({type: 'number', message: `${indent}读取数字: ${num}`});} else if (char === '[') {this.processLog.push({type: 'bracket', message: `${indent}遇到 '[', 开始递归处理`});let j = i + 1;let bracketCount = 1;while (j < s.length && bracketCount > 0) {if (s[j] === '[') bracketCount++;if (s[j] === ']') bracketCount--;j++;}const innerStr = s.substring(i + 1, j - 1);const innerResult = this._decompressRecursive(innerStr, depth + 1);this.processLog.push({type: 'recursion', message: `${indent}递归返回: "${innerResult}" × ${num}`});current += innerResult.repeat(Math.max(1, num));this.processLog.push({type: 'current', message: `${indent}当前结果: "${current}"`});num = 0;i = j - 1;} else if (char === ']') {break;} else {current += char;this.processLog.push({type: 'character', message: `${indent}添加字符 "${char}", 当前: "${current}"`});}}return current;}isDigit(char) {12 行未改动inputLength: input.length,outputLength: output.length,compressionRatio: output.length > 0 ? ((1 - input.length / output.length) * 100).toFixed(1) : 0};this.history.unshift(record);this.history = this.history.slice(0, 20);localStorage.setItem('decompressHistory', JSON.stringify(this.history));}27 行未改动if (history.length === 0) {historyDisplay.innerHTML = '<div class="text-white/60 text-center py-4">暂无历史记录</div>';return;}historyDisplay.innerHTML = history.map(record => `<div class="bg-white/10 p-4 rounded-lg border border-white/20"><div class="flex justify-between items-start mb-2"><code class="text-white/90 bg-white/20 px-2 py-1 rounded text-sm">${record.input}</code>19 行未改动try {const result = decompressor.decompress(input);const processLog = decompressor.getProcessLog();// 显示解压过程processDisplay.innerHTML = processLog.map(log => {const colorClass = {info: 'text-blue-300',4 行未改动recursion: 'text-indigo-300',character: 'text-teal-300',current: 'text-orange-300'}[log.type] || 'text-white';return `<div class="py-1 border-b border-white/10 ${colorClass}">${log.message}</div>`;}).join('');// 显示最终结果resultDisplay.innerHTML = `<div class="text-green-300 font-mono text-lg break-all">${result}</div>`;// 更新统计信息const inputLen = input.length;const outputLen = result.length;const ratio = outputLen > 0 ? ((1 - inputLen / outputLen) * 100).toFixed(1) : 0;statsDisplay.innerHTML = `<span>输入长度: ${inputLen}</span><span class="mx-3">|</span><span>输出长度: ${outputLen}</span><span class="mx-3">|</span><span>压缩比: ${ratio}%</span>`;// 启用复制按钮copyBtn.disabled = false;copyBtn.classList.remove('bg-white/20');copyBtn.classList.add('bg-green-500/30', 'hover:bg-green-500/40');// 加载更新后的历史记录loadHistory();showNotification('解压成功!', 'success');} catch (error) {processDisplay.innerHTML = `<div class="text-red-300">错误: ${error.message}</div>`;resultDisplay.innerHTML = `<div class="text-red-300">解压失败</div>`;statsDisplay.innerHTML = `<span class="text-red-300">解析错误</span>`;14 行未改动if (!resultText || resultText === '解压结果将显示在这里') {showNotification('没有可复制的内容!', 'error');return;}navigator.clipboard.writeText(resultText).then(() => {const originalText = copyBtn.innerHTML;copyBtn.innerHTML = '<i class="fas fa-check mr-1"></i>已复制';copyBtn.classList.remove('bg-green-500/30', 'hover:bg-green-500/40');copyBtn.classList.add('bg-green-600', 'text-white');setTimeout(() => {copyBtn.innerHTML = originalText;copyBtn.classList.remove('bg-green-600', 'text-white');copyBtn.classList.add('bg-white/20');}, 2000);showNotification('结果已复制到剪贴板!', 'success');}).catch(() => {showNotification('复制失败!', 'error');});2 行未改动// 保存记录saveBtn.addEventListener('click', function() {const input = inputString.value.trim();const result = resultDisplay.textContent;if (!input || result === '解压结果将显示在这里') {showNotification('没有可保存的记录!', 'error');return;}showNotification('记录已保存!', 'success');});// 示例加载功能16 行未改动success: 'bg-green-500',error: 'bg-red-500',info: 'bg-blue-500'}[type];notification.className = `fixed top-4 right-4 ${bgColor} text-white px-6 py-3 rounded-xl shadow-lg transition-all duration-300 fade-in`;notification.innerHTML = `<i class="fas fa-${type === 'success' ? 'check' : type === 'error' ? 'exclamation-triangle' : 'info-circle'} mr-2"></i>${message}`;document.body.appendChild(notification);setTimeout(() => {notification.style.opacity = '0';notification.style.transform = 'translateX(100%)';setTimeout(() => {13 行未改动