Skip to content

Commit

Permalink
🐛 兼容GM_cookie.list的调用方式和菜单展示问题 #117
Browse files Browse the repository at this point in the history
  • Loading branch information
CodFrm committed Dec 3, 2022
1 parent 2eed348 commit a54d0c6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/runtime/background/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export default class Runtime extends Manager {
tabMap.set(request.scriptId, menuArr);
}
// 查询菜单是否已经存在
for (let i = 0; menuArr.length; i += 1) {
for (let i = 0; i < menuArr.length; i += 1) {
// id 相等 跳过,选第一个,并close链接
if (menuArr[i].request.params[0] === request.params[0]) {
channel.disChannel();
Expand Down
18 changes: 18 additions & 0 deletions src/runtime/content/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,24 @@ export function createContext(
if (val.startsWith("GM.")) {
const [, t] = val.split(".");
(<{ [key: string]: any }>context.GM)[t] = api.api.bind(context);
} else if (val === "GM_cookie") {
// 特殊处理GM_cookie.list之类
context[val] = api.api.bind(context);
// eslint-disable-next-line func-names, camelcase
const GM_cookie = function (action: string) {
return (
details: GMTypes.CookieDetails,
done: (
cookie: GMTypes.Cookie[] | any,
error: any | undefined
) => void
) => {
return context[val](action, details, done);
};
};
context[val].list = GM_cookie("list");
context[val].delete = GM_cookie("delete");
context[val].set = GM_cookie("set");
} else {
context[val] = api.api.bind(context);
}
Expand Down
12 changes: 12 additions & 0 deletions src/runtime/gm_api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,18 @@ describe("GM cookie", () => {
}
);
});
// 测试GM_cookie.list
await new Promise<void>((resolve) => {
// @ts-ignore
contentApi.GM_cookie.list(
{ url: "https://scriptcat.org" },
// @ts-ignore
(value, err) => {
expect(err).toEqual("hostname must be in the definition of connect");
resolve();
}
);
});
// 在@connect中,但被拒绝
const hookFn = (createProperties: chrome.tabs.CreateProperties) => {
// 模拟确认
Expand Down

0 comments on commit a54d0c6

Please sign in to comment.