diff --git a/.DS_Store b/.DS_Store index f8f9e51..70fdd9b 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/delete.png b/delete.png new file mode 100644 index 0000000..f777ca9 Binary files /dev/null and b/delete.png differ diff --git a/manifest.json b/manifest.json index 63d9417..8e21a7e 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "渠道应用开发部知识库", - "version": "1.0.2", + "version": "1.1", "description": "通过关键词快速搜索内部文档", "permissions": ["storage"], "host_permissions": [ diff --git a/popup.html b/popup.html index cc6b129..adbf4a5 100644 --- a/popup.html +++ b/popup.html @@ -6,25 +6,31 @@ -
- -
-

渠道应用开发部知识库

- 跳转OA -
+
+ +
+

渠道应用开发部知识库

+ 跳转OA +
+
+ +
+ -
- + + - \ No newline at end of file + diff --git a/popup.js b/popup.js index cd2cc60..bafb03d 100644 --- a/popup.js +++ b/popup.js @@ -1,21 +1,33 @@ document.addEventListener("DOMContentLoaded", () => { const input = document.getElementById("searchInput"); const searchBtn = document.getElementById("searchBtn"); + const clearHistoryBtn = document.getElementById("clearHistoryBtn"); const resultBox = document.getElementById("results"); const historyBox = document.getElementById("historyTags"); + const historyWrapper = document.getElementById("historyWrapper"); let currentPage = 1; let totalPages = 1; let lastKeywords = []; function log(...args) { - console.log("[v1.0.2]", ...args); + try { + const version = chrome.runtime?.getManifest?.().version || "dev"; + console.log(`[v${version}]`, ...args); + } catch (e) { + console.log("[v?]", ...args); + } } function showLoading() { resultBox.innerHTML = "
  • 加载中...
  • "; } + function clearResults() { + resultBox.innerHTML = ""; + historyWrapper.classList.add("hidden"); + } + function renderPagination() { const pagination = document.createElement("div"); pagination.className = "pagination"; @@ -38,10 +50,7 @@ document.addEventListener("DOMContentLoaded", () => { } function updateHistory(keyword) { - if (!chrome?.storage?.local) { - log("chrome.storage.local 不可用,跳过历史记录"); - return; - } + if (!chrome?.storage?.local) return; chrome.storage.local.get(["searchHistory"], (res) => { let history = res.searchHistory || []; history = [keyword, ...history.filter(item => item !== keyword)]; @@ -56,7 +65,7 @@ document.addEventListener("DOMContentLoaded", () => { const history = res.searchHistory || []; historyBox.innerHTML = ""; if (history.length === 0) { - historyBox.classList.add("hidden"); + historyWrapper.classList.add("hidden"); return; } @@ -71,7 +80,7 @@ document.addEventListener("DOMContentLoaded", () => { historyBox.appendChild(tag); }); - historyBox.classList.remove("hidden"); + historyWrapper.classList.remove("hidden"); }); } @@ -135,7 +144,10 @@ document.addEventListener("DOMContentLoaded", () => { function triggerSearch() { const inputValue = input.value.trim(); - if (!inputValue) return; + if (!inputValue) { + clearResults(); + return; + } const keywords = inputValue.split(/\s+/).filter(Boolean); updateHistory(inputValue); fetchResults(keywords, 1); @@ -147,9 +159,20 @@ document.addEventListener("DOMContentLoaded", () => { }); input.addEventListener("focus", renderHistoryTags); + input.addEventListener("input", () => { + if (!input.value.trim()) clearResults(); + }); + input.addEventListener("blur", () => { - setTimeout(() => historyBox.classList.add("hidden"), 200); + setTimeout(() => historyWrapper.classList.add("hidden"), 200); + }); + + clearHistoryBtn.addEventListener("click", () => { + chrome.storage.local.remove("searchHistory", () => { + log("历史记录已清空"); + renderHistoryTags(); + }); }); log("插件初始化完成"); -}); \ No newline at end of file +}); diff --git a/styles.css b/styles.css index 4e70952..24a97fb 100644 --- a/styles.css +++ b/styles.css @@ -146,4 +146,64 @@ h1 { .pagination button:hover { background-color: #ddd; -} \ No newline at end of file +} + +/* 基础结构样式保持不变,新增按钮样式 */ + +#clearHistoryBtn { + background: #f8f8f8; + border: 1px solid #ccc; + border-radius: 4px; + font-size: 14px; + padding: 0 10px; + cursor: pointer; + line-height: 28px; + height: 32px; +} + +#clearHistoryBtn:hover { + background-color: #eee; +} + +/* 原样式基础上追加 */ +.history-wrapper { + margin-bottom: 10px; +} + +.history-header { + display: flex; + justify-content: space-between; + align-items: center; + font-size: 13px; + margin-bottom: 6px; +} + +#clearHistoryBtn { + background: #f8f8f8; + border: 1px solid #ccc; + border-radius: 4px; + font-size: 14px; + padding: 2px 8px; + cursor: pointer; + line-height: 20px; +} + +#clearHistoryBtn:hover { + background-color: #eee; +} + +.delete-icon { + width: 16px; + height: 16px; + max-width: 100%; + object-fit: contain; + cursor: pointer; + opacity: 0.6; + transition: opacity 0.2s; +} + +.delete-icon:hover { + opacity: 1; + background-color: #f0f0f0; + border-radius: 3px; +}