Skip to content

Commit

Permalink
⚡️ 优化名称搜索 #262
Browse files Browse the repository at this point in the history
  • Loading branch information
CodFrm committed Feb 26, 2024
1 parent bf68abb commit 3056c24
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Expand Up @@ -24,6 +24,7 @@ module.exports = {
},
plugins: ["react", "@typescript-eslint", "prettier"],
rules: {
"no-restricted-syntax": "off",
"react/jsx-filename-extension": [1, { extensions: [".tsx"] }],
"no-unused-expressions": ["error", { allowShortCircuit: true }],
"react/jsx-props-no-spreading": "off",
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.json
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "ScriptCat",
"version": "0.16.0.1010",
"version": "0.16.1",
"author": "CodFrm",
"description": "脚本猫,一个用户脚本管理器,支持后台脚本、定时脚本、页面脚本,可编写脚本每天帮你自动处理事务.",
"options_ui": {
Expand Down
21 changes: 16 additions & 5 deletions src/pages/options/routes/ScriptList.tsx
Expand Up @@ -202,11 +202,22 @@ function ScriptList() {
</div>
);
},
onFilter: (value, row) =>
value
? row.name.indexOf(value) !== -1 ||
i18nName(row).indexOf(value) !== -1
: true,
onFilter: (value: string, row) => {
if (!value) {
return true;
}
value = value.toLocaleLowerCase();
row.name = row.name.toLocaleLowerCase();
const i18n = i18nName(row).toLocaleLowerCase();
// 空格分开关键字搜索
const keys = value.split(" ");
for (const key of keys) {
if (row.name.includes(key) || i18n.includes(key)) {
return true;
}
}
return false;
},
onFilterDropdownVisibleChange: (visible) => {
if (visible) {
setTimeout(() => inputRef.current!.focus(), 150);
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/background/runtime.ts
Expand Up @@ -419,7 +419,7 @@ export default class Runtime extends Manager {
addRunScript(sender.tabId!, script, false);
return script.status !== SCRIPT_STATUS_ENABLE;
}
);
).sort((a, b) => a.sort - b.sort);

if (!filter.length) {
resolve({ scripts: [] });
Expand Down

0 comments on commit 3056c24

Please sign in to comment.