Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
2396bb5
以类似broadcast机制重构通讯机制
cyfung1031 Dec 9, 2025
531ac10
优化 scripting.ts 的代码设计
cyfung1031 Dec 9, 2025
5750278
共通化
cyfung1031 Dec 9, 2025
1de8edd
cloneInto 改用 固定的performance
cyfung1031 Dec 9, 2025
d650fdf
刪未使用 ImmutableEventTarget
cyfung1031 Dec 11, 2025
402c46c
Merge branch 'release/v1.3' into develop/messaging-performance-boost2
cyfung1031 Dec 13, 2025
78d56bc
该错误为预期内情况,无需记录 debug 日志
cyfung1031 Dec 16, 2025
f614539
Merge branch 'release/v1.3' into develop/messaging-performance-boost2
cyfung1031 Dec 27, 2025
6aea588
删掉未使用的 getUspMessageFlag
cyfung1031 Dec 27, 2025
a18b6d1
重新整理代码,修正 `@inject-into content`问题
cyfung1031 Dec 31, 2025
2173bdd
删去不使用的 listenPageMessages, 修正 CAT_fetchDocument
cyfung1031 Dec 31, 2025
71b04a6
重构 MessageFlag 设计,修正 `pkg/utils/uuid` 引用
cyfung1031 Jan 1, 2026
a18a8ff
Merge branch 'release/v1.3' into develop/messaging-performance-boost2
cyfung1031 Jan 1, 2026
9f55173
Merge branch 'release/v1.3' into develop/messaging-performance-boost2
cyfung1031 Jan 18, 2026
f0d3ec2
Update src/app/service/content/exec_script.ts
cyfung1031 Jan 20, 2026
8f92865
注释中"接数"应为"接收"。正确表述应为"接收 service_worker 的 chrome.storage.local 值改变通知"。
cyfung1031 Jan 20, 2026
bf09956
更新 createPageMessaging
cyfung1031 Jan 20, 2026
0ef870a
更新 createPageMessaging
cyfung1031 Jan 20, 2026
b48865c
Update src/app/service/service_worker/value.ts
cyfung1031 Jan 20, 2026
4449309
Update src/app/service/service_worker/runtime.ts
cyfung1031 Jan 20, 2026
06b52ae
注释补充
cyfung1031 Jan 20, 2026
10941fe
Update scripting.ts
cyfung1031 Jan 22, 2026
d37dee2
fix early-start
cyfung1031 Jan 24, 2026
fb4b8d0
删除early-start用的 messageFlag
cyfung1031 Jan 24, 2026
ff2538a
vitest env fix
cyfung1031 Jan 29, 2026
20b56fc
分离常量,避免SW环境无CustomEvent的问题
CodFrm Jan 30, 2026
87c0a19
重构 #1067 (#1162)
CodFrm Jan 31, 2026
1d46c86
chrome.runtime.lastError 处理
cyfung1031 Jan 31, 2026
7676ece
删除未使用的 MessageDelivery
cyfung1031 Jan 31, 2026
2af1592
vitest 测试用 SC_RANDOM_KEY
cyfung1031 Jan 31, 2026
965abdb
// 加载logger组件 -> // 初始化日志组件
cyfung1031 Jan 31, 2026
5d00d0c
Update common.ts
cyfung1031 Jan 31, 2026
efa8a08
Update common.ts
cyfung1031 Jan 31, 2026
9ffee58
删除过期代码
CodFrm Jan 31, 2026
1a4502c
修复CAT_fetchDocument问题
CodFrm Jan 31, 2026
a8fd5c5
整理代码
CodFrm Jan 31, 2026
242d0b5
整理代码
cyfung1031 Jan 31, 2026
7c4b597
处理firefox inject环境访问chrome.runtime报错的问题
CodFrm Jan 31, 2026
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
148 changes: 84 additions & 64 deletions example/tests/early_inject_content_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,93 @@
// @run-at document-start
// ==/UserScript==

(async function () {
"use strict";

console.log("%c=== Content环境 GM API 测试开始 ===", "color: blue; font-size: 16px; font-weight: bold;");

let testResults = {
passed: 0,
failed: 0,
total: 0,
};

// 测试辅助函数(支持同步和异步)
async function test(name, fn) {
testResults.total++;
try {
await fn();
testResults.passed++;
console.log(`%c✓ ${name}`, "color: green;");
return true;
} catch (error) {
testResults.failed++;
console.error(`%c✗ ${name}`, "color: red;", error);
return false;
}
// 测试辅助函数(支持同步和异步)
async function test(name, fn) {
testResults.total++;
try {
await fn();
testResults.passed++;
console.log(`%c✓ ${name}`, "color: green;");
return true;
} catch (error) {
testResults.failed++;
console.error(`%c✗ ${name}`, "color: red;", error);
return false;
}

// assert(expected, actual, message) - 比较两个值是否相等
function assert(expected, actual, message) {
if (expected !== actual) {
const valueInfo = `期望 ${JSON.stringify(expected)}, 实际 ${JSON.stringify(actual)}`;
const error = message ? `${message} - ${valueInfo}` : `断言失败: ${valueInfo}`;
throw new Error(error);
}
}

function testSync(name, fn) {
testResults.total++;
try {
fn();
testResults.passed++;
console.log(`%c✓ ${name}`, "color: green;");
return true;
} catch (error) {
testResults.failed++;
console.error(`%c✗ ${name}`, "color: red;", error);
return false;
}
}

// assert(expected, actual, message) - 比较两个值是否相等
function assert(expected, actual, message) {
if (expected !== actual) {
const valueInfo = `期望 ${JSON.stringify(expected)}, 实际 ${JSON.stringify(actual)}`;
const error = message ? `${message} - ${valueInfo}` : `断言失败: ${valueInfo}`;
throw new Error(error);
}
}

// assertTrue(condition, message) - 断言条件为真
function assertTrue(condition, message) {
if (!condition) {
throw new Error(message || "断言失败: 期望条件为真");
}
// assertTrue(condition, message) - 断言条件为真
function assertTrue(condition, message) {
if (!condition) {
throw new Error(message || "断言失败: 期望条件为真");
}
}

console.log("%c=== Content环境 GM API 测试开始 ===", "color: blue; font-size: 16px; font-weight: bold;");

let testResults = {
passed: 0,
failed: 0,
total: 0,
};

// 同步测试

// ============ GM_addElement/GM_addStyle 测试 ============
console.log("\n%c--- DOM操作 API 测试 ---", "color: orange; font-weight: bold;");

testSync("GM_addElement", () => {
const element = GM_addElement("div", {
textContent: "GM_addElement测试元素",
style: "display:none;",
id: "gm-test-element",
});
assertTrue(element !== null && element !== undefined, "GM_addElement应该返回元素");
assert("gm-test-element", element.id, "元素ID应该正确");
assert("DIV", element.tagName, "元素标签应该是DIV");
console.log("返回元素:", element);
// 清理测试元素
element.parentNode.removeChild(element);
});

testSync("GM_addStyle", () => {
const styleElement = GM_addStyle(`
.gm-style-test {
color: #10b981 !important;
}
`);
assertTrue(styleElement !== null && styleElement !== undefined, "GM_addStyle应该返回样式元素");
assertTrue(styleElement.tagName === "STYLE" || styleElement.sheet, "应该返回STYLE元素或样式对象");
console.log("返回样式元素:", styleElement);
// 清理测试样式
styleElement.parentNode.removeChild(styleElement);
});

(async function () {
"use strict";

// ============ 早期脚本环境检查 ============
console.log("\n%c--- 早期脚本环境检查 ---", "color: orange; font-weight: bold;");
Expand Down Expand Up @@ -107,37 +153,11 @@
console.log("脚本注入到:", node.tagName);
});

// ============ GM_addElement/GM_addStyle 测试 ============
console.log("\n%c--- DOM操作 API 测试 ---", "color: orange; font-weight: bold;");

await test("GM_addElement", () => {
const element = GM_addElement("div", {
textContent: "GM_addElement测试元素",
style: "display:none;",
id: "gm-test-element",
});
assertTrue(element !== null && element !== undefined, "GM_addElement应该返回元素");
assert("gm-test-element", element.id, "元素ID应该正确");
assert("DIV", element.tagName, "元素标签应该是DIV");
console.log("返回元素:", element);
});

await test("GM_addStyle", () => {
const styleElement = GM_addStyle(`
.gm-style-test {
color: #10b981 !important;
}
`);
assertTrue(styleElement !== null && styleElement !== undefined, "GM_addStyle应该返回样式元素");
assertTrue(styleElement.tagName === "STYLE" || styleElement.sheet, "应该返回STYLE元素或样式对象");
console.log("返回样式元素:", styleElement);
});

// ============ GM_log 测试 ============
console.log("\n%c--- GM_log 测试 ---", "color: orange; font-weight: bold;");

await test("GM_log", () => {
GM_log("测试日志输出", { type: "test", value: 123 });
GM_log("测试日志输出", "info", { type: "test", value: 123 });
// GM_log本身不返回值,只要不抛出异常就算成功
assertTrue(true, "GM_log应该能正常输出");
});
Expand Down
146 changes: 82 additions & 64 deletions example/tests/early_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,91 @@
// @run-at document-start
// ==/UserScript==

(async function () {
"use strict";

console.log("%c=== 早期脚本 GM API 测试开始 ===", "color: blue; font-size: 16px; font-weight: bold;");

let testResults = {
passed: 0,
failed: 0,
total: 0,
};

// 测试辅助函数(支持同步和异步)
async function test(name, fn) {
testResults.total++;
try {
await fn();
testResults.passed++;
console.log(`%c✓ ${name}`, "color: green;");
return true;
} catch (error) {
testResults.failed++;
console.error(`%c✗ ${name}`, "color: red;", error);
return false;
}
// 测试辅助函数(支持同步和异步)
async function test(name, fn) {
testResults.total++;
try {
await fn();
testResults.passed++;
console.log(`%c✓ ${name}`, "color: green;");
return true;
} catch (error) {
testResults.failed++;
console.error(`%c✗ ${name}`, "color: red;", error);
return false;
}

// assert(expected, actual, message) - 比较两个值是否相等
function assert(expected, actual, message) {
if (expected !== actual) {
const valueInfo = `期望 ${JSON.stringify(expected)}, 实际 ${JSON.stringify(actual)}`;
const error = message ? `${message} - ${valueInfo}` : `断言失败: ${valueInfo}`;
throw new Error(error);
}
}

function testSync(name, fn) {
testResults.total++;
try {
fn();
testResults.passed++;
console.log(`%c✓ ${name}`, "color: green;");
return true;
} catch (error) {
testResults.failed++;
console.error(`%c✗ ${name}`, "color: red;", error);
return false;
}
}

// assert(expected, actual, message) - 比较两个值是否相等
function assert(expected, actual, message) {
if (expected !== actual) {
const valueInfo = `期望 ${JSON.stringify(expected)}, 实际 ${JSON.stringify(actual)}`;
const error = message ? `${message} - ${valueInfo}` : `断言失败: ${valueInfo}`;
throw new Error(error);
}
}

// assertTrue(condition, message) - 断言条件为真
function assertTrue(condition, message) {
if (!condition) {
throw new Error(message || "断言失败: 期望条件为真");
}
// assertTrue(condition, message) - 断言条件为真
function assertTrue(condition, message) {
if (!condition) {
throw new Error(message || "断言失败: 期望条件为真");
}
}

console.log("%c=== 早期脚本 GM API 测试开始 ===", "color: blue; font-size: 16px; font-weight: bold;");

let testResults = {
passed: 0,
failed: 0,
total: 0,
};

// ============ GM_addElement/GM_addStyle 测试 ============
console.log("\n%c--- DOM操作 API 测试 ---", "color: orange; font-weight: bold;");

testSync("GM_addElement", () => {
const element = GM_addElement("div", {
textContent: "GM_addElement测试元素",
style: "display:none;",
id: "gm-test-element",
});
assertTrue(element !== null && element !== undefined, "GM_addElement应该返回元素");
assert("gm-test-element", element.id, "元素ID应该正确");
assert("DIV", element.tagName, "元素标签应该是DIV");
console.log("返回元素:", element);
// 清理测试元素
element.parentNode.removeChild(element);
});

testSync("GM_addStyle", () => {
const styleElement = GM_addStyle(`
.gm-style-test {
color: #10b981 !important;
}
`);
assertTrue(styleElement !== null && styleElement !== undefined, "GM_addStyle应该返回样式元素");
assertTrue(styleElement.tagName === "STYLE" || styleElement.sheet, "应该返回STYLE元素或样式对象");
console.log("返回样式元素:", styleElement);
// 清理测试样式
styleElement.parentNode.removeChild(styleElement);
});

(async function () {
"use strict";

// ============ 早期脚本环境检查 ============
console.log("\n%c--- 早期脚本环境检查 ---", "color: orange; font-weight: bold;");
Expand Down Expand Up @@ -135,37 +179,11 @@
}
});

// ============ GM_addElement/GM_addStyle 测试 ============
console.log("\n%c--- DOM操作 API 测试 ---", "color: orange; font-weight: bold;");

await test("GM_addElement", () => {
const element = GM_addElement("div", {
textContent: "GM_addElement测试元素",
style: "display:none;",
id: "gm-test-element",
});
assertTrue(element !== null && element !== undefined, "GM_addElement应该返回元素");
assert("gm-test-element", element.id, "元素ID应该正确");
assert("DIV", element.tagName, "元素标签应该是DIV");
console.log("返回元素:", element);
});

await test("GM_addStyle", () => {
const styleElement = GM_addStyle(`
.gm-style-test {
color: #10b981 !important;
}
`);
assertTrue(styleElement !== null && styleElement !== undefined, "GM_addStyle应该返回样式元素");
assertTrue(styleElement.tagName === "STYLE" || styleElement.sheet, "应该返回STYLE元素或样式对象");
console.log("返回样式元素:", styleElement);
});

// ============ GM_log 测试 ============
console.log("\n%c--- GM_log 测试 ---", "color: orange; font-weight: bold;");

await test("GM_log", () => {
GM_log("测试日志输出", { type: "test", value: 123 });
GM_log("测试日志输出", "info", { type: "test", value: 123 });
// GM_log本身不返回值,只要不抛出异常就算成功
assertTrue(true, "GM_log应该能正常输出");
});
Expand Down
2 changes: 1 addition & 1 deletion example/tests/inject_content_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
console.log("\n%c--- GM_log 测试 ---", "color: orange; font-weight: bold;");

await test("GM_log", () => {
GM_log("测试日志输出", { type: "test", value: 123 });
GM_log("测试日志输出", "info", { type: "test", value: 123 });
// GM_log本身不返回值,只要不抛出异常就算成功
assertTrue(true, "GM_log应该能正常输出");
});
Expand Down
Loading
Loading