From b969aaff44764bd3807816ef4fe7e8b2dc2b59da Mon Sep 17 00:00:00 2001 From: JingMatrix Date: Mon, 13 Nov 2023 15:32:08 +0100 Subject: [PATCH] Add missing parameters for GM_cookie 1. Fix typos in #dispatch method 2. Add commonly missing parameters for set and delete Fix #134 --- app/src/main/assets/GM.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/src/main/assets/GM.js b/app/src/main/assets/GM.js index d05bc53b..1b4f10b2 100644 --- a/app/src/main/assets/GM.js +++ b/app/src/main/assets/GM.js @@ -169,14 +169,15 @@ 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); } @@ -184,9 +185,18 @@ const GM_cookie = new (class CookieManager { 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); } })();