File size: 3,521 Bytes
8ffb677
9bdc593
8ffb677
9bdc593
 
 
 
8ffb677
 
9bdc593
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8ffb677
9bdc593
 
 
 
 
 
 
8ffb677
9bdc593
 
 
 
 
 
 
 
 
 
 
cc826a1
9bdc593
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8ffb677
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<!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">清理多余换行、空白字符和常见中英文标点混用问题。</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="mode">清理模式</label>
            <select id="mode">
              <option value="standard">标准</option>
              <option value="compact">紧凑</option>
              <option value="none">仅标点规范</option>
            </select>
          </div>
          <div class="plugin-field">
            <label class="plugin-label" for="file">从文件读取,可选</label>
            <input id="file" type="file" accept=".md,.txt" onchange="loadFile()">
          </div>
          <textarea id="inputText" placeholder="粘贴需要清理的文本"></textarea>
          <button class="plugin-button" onclick="processText()">清理文本</button>
        </div>
      </div>

      <div class="plugin-panel">
        <h2 class="plugin-panel-title">输出</h2>
        <pre id="output" class="plugin-output">等待清理结果。</pre>
      </div>
    </section>
  </main>

  <script src="/static/plugin-ui.js"></script>
  <script>
    const API = "/plugins/text/api";

    async function loadStatus() {
      try {
        const data = await PluginUI.request(`${API}/status`);
        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 loadFile() {
      try {
        const input = document.getElementById("file");
        if (!input.files.length) return;
        const form = new FormData();
        form.append("file", input.files[0]);
        const data = await PluginUI.request(`${API}/upload`, { method: "POST", body: form });
        document.getElementById("inputText").value = data.content || "";
        PluginUI.showMessage("message", `已读取文件:${data.filename}`);
      } catch (error) {
        PluginUI.showMessage("message", error.message, "error");
      }
    }

    async function processText() {
      try {
        const form = new FormData();
        form.append("text", document.getElementById("inputText").value);
        form.append("mode", document.getElementById("mode").value);
        const data = await PluginUI.request(`${API}/process`, { method: "POST", body: form });
        PluginUI.setText("output", data.cleaned_text || "");
        PluginUI.showMessage("message", `清理完成:${data.original_char_count} -> ${data.cleaned_char_count} 字符`);
      } catch (error) {
        PluginUI.showMessage("message", error.message, "error");
      }
    }

    loadStatus();
  </script>
</body>
</html>