Skip to content

Commit 3046200

Browse files
committed
🐛 修复GM cookie list获取不全的问题
1 parent 783404b commit 3046200

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

src/app/service/content/gm_api.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,16 @@ export default class GMApi extends GM_Base {
343343
details: GMTypes.CookieDetails,
344344
done: (cookie: GMTypes.Cookie[] | any, error: any | undefined) => void
345345
) {
346-
// 如果没有url,自动填充当前url
347-
if (!details.url) {
346+
// 如果url和域名都没有,自动填充当前url
347+
if (!details.url && !details.domain) {
348348
details.url = window.location.href;
349349
}
350+
// 如果是set、delete操作,自动填充当前url
351+
if (action === "set" || action === "delete") {
352+
if (!details.url) {
353+
details.url = window.location.href;
354+
}
355+
}
350356
a.sendMessage("GM_cookie", [action, details])
351357
.then((resp: any) => {
352358
done && done(resp, undefined);

src/app/service/service_worker/gm_api.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ export default class GMApi {
167167
return true;
168168
}
169169
const detail = <GMTypes.CookieDetails>request.params[1];
170-
if (!detail.url) {
171-
throw new Error("there must be one of url");
170+
if (!detail.url && !detail.domain) {
171+
throw new Error("there must be one of url or domain");
172172
}
173173
let url: URL = <URL>{};
174174
if (detail.url) {
@@ -214,8 +214,8 @@ export default class GMApi {
214214
if (detail.domain) {
215215
detail.domain = detail.domain.trim();
216216
}
217-
if (!detail.url) {
218-
throw new Error("there must be one of url");
217+
if (!detail.url && !detail.domain) {
218+
throw new Error("there must be one of url or domain");
219219
}
220220
if (typeof detail.partitionKey !== "object" || detail.partitionKey == null) {
221221
detail.partitionKey = {};

0 commit comments

Comments
 (0)