大学目录生成工具 - 编码修复版

编码修复说明

已修复文件编码问题,现在使用UTF-8编码并添加BOM标记,确保中文正确显示。

如果下载的文件仍有乱码,请尝试以下方法:

使用说明:上传包含大学介绍文件的多个HTML文件,系统将自动提取大学名称并生成目录结构。

格式要求:每个HTML文件应包含类似以下格式的标题:

<h4 id="81-上海大学(211)-1"><strong>81. 上海大学(211)</strong></h4>

系统将提取数字编号和大学名称,生成规范的目录结构。

测试示例

如果您没有测试文件,可以使用以下示例内容创建HTML文件进行测试:

<h4 id="1-北京大学(c9、法学四系)-1"><strong>1. 北京大学(C9、法学四系)</strong></h4> <h4 id="2-清华大学(c9)-1"><strong>2. 清华大学(C9)</strong></h4> <h4 id="81-上海大学(211)-1"><strong>81. 上海大学(211)</strong></h4>

处理选项

勾选后,系统将修改每个原始HTML文件,添加导航链接和锚点
使用更全面的正则表达式提取所有大学信息(包括非标准格式)
为文件添加UTF-8 BOM标记,确保中文正确显示

上传HTML文件

拖放文件到此处或点击下方按钮选择多个HTML文件

未选择文件

处理中...

处理结果

目录预览
大学列表
更新内容
修改的文件

生成的目录预览:

提取的大学列表:

生成的更新内容:

修改的文件预览:

\n`; downloadFile('中国重点大学特色与对比分析总目录.htm', content, 'text/html'); }; downloadUpdatedBtn.onclick = function() { downloadFile('大学更新内容.txt', updatedFilesHTML, 'text/plain'); }; downloadAllBtn.onclick = function() { const zip = new JSZip(); // 添加总目录文件 const directoryContent = `\n\n\n\n中国重点大学特色与对比分析总目录\n\n\n${directoryHTML}\n\n`; zip.file("中国重点大学特色与对比分析总目录.htm", addBOM.checked ? addUTF8BOM(directoryContent) : directoryContent); // 添加更新内容文件 zip.file("大学更新内容.txt", addBOM.checked ? addUTF8BOM(updatedFilesHTML) : updatedFilesHTML); // 添加修改后的HTML文件 if (modifyOriginalFiles.checked) { for (const filename in modifiedFiles) { // 确保HTML文件有正确的编码声明 let content = modifiedFiles[filename]; if (!content.includes('charset=')) { content = content.replace('', '\n'); } zip.file(filename, addBOM.checked ? addUTF8BOM(content) : content); } } // 添加大学列表 let universityListText = "提取的大学列表:\n\n"; universities.forEach(uni => { universityListText += `${uni.anchor}. ${uni.name} (文件: ${uni.filename})\n`; }); zip.file("大学列表.txt", addBOM.checked ? addUTF8BOM(universityListText) : universityListText); // 生成ZIP zip.generateAsync({type:"blob"}).then(function(content) { const a = document.createElement("a"); const url = URL.createObjectURL(content); a.href = url; a.download = "大学目录生成结果.zip"; document.body.appendChild(a); a.click(); setTimeout(function() { document.body.removeChild(a); URL.revokeObjectURL(url); }, 0); }); }; } // 添加UTF-8 BOM标记 function addUTF8BOM(str) { return '\uFEFF' + str; } // 下载文件 function downloadFile(filename, content, mimeType) { const blob = new Blob([addBOM.checked ? addUTF8BOM(content) : content], {type: mimeType + ';charset=utf-8'}); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = filename; document.body.appendChild(a); a.click(); document.body.removeChild(a); URL.revokeObjectURL(url); } // 重置应用 function resetApp() { selectedFiles = []; universities = []; directoryHTML = ''; updatedFilesHTML = ''; modifiedFiles = {}; fileInput.value = ''; fileInfo.textContent = '未选择文件'; fileList.innerHTML = ''; processBtn.disabled = true; results.style.display = 'none'; progressContainer.style.display = 'none'; hideError(); hideSuccess(); debugInfo.style.display = 'none'; debugInfo.textContent = ''; extractionStats.style.display = 'none'; // 重置标签 tabs.forEach((tab, index) => { if (index === 0) { tab.classList.add('active'); } else { tab.classList.remove('active'); } }); tabContents.forEach((content, index) => { if (index === 0) { content.classList.add('active'); } else { content.classList.remove('active'); } }); } // 辅助函数 function formatFileSize(bytes) { if (bytes === 0) return '0 Bytes'; const k = 1024; const sizes = ['Bytes', 'KB', 'MB', 'GB']; const i = Math.floor(Math.log(bytes) / Math.log(k)); return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]; } function showError(message) { errorMessage.textContent = message; errorMessage.style.display = 'block'; } function hideError() { errorMessage.style.display = 'none'; } function showSuccess(message) { successMessage.textContent = message; successMessage.style.display = 'block'; } function hideSuccess() { successMessage.style.display = 'none'; } });