Skip to content

Commit

Permalink
Add missing parameters for GM_cookie
Browse files Browse the repository at this point in the history
1. Fix typos in #dispatch method
2. Add commonly missing parameters for set and delete

Fix #134
  • Loading branch information
JingMatrix committed Nov 13, 2023
1 parent a958799 commit b969aaf
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions app/src/main/assets/GM.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,24 +169,34 @@ const GM_cookie = new (class CookieManager {
}
async #dispatch(method, details, callback) {
if (typeof callback == "function") {
let error;
let error, result;
try {
return await this.#command(method, details);
result = await this.#command(method, details);
} catch (e) {
error = e;
}
callback(e.message);
callback(error?.message);
if (error instanceof Error) throw error;
return result;
} else {
return this.#command(method, details);
}
}
set(details, callback) {
let cookies = details;
if (!Array.isArray(cookies)) cookies = [details];
for (const cookie of cookies) {
if (typeof cookie.expirationDate == "number") {
cookie.expires = cookie.expirationDate;
delete cookie.expirationDate;
}
if (cookie.domain == undefined) cookie.domain = window.location.hostname;
}
return this.#dispatch("Network.setCookies", { cookies }, callback);
}
delete(details, callback) {
if (details.domain == undefined && details.url == undefined)
details.domain = window.location.hostname;
return this.#dispatch("Network.deleteCookies", details, callback);
}
})();
Expand Down

0 comments on commit b969aaf

Please sign in to comment.