修复匹配问题与优化批量开启速度
This commit is contained in:
parent
ddd3219bae
commit
ffabe268b1
@ -238,7 +238,7 @@ export class RuntimeService {
|
||||
return undefined;
|
||||
}
|
||||
// 如果是iframe,判断是否允许在iframe里运行
|
||||
if (chromeSender.frameId !== undefined) {
|
||||
if (chromeSender.frameId) {
|
||||
if (scriptRes.metadata.noframes) {
|
||||
return undefined;
|
||||
}
|
||||
@ -485,7 +485,9 @@ export class RuntimeService {
|
||||
|
||||
// 如果脚本开启, 则注册脚本
|
||||
if (this.isEnableDeveloperMode && script.status === SCRIPT_STATUS_ENABLE) {
|
||||
if (!scriptRes.metadata["noframes"]) {
|
||||
if (scriptRes.metadata["noframes"]) {
|
||||
registerScript.allFrames = false;
|
||||
} else {
|
||||
registerScript.allFrames = true;
|
||||
}
|
||||
if (scriptRes.metadata["run-at"]) {
|
||||
|
@ -369,5 +369,7 @@
|
||||
"export_success": "导出成功",
|
||||
"get_backup_dir_url_failed": "获取备份目录地址失败",
|
||||
"get_backup_files_failed": "获取备份文件失败",
|
||||
"develop_mode_guide": "检测到当前未开启开发者模式,您的脚本无法正常使用,<a href=\"https://docs.scriptcat.org/docs/use/open-dev/\" target=\"black\" style=\"color: var(--color-text-1)\">👉点我了解如何开启</a>"
|
||||
"develop_mode_guide": "检测到当前未开启开发者模式,您的脚本无法正常使用,<a href=\"https://docs.scriptcat.org/docs/use/open-dev/\" target=\"black\" style=\"color: var(--color-text-1)\">👉点我了解如何开启</a>",
|
||||
"enable_script_failed": "脚本开启失败",
|
||||
"disable_script_failed": "脚本关闭失败"
|
||||
}
|
@ -81,6 +81,8 @@ import {
|
||||
requestStopScript,
|
||||
requestRunScript,
|
||||
scriptClient,
|
||||
enableLoading,
|
||||
updateEnableStatus,
|
||||
} from "@App/pages/store/features/script";
|
||||
import { message, systemConfig } from "@App/pages/store/global";
|
||||
import { SynchronizeClient, ValueClient } from "@App/app/service/service_worker/client";
|
||||
@ -706,19 +708,23 @@ function ScriptList() {
|
||||
type="primary"
|
||||
size="mini"
|
||||
onClick={() => {
|
||||
const uuids: string[] = [];
|
||||
const enableAction = (enable: boolean) => {
|
||||
const uuids = select.map((item) => item.uuid);
|
||||
dispatch(enableLoading({ uuids: uuids, loading: true }));
|
||||
Promise.allSettled(uuids.map((uuid) => scriptClient.enable(uuid, enable))).finally(() => {
|
||||
dispatch(updateEnableStatus({ uuids: uuids, enable: enable }));
|
||||
dispatch(enableLoading({ uuids: uuids, loading: false }));
|
||||
});
|
||||
};
|
||||
switch (action) {
|
||||
case "enable":
|
||||
select.forEach((item) => {
|
||||
dispatch(requestEnableScript({ uuid: item.uuid, enable: true }));
|
||||
});
|
||||
enableAction(true);
|
||||
break;
|
||||
case "disable":
|
||||
select.forEach((item) => {
|
||||
dispatch(requestEnableScript({ uuid: item.uuid, enable: false }));
|
||||
});
|
||||
enableAction(false);
|
||||
break;
|
||||
case "export":
|
||||
const uuids: string[] = [];
|
||||
select.forEach((item) => {
|
||||
uuids.push(item.uuid);
|
||||
});
|
||||
|
@ -102,6 +102,22 @@ export const scriptSlice = createAppSlice({
|
||||
script.runStatus = action.payload.runStatus;
|
||||
}
|
||||
},
|
||||
updateEnableStatus: (state, action: PayloadAction<{ uuids: string[]; enable: boolean }>) => {
|
||||
state.scripts = state.scripts.map((s) => {
|
||||
if (action.payload.uuids.includes(s.uuid)) {
|
||||
s.status = action.payload.enable ? SCRIPT_STATUS_ENABLE : SCRIPT_STATUS_DISABLE;
|
||||
}
|
||||
return s;
|
||||
});
|
||||
},
|
||||
enableLoading(state, action: PayloadAction<{ uuids: string[]; loading: boolean }>) {
|
||||
state.scripts = state.scripts.map((s) => {
|
||||
if (action.payload.uuids.includes(s.uuid)) {
|
||||
s.enableLoading = action.payload.loading;
|
||||
}
|
||||
return s;
|
||||
});
|
||||
},
|
||||
},
|
||||
extraReducers: (builder) => {
|
||||
builder
|
||||
@ -144,6 +160,6 @@ export const scriptSlice = createAppSlice({
|
||||
},
|
||||
});
|
||||
|
||||
export const { sortScript, upsertScript, deleteScript } = scriptSlice.actions;
|
||||
export const { sortScript, upsertScript, deleteScript, enableLoading, updateEnableStatus } = scriptSlice.actions;
|
||||
|
||||
export const { selectScripts } = scriptSlice.selectors;
|
||||
|
@ -179,6 +179,12 @@ describe("parsePatternMatchesURL", () => {
|
||||
host: "127.0.0.1",
|
||||
path: "",
|
||||
});
|
||||
const matches4 = parsePatternMatchesURL("*://*/*");
|
||||
expect(matches4).toEqual({
|
||||
scheme: "*",
|
||||
host: "*",
|
||||
path: "*",
|
||||
});
|
||||
});
|
||||
it("search", () => {
|
||||
// 会忽略掉search部分
|
||||
|
Loading…
x
Reference in New Issue
Block a user