From 76077a9bc18362c0e087d350d7c5e366c1d26cf3 Mon Sep 17 00:00:00 2001 From: Folyd Date: Fri, 25 Nov 2022 20:58:26 +0800 Subject: [PATCH] Feat rustc search appendix --- extension/main.js | 20 ++++++++++++-------- extension/script/rustc.js | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/extension/main.js b/extension/main.js index f7b5ac4f..a01d37e1 100644 --- a/extension/main.js +++ b/extension/main.js @@ -183,16 +183,20 @@ function getPlatformOs() { }, onAppend: (query) => { query = query.replaceAll("/", "").trim(); + let appendix = { + content: rustcSearcher.getSearchUrl(query), + description: `Search nightly rustc docs ${c.match(query)} on ${rustcSearcher.getRootPath()}`, + }; if (rustcSearcher?.searchIndex?.length > 0) { - return [{ - content: rustcSearcher.getSearchUrl(query), - description: `Search nightly rustc docs ${c.match(query)} on ${rustcSearcher.getRootPath()}`, - }]; + return [appendix]; } else { - return [{ - content: rustcSearcher.getRootPath(), - description: "To search nightly rustc docs, please open the nightly rustc docs page in advance.", - }]; + return [ + appendix, + { + content: rustcSearcher.getRootPath(), + description: "To search nightly rustc docs on the address bar, please open the nightly rustc docs page in advance.", + }, + ]; } }, }); diff --git a/extension/script/rustc.js b/extension/script/rustc.js index 6bf4967b..803506c5 100644 --- a/extension/script/rustc.js +++ b/extension/script/rustc.js @@ -18,10 +18,10 @@ document.addEventListener("DOMContentLoaded", () => { }); window.addEventListener("message", function (event) { - console.log(event.data); if (event.source === window && event.data && event.data.direction === "rust-search-extension:rustc") { + console.log(event.data); let now = new Date(); let version = `${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()}`; // rustc search index is a memory cache, therefore we don't use localStorage