From b7484e19139237c9e764295936dddc733620304b Mon Sep 17 00:00:00 2001 From: gdh1995 Date: Sat, 23 Sep 2023 17:16:27 +0800 Subject: [PATCH] .filter param: apply smartCase on title=xxx and url=xxx --- background/filter_tabs.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/background/filter_tabs.ts b/background/filter_tabs.ts index 85cf0f59f..25dfd6237 100644 --- a/background/filter_tabs.ts +++ b/background/filter_tabs.ts @@ -175,7 +175,9 @@ const makeStringMatcher = (val: string, str: string | null | undefined): ((x?: s const strRe = lastSlash > 1 && ( /^[a-z]+$/).test(val.slice(lastSlash + 1)) ? BgUtils_.makeRegexp_(val.slice(1, lastSlash) , val.slice(lastSlash + 1).replace( /g/g, ""), 0) as RegExpOne : null - return strRe ? x => strRe.test(x || "") : str ? x => (x || "").includes(str) : null + const lower = !strRe && !!str && str.toLowerCase() + return strRe ? (str = null, x => strRe.test(x || "")) + : str ? str === lower ? x => !!x && x.toLowerCase().includes(lower) : x => !!x && x.includes(str!) : null } export interface FilterInfo { known?: boolean } @@ -206,7 +208,9 @@ export const filterTabsByCond_ = (activeTab: Tab | null | undefined const useHash = key.includes("hash") matcher = url ? Exclusions.createSimpleUrlMatcher_(":" + (useHash ? url : url.split("#", 1)[0])) : null } - cond = matcher ? tab => Exclusions.matchSimply_(matcher!, getTabUrl(tab)) : cond + const smartCase = !!matcher && matcher.t === kMatchUrl.StringPrefix && val === val.toLowerCase() + cond = matcher ? tab => Exclusions.matchSimply_(matcher! + , smartCase ? getTabUrl(tab).toLowerCase() : getTabUrl(tab)) : cond break case "title+url": const strMatcher = val && makeStringMatcher(val, val)!