From e90859286e1e7f5c0e06a101671259745e6668a0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98=E5=B0=8F=E5=A2=A8?=
<2291200076@qq.com>
Date: Sat, 7 Jan 2023 02:18:18 +0800
Subject: [PATCH] =?UTF-8?q?=E5=87=8F=E5=B0=91=E4=B8=8D=E5=BF=85=E8=A6=81?=
=?UTF-8?q?=E8=BE=93=E5=87=BA=EF=BC=9B=E6=9B=B4=E6=96=B0=E6=90=9C=E7=B4=A2?=
=?UTF-8?q?=E5=BB=BA=E8=AE=AE=E4=BB=A3=E7=A0=81=E9=80=BB=E8=BE=91=E4=BC=98?=
=?UTF-8?q?=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
scripts/advanced-search/background.js | 42 +++++++--------------------
1 file changed, 10 insertions(+), 32 deletions(-)
diff --git a/scripts/advanced-search/background.js b/scripts/advanced-search/background.js
index e8bc9da..2aa795d 100644
--- a/scripts/advanced-search/background.js
+++ b/scripts/advanced-search/background.js
@@ -959,7 +959,7 @@ async function checkIsActived() {
resolve(State.State_SSSearch);
});
});
- console.log("Double S 快捷搜索功能开启状态:" + isActived);
+ // console.log("Double S 快捷搜索功能开启状态:" + isActived);
if (!isActived) {
chrome.omnibox.setDefaultSuggestion({
description: "Double S 快捷搜索功能未开启,请在小墨助手扩展设置中开启后再试"
@@ -1067,7 +1067,7 @@ function isCurrentNewTab(tabs) {
/**
- * 更新下拉框中提示
+ * 更新搜索框中提示
* @param String text 用户输入文本
*/
function updateDefaultSuggestion(text) {
@@ -1079,7 +1079,7 @@ function updateDefaultSuggestion(text) {
];
// 如果用户输入不为空,先假设为文字搜索,如果后面匹配上了其他搜索方式,则更新
- let isPlaintext = !!text.trim().length;
+ let isPlaintext = true;
currentSearchModeIndex = 0; // 初始化搜索方式下标
// 默认第 0 个为文字搜索,除此之外的搜索方式如果都没有匹配到,则显示文字搜索
@@ -1102,40 +1102,18 @@ function updateDefaultSuggestion(text) {
}
description.push(' ] ');
- if (text.trim().length != 0) {
- description[2] = isPlaintext ? ('' + omniboxSearchModes[0].showText + ':' + encodeXML(text.trim()) + '') : ('' + omniboxSearchModes[0].showText + '');
+ // 最后来处理最前面的文字部分
+ if (isPlaintext) {
+ // 当前为文字搜索,这里不加粗
+ description[2] = '' + omniboxSearchModes[0].showText + (text.trim().length > 0 ? encodeXML(':' + text.trim()) : "") + ''
} else {
- // 用户什么也没输入时,就高亮显示文字搜索关键字
- description[2] = '' + omniboxSearchModes[0].showText + '';
+ // 当前为其他类型搜索,这里不加粗
+ description[2] = '' + omniboxSearchModes[0].showText + ''
}
- console.log("[更新搜索建议]",
- "搜索模式:", omniboxSearchModes[currentSearchModeIndex].showText,
- "isPlaintext", isPlaintext,
- "text:", text,
- // "description:", description,
- )
+ console.log("[更新搜索建议]", "搜索模式:", omniboxSearchModes[currentSearchModeIndex].showText);
chrome.omnibox.setDefaultSuggestion({
description: description.join('')
});
-
- // var isRegex = /^re:/.test(text);
- // var isFile = /^file:/.test(text);
- // var isHalp = (text == 'halp');
- // var isPlaintext = text.length && !isRegex && !isFile && !isHalp;
-
- // var description = '搜索方式 [ ';
- // description += isPlaintext ? ('' + text + '') : '文字';
- // description += ' | ';
- // description += isRegex ? ('' + text + '') : 're: 正则';
- // description += ' | ';
- // description += isFile ? ('' + text + '') : 'file:文件';
- // description += ' | ';
- // description += isHalp ? 'halp' : 'halp';
- // description += ' ]';
-
- // chrome.omnibox.setDefaultSuggestion({
- // description: description
- // });
}