| <!DOCTYPE html> |
| <html lang="zh-CN"> |
| <head> |
| <meta charset="UTF-8"> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| <title>文档合并拆分</title> |
| <link rel="stylesheet" href="/static/plugin-ui.css"> |
| </head> |
| <body> |
| <main class="plugin-shell"> |
| <header class="plugin-header"> |
| <div> |
| <h1 class="plugin-title">文档合并拆分</h1> |
| <p class="plugin-subtitle">合并多个 Markdown/文本文件,或按章节拆分单个文档。</p> |
| </div> |
| <span id="statusPill" class="plugin-status">检查中</span> |
| </header> |
|
|
| <div id="message" class="plugin-message"></div> |
| <section class="plugin-grid equal"> |
| <div class="plugin-panel"> |
| <h2 class="plugin-panel-title">文档合并</h2> |
| <div class="plugin-stack"> |
| <div class="plugin-field"> |
| <label class="plugin-label" for="mergeFiles">文件列表</label> |
| <input id="mergeFiles" type="file" accept=".md,.txt" multiple> |
| </div> |
| <div class="plugin-field"> |
| <label class="plugin-label" for="mergeFormat">输出格式</label> |
| <select id="mergeFormat"> |
| <option value="md">Markdown</option> |
| <option value="txt">纯文本</option> |
| </select> |
| </div> |
| <button class="plugin-button" onclick="mergeDocuments()">合并并下载</button> |
| </div> |
| </div> |
|
|
| <div class="plugin-panel"> |
| <h2 class="plugin-panel-title">文档拆分</h2> |
| <div class="plugin-stack"> |
| <div class="plugin-field"> |
| <label class="plugin-label" for="splitFile">单个文档</label> |
| <input id="splitFile" type="file" accept=".md,.txt"> |
| </div> |
| <div class="plugin-field"> |
| <label class="plugin-label" for="splitFormat">输出格式</label> |
| <select id="splitFormat"> |
| <option value="md">Markdown</option> |
| <option value="txt">纯文本</option> |
| </select> |
| </div> |
| <button class="plugin-button" onclick="splitDocument()">拆分并下载 ZIP</button> |
| <p class="plugin-muted">拆分规则:识别“第X章”格式的章节标题。</p> |
| </div> |
| </div> |
| </section> |
|
|
| <section class="plugin-panel"> |
| <h2 class="plugin-panel-title">状态</h2> |
| <pre id="output" class="plugin-output">等待操作。</pre> |
| </section> |
| </main> |
|
|
| <script src="/static/plugin-ui.js"></script> |
| <script> |
| const API = "/plugins/doc/api"; |
| |
| async function loadStatus() { |
| try { |
| const data = await PluginUI.request(`${API}/status`); |
| PluginUI.setJson("output", data); |
| const pill = document.getElementById("statusPill"); |
| pill.textContent = data.enabled === false ? "插件未启用" : "可用"; |
| pill.className = `plugin-status ${data.enabled === false ? "warn" : "ok"}`; |
| } catch { |
| document.getElementById("statusPill").textContent = "状态未知"; |
| } |
| } |
| |
| async function mergeDocuments() { |
| try { |
| const input = document.getElementById("mergeFiles"); |
| if (!input.files.length) throw new Error("请选择至少一个文件"); |
| const form = new FormData(); |
| Array.from(input.files).forEach((file) => form.append("files", file)); |
| form.append("output_format", document.getElementById("mergeFormat").value); |
| const blob = await PluginUI.requestBlob(`${API}/merge`, { method: "POST", body: form }); |
| PluginUI.downloadBlob(blob, `merged_document.${document.getElementById("mergeFormat").value}`); |
| PluginUI.showMessage("message", "合并完成,文件已下载"); |
| } catch (error) { |
| PluginUI.showMessage("message", error.message, "error"); |
| } |
| } |
| |
| async function splitDocument() { |
| try { |
| const input = document.getElementById("splitFile"); |
| if (!input.files.length) throw new Error("请选择要拆分的文件"); |
| const form = new FormData(); |
| form.append("file", input.files[0]); |
| form.append("output_format", document.getElementById("splitFormat").value); |
| const blob = await PluginUI.requestBlob(`${API}/split`, { method: "POST", body: form }); |
| PluginUI.downloadBlob(blob, "split_documents.zip"); |
| PluginUI.showMessage("message", "拆分完成,ZIP 已下载"); |
| } catch (error) { |
| PluginUI.showMessage("message", error.message, "error"); |
| } |
| } |
| |
| loadStatus(); |
| </script> |
| </body> |
| </html> |
|
|