From 9c33a98984a64ebb7eb24753dde87152cd81e0ca Mon Sep 17 00:00:00 2001 From: luke Date: Sun, 25 May 2025 09:16:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=901.1=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .DS_Store | Bin 6148 -> 6148 bytes delete.png | Bin 0 -> 4673 bytes manifest.json | 2 +- popup.html | 38 ++++++++++++++++++------------- popup.js | 43 ++++++++++++++++++++++++++-------- styles.css | 62 +++++++++++++++++++++++++++++++++++++++++++++++++- 6 files changed, 117 insertions(+), 28 deletions(-) create mode 100644 delete.png diff --git a/.DS_Store b/.DS_Store index f8f9e51d6e94b8091546972b153baf695d5dfe7d..70fdd9b9fa033b3261c4e7efb54960beca4ab947 100644 GIT binary patch delta 170 zcmZoMXffEJ##n#9hJk^Bg+Y%YogtHsPZXz%jNg|Tl?t4=0l85VgRBJ BDX0Jd diff --git a/delete.png b/delete.png new file mode 100644 index 0000000000000000000000000000000000000000..f777ca93a182f501090278987a8dbfb4116fa982 GIT binary patch literal 4673 zcmeHLX*8Q#+cpG2RAOqBwxMZ_MQWa-(wd4^Yc4{FsfLzPMF=g4F*OIJM~n8Dt4h^a z#L(cxJUgdqs;MX{q2Bae>-+cp`hI@v{CJ+do_k+w@4fDI-Pd#7n|Ra0h>zzC4+{$m zpNTQbiaGZDet?|JcZFSL0drstvNF2LQaK>L%EAI+n4k>qJaXP}@=Jnuh2iE4CNI{* zTcD(yr;?08oKFMoEVhcD{iO0d>> zb;?ngOaGn2Ufff{CSS+*z{58`6k_oL#^T+1F|eQIh^48yTX)|SOnK+d>1t{oB8#u@ zX~l{{@$Vcee1}!ezCOXNS$9%$T2qQ%*Enx5MmCW^cPw^E-KTCUG*Yr!TM(Dq~Wyro8Z!g~2Pk8*7GV z9qK@LB8A_SBONNnMwxixl}&E;@i^C?Te_=nx}V>%f!!B3qRy-%3S+09pX#ViV>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qO^rZ)D&$%oA- z_mjZ!>**z;TIC9BzS@$vjjDg0G+-rHlasEXt5gNEAL+S5%(JD;=1eCo{B!$Pqw zoltg~dlm0}fO4zGNv;oLwkznl#qx^1=kvW8CcAjQaO!Z`n8FHzl7G-itiV_NQhYK8 dDfkmEBX41)hzGF8%sU|#lWP{J%B$#@{{RfxRoDOk literal 0 HcmV?d00001 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; +}