commit e6655dd36c88235af7af5a03cfaa4d35fc50b3fd Author: luke Date: Thu May 22 07:23:32 2025 +0800 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..85e7c1d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.idea/ diff --git a/icon.png b/icon.png new file mode 100644 index 0000000..a1bbb5c Binary files /dev/null and b/icon.png differ diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..9d3e2be --- /dev/null +++ b/manifest.json @@ -0,0 +1,15 @@ +{ + "manifest_version": 3, + "name": "知识库搜索助手", + "version": "1.0", + "description": "通过关键词从企业知识库中搜索内容。", + "permissions": [], + "action": { + "default_popup": "popup.html", + "default_icon": { + "16": "icon.png", + "48": "icon.png", + "128": "icon.png" + } + } +} diff --git a/popup.html b/popup.html new file mode 100644 index 0000000..dab443f --- /dev/null +++ b/popup.html @@ -0,0 +1,16 @@ + + + + + 知识库搜索助手 + + + +
+ + + +
+ + + diff --git a/popup.js b/popup.js new file mode 100644 index 0000000..b8aa955 --- /dev/null +++ b/popup.js @@ -0,0 +1,52 @@ +document.getElementById("searchBtn").addEventListener("click", async () => { + const input = document.getElementById("searchInput").value.trim(); + const resultBox = document.getElementById("results"); + resultBox.innerHTML = ""; + + if (!input) return; + + const keywords = input.split(/\s+/).filter(Boolean); + const keywordGroups = keywords.map(k => [k]); + + try { + const response = await fetch("http://app.wisdompulse.cn/search", { + method: "POST", + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify({ + keywordGroups, + page: 1, + size: 10 + }) + }); + + const data = await response.json(); + + if (!data.results || data.results.length === 0) { + resultBox.innerHTML = "
  • 未找到相关文档
  • "; + return; + } + + data.results.forEach(doc => { + const li = document.createElement("li"); + + const link = document.createElement("a"); + link.href = `http://app.wisdompulse.cn/html/${doc.filepath}`; + link.target = "_blank"; + link.textContent = doc.filename; + + const snippet = document.createElement("div"); + snippet.className = "summary"; + snippet.innerHTML = doc.summary?.slice(0, 300) + "..."; + + li.appendChild(link); + li.appendChild(snippet); + resultBox.appendChild(li); + }); + + } catch (err) { + console.error("搜索失败", err); + resultBox.innerHTML = "
  • 搜索失败,请检查网络或服务状态。
  • "; + } +}); diff --git a/styles.css b/styles.css new file mode 100644 index 0000000..4607a85 --- /dev/null +++ b/styles.css @@ -0,0 +1,57 @@ +body { + font-family: Arial, sans-serif; + width: 320px; + padding: 10px; + background-color: #f9f9f9; +} + +.container { + display: flex; + flex-direction: column; +} + +input { + padding: 8px; + margin-bottom: 8px; + border: 1px solid #ccc; + border-radius: 4px; +} + +button { + padding: 8px; + background-color: #007bff; + color: white; + border: none; + border-radius: 4px; + cursor: pointer; +} + +button:hover { + background-color: #0056b3; +} + +#results { + list-style: none; + padding: 0; + margin-top: 10px; +} + +#results li { + margin-bottom: 12px; +} + +#results a { + font-weight: bold; + color: #007bff; + text-decoration: none; +} + +#results a:hover { + text-decoration: underline; +} + +#results .summary { + font-size: 12px; + color: #555; + margin-top: 4px; +}