Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions src/app/service/service_worker/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,15 @@ export class ScriptClient extends Client {
})
// this.do 只会resolve 不会reject
)) as PromiseFulfilledResult<{ success: boolean; msg: string }>[];
const stat = results.reduce(
(obj, result, index) => {
if (result.value.success) {
obj.success++;
} else {
obj.fail++;
obj.msg.push(`#${index + 1}: ${result.value.msg}`);
}
return obj;
},
{ success: 0, fail: 0, msg: [] as string[] }
);
const stat = { success: 0, fail: 0, msg: [] as string[] };
results.forEach(({ value }, index) => {
if (value.success) {
stat.success++;
} else {
stat.fail++;
stat.msg.push(`#${index + 1}: ${value.msg}`);
}
});
return stat;
}

Expand Down
15 changes: 8 additions & 7 deletions src/app/service/service_worker/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,29 +409,30 @@ export class RuntimeService {
// 匹配当前页面的脚本
const matchScriptUuid = await this.getPageScriptUuidByUrl(chromeSender.url!);

const enableScript = matchScriptUuid.reduce((arr, uuid) => {
const enableScript = [] as ScriptLoadInfo[];

for (const uuid of matchScriptUuid) {
const scriptRes = Object.assign({}, this.scriptMatchCache?.get(uuid));
// 判断脚本是否开启
if (scriptRes.status === SCRIPT_STATUS_DISABLE) {
return arr;
continue;
}
// 判断注入页面类型
if (scriptRes.metadata["run-in"]) {
// 判断插件运行环境
const contextType = chrome.extension.inIncognitoContext ? "incognito-tabs" : "normal-tabs";
if (!scriptRes.metadata["run-in"].includes(contextType)) {
return arr;
continue;
}
}
// 如果是iframe,判断是否允许在iframe里运行
if (chromeSender.frameId) {
if (scriptRes.metadata.noframes) {
return arr;
continue;
}
}
arr.push(scriptRes as ScriptLoadInfo);
return arr;
}, [] as ScriptLoadInfo[]);
enableScript.push(scriptRes as ScriptLoadInfo);
}

await Promise.all([
// 加载value
Expand Down
19 changes: 8 additions & 11 deletions src/locales/locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,14 @@ export async function matchLanguage() {
}
}
// 根据前缀去匹配
const prefixMap = i18n.languages.reduce(
(acc, lng) => {
const prefix = lng.split("-")[0];
if (!acc[prefix]) {
acc[prefix] = [];
}
acc[prefix].push(lng);
return acc;
},
{} as Record<string, string[]>
);
const prefixMap = {} as Partial<Record<string, string[]>>;
for (const lng of i18n.languages) {
const prefix = lng.split("-")[0];
if (!prefixMap[prefix]) {
prefixMap[prefix] = [];
}
prefixMap[prefix].push(lng);
}
for (let i = 0; i < acceptLanguages.length; i += 1) {
const lng = acceptLanguages[i];
const prefix = lng.split("-")[0];
Expand Down