API ããã¥ã¡ã³ã
æ¦è¦â
ãã®æ¡å¼µæ©è½ã® API å®ç¾©ã¯ Tampermonkey ããã¥ã¡ã³ã ã«åºã¥ãã¦ãã¾ããæéã¨å´åã®å¶ç´ã«ãããç¾å¨ã¯ä¸é¨ã® API ã®ã¿ãå®è£
ããã¦ãããä»å¾ãç¶ç¶çã«æ¹åããã¾ãããã®æ¡å¼µæ©è½ãæ¡å¼µãã API ããå
ã® GM API ã¨ç°ãªã API ã¯ããã¥ã¡ã³ãã§ç¹å¥ã«ãã¼ã¯ããã¦ãã¾ãï¼* ã使ç¨ï¼ãä¸é¨ã® API 㯠GM.* ã®ã«ã¼ã«ã«å¾ã£ãåæçãæä¾ãã¦ãã¾ãã詳細ã¯ããã¥ã¡ã³ãæ¬æãåç
§ãã¦ãã ããã
詳細㪠API å®ç¾©ã«ã¤ãã¦ã¯ scriptcat.d.ts ã¾ãã¯ãã«ãã¤ã³ã¨ãã£ã¿ã®ãã³ããåç
§ãã¦ãã ãããããã¥ã¡ã³ããå¸¸ã«ææ°ã§ã¯ãªãå ´åãããã¾ãããã®æ¡å¼µæ©è½åºæã® API ã«ã¤ãã¦ã¯ CatApi ããã¥ã¡ã³ã ãåç
§ãã¦ãã ããã
é¢é£ããä¾ã¯ example ãã£ã¬ã¯ã㪠ã§ã確èªã§ãã¾ãã
å®ç¾©â
GM_infoâ
ã¹ã¯ãªããã«é¢ããæ
å ±ãåå¾ãã¾ããã¡ã¿ãã¼ã¿ãã©ã³ã¿ã¤ã ç°å¢ãã©ã¡ã¼ã¿ãå«ã¾ãã¾ãããã使ç¨ããããã£ã¼ã«ãã«ã¯ scriptHandlerãversionãscriptMetaStrãscriptUpdateURLãdownloadMode ãªã©ãããã¾ãã詳細ï¼å®å
¨ã§ã¯ãªãï¼ãªå®ç¾©ã¯ scriptcat.d.ts ãåç
§ãã¦ãã ããã
console.log(GM_info.scriptHandler);
console.log(GM_info.version);
console.log(GM_info.scriptMetaStr);
sandboxModeã¯ç¾å¨rawã®ã¿ã®å¤ã§ããrunAtã¯ãµãã¼ãããã¦ãã¾ãããuserAgentDataã¯ãµãã¼ãããã¦ãã¾ãããTampermonkey ã¨å®å ¨ã«ä¸è´ããã¨ã¯éãã¾ããã
GM_log *â
ãã°é¢æ°ãããã¯ã°ã©ã¦ã³ãã¹ã¯ãªããã®ãã°ã¯ããã·ã¥ãã¼ãã®å®è¡ãã°ã§ç¢ºèªã§ãã¾ãï¼å®è¡ç¶æ
åãã¯ãªãã¯ï¼ãTampermonkey ã¨æ¯è¼ãã¦ããã° level ã追å ããã¦ãã¾ãã
declare function GM_log(message: string, level?: GMTypes.LoggerLevel): void;
declare namespace GMTypes {
type LoggerLevel = "debug" | "info" | "warn" | "error";
}
GM_log("debug info", "debug");
GM_get/set/deleteValueâ
ã¹ãã¬ã¼ã¸ã®å¤ãåå¾ã¾ãã¯è¨å®ãã¾ããåã storageName ä¸ã®ãã¼ã¿ã¯å ±æããããªã¢ã«ã¿ã¤ã ã§åæããã¾ãã
// ãã¼ã¿ã追å â ãã¼ã¿ã¯ bool/string/number/object ã®ããããã®ã¿ã§ãã¯ã©ã¹ã¤ã³ã¹ã¿ã³ã¹ã¯ä¿åã§ãã¾ãã
declare function GM_setValue(name: string, value: any): void;
// ãã¼ã¿ãåå¾
declare function GM_getValue(name: string, defaultValue?: any): any | undefined;
// ãã¼ã¿ãåé¤ãååå¾ãã㨠undefined ã¾ã㯠defaultValue ãè¿ããã¾ã
declare function GM_deleteValue(name: string): void;
GM_setValue("foo", 42);
const v = GM_getValue("foo", 0);
GM_deleteValue("foo");
注æ: GM_setValue ã« undefined ãæ¸¡ããå ´åãTampermonkey/GreaseMonkey ã undefined ãå¤ã¨ãã¦ä¿åããã®ã¨ã¯ç°ãªããScriptCat ã¯ãã®ãã¼ãåé¤ãã¾ããâ
注æ: ãã¼ã¿æä½ã¯éåæã§ãããããGM_setValue ã GM_deleteValue ã®ç´å¾ã« window.close() ãå¼ã³åºãã¨ããã¼ã¿ãæ£ããæ´æ°ãããªãå ´åãããã¾ãããã¼ã¿æä½ã®å®äºãä¿è¨¼ããã«ã¯ await GM.setValue ã¾ã㯠await GM.deleteValue ã®ä½¿ç¨ãæ¨å¥¨ãã¾ããâ
GM_listValuesâ
ãã¹ã¦ã®ãã¼ãä¸è¦§è¡¨ç¤ºãã¾ãã
declare function GM_listValues(): string[];
console.log(GM_listValues());
GM_setValues / GM_getValues / GM_deleteValues *â
ãããåå¾/è¨å® APIï¼æ¡å¼µæ©è½ï¼ã
// è¤æ°ã®å¤ãè¨å®ãvalues ã¯ãã¼ãå¤åãå¤ãå
容ã®ãªãã¸ã§ã¯ãã§ã
declare function GM_setValues(values: { [key: string]: any }): void;
// è¤æ°ã®å¤ãåå¾ãkeysOrDefaults ããªãã¸ã§ã¯ãã®å ´åããã®å¤ãããã©ã«ãã¨ãã¦ä½¿ç¨ããã¾ã
declare function GM_getValues(keysOrDefaults: { [key: string]: any } | string[] | null | undefined): { [key: string]: any };
// è¤æ°ã®å¤ãåé¤ãnames ã¯æååã®é
åã§ã
declare function GM_deleteValues(names: string[]): void;
// ãããã»ãã
GM_setValues({ a: 1, b: 2 });
// ãããåå¾ï¼åå¨ããªãå ´åã¯ããã©ã«ããè¿ãï¼
const { a, b, c = 3 } = GM_getValues({ a: 0, b: 0, c: 3 });
// ãããåé¤
GM_deleteValues(["a", "b"]);
注æ: ãã¼ã¿æä½ã¯éåæã§ãããããGM_setValues ã GM_deleteValues ã®ç´å¾ã« window.close() ãå¼ã³åºãã¨ããã¼ã¿ãæ£ããæ´æ°ãããªãå ´åãããã¾ãããã¼ã¿æä½ã®å®äºãä¿è¨¼ããã«ã¯ await GM.setValues ã¾ã㯠await GM.deleteValues ã®ä½¿ç¨ãæ¨å¥¨ãã¾ããâ
GM_add/removeValueChangeListenerâ
tabid㯠0.17.0-alpha 以éåé¤ããã¾ããã詳細㯠GM_cookie ãåç §ãã¦ãã ããã
å¤ã®å¤æ´ããªãã¹ã³ãã¾ããadd ã¯ãªãã¹ã³ ID ãè¿ããremove ã§ãªãã¹ã³ããã£ã³ã»ã«ã§ãã¾ãããã®ã¡ã½ããã¯ã·ã³ãã«ãªéä¿¡ãå®è£
ããããã«ä½¿ç¨ã§ããstorageName ã使ç¨ããã¨ã¹ã¯ãªããéã®éä¿¡ãå¯è½ã«ãªãã¾ãã
// tabid ã¯ããã¯ã°ã©ã¦ã³ãã¹ã¯ãªãããããªãã¹ã³ããå ´åã®ã¿åå¨ãã¾ã
type ValueChangeListener = (
name: string,
oldValue: any,
newValue: any,
remote: boolean,
tabid?: number
) => any;
declare function GM_addValueChangeListener(
name: string,
listener: GMTypes.ValueChangeListener
): number;
declare function GM_removeValueChangeListener(listenerId: number): void;
const id = GM_addValueChangeListener("foo", (k, oldV, newV, remote) => {
console.log(k, oldV, newV, remote);
});
GM_removeValueChangeListener(id);
GM_getResourceText/GM_getResourceURLâ
@resource ã§å®£è¨ããããªã½ã¼ã¹æ
å ±ãåå¾ãã¾ãã
// GM_getResourceText ã¯ãªã½ã¼ã¹ã®ããã¹ããã¼ã¿ãåå¾ãã¾ããç»åãªã©ã®ãã¤ãåãã¼ã¿ã¯ç©ºæååãè¿ãã¾ã â ãã®å ´å㯠GM_getResourceURL ã使ç¨ãã¦ãã ãã
declare function GM_getResourceText(name: string): string | undefined;
// GM_getResourceURL 㯠base64 ã¨ã³ã³ã¼ãããããã¼ã¿ãåå¾ãã¾ãã第äºãã©ã¡ã¼ã¿ã§ blob URL ãåå¾ã§ãã¾ã
declare function GM_getResourceURL(name: string, isBlobUrl?: boolean): string | undefined;
const css = GM_getResourceText("mystyle");
const imgUrl = GM_getResourceURL("logo");
GM_addElementâ
ãã¼ã¸ã«è¦ç´ ãæ¿å ¥ãã¾ããCSP å¶éãè¿åã§ãã¾ãã
declare function GM_addElement(tag: string, attributes: any): HTMLElement;
declare function GM_addElement(parentNode: Element, tag: string, attrs: any): HTMLElement;
// ã¹ã¯ãªãããæ¿å
¥
GM_addElement("script", { src: "https://example.com/app.js" });
// ã¹ã¿ã¤ã«ãæ¿å
¥
GM_addElement(document.head, "style", { textContent: ".foo{color:blue}" });
GM_addStyleâ
ãã¼ã¸ã«ã¹ã¿ã¤ã«ã追å ããã¹ã¿ã¤ã« DOM ãã¼ããè¿ãã¾ããCSP å¶éãè¿åã§ãã¾ãã
declare function GM_addStyle(css: string): HTMLElement;
GM_addStyle(`
body { background: #f0f0f0; }
.btn { color: red; }
`);
GM_openInTab *â
æ°ããã¦ã£ã³ãã¦ãéãã¾ãã
declare function GM_openInTab(url: string, options: GMTypes.OpenTabOptions): GMTypes.Tab;
declare function GM_openInTab(url: string, loadInBackground: boolean): GMTypes.Tab;
declare function GM_openInTab(url: string): GMTypes.Tab;
declare namespace GMTypes {
interface OpenTabOptions {
active?: boolean;
insert?: boolean | number;
setParent?: boolean;
incognito?: boolean;
loadInBackground?: boolean;
pinned?: boolean;
useOpen?: boolean;
}
interface Tab {
close(): void;
onclose?: () => void;
closed?: boolean;
name?: string;
}
}
const tab = GM_openInTab("https://example.com", { active: false });
tab.onclose = () => console.log("closed");
tab.close();
GM_get/saveTab/GM_getTabsâ
GM_setValue ã«ä¼¼ããã¼ã¿ä¿åæ¹æ³ã§ããããã®ã¡ã½ããã®ã©ã¤ãã¿ã¤ã ã¯åä¸ã®ãã©ã¦ã¶ã¿ãã®ãªã¼ãã³âã¯ãã¼ãº ãµã¤ã¯ã«ã«ç´ã¥ãã¦ãããããã¯ã°ã©ã¦ã³ãã¹ã¯ãªããããã¯ä½¿ç¨ã§ãã¾ããã
// ã¿ããã¼ã¿ãåå¾
declare function GM_getTab(callback: (obj: object) => void): void;
// ã¿ããã¼ã¿ãä¿å
declare function GM_saveTab(obj: object): void;
// ãã¹ã¦ã®ã¿ãã®ãã¼ã¿ãåå¾
declare function GM_getTabs(callback: (objs: { [key: number]: object }) => void): void;
GM_saveTab({ foo: 1 }, () => console.log("saved"));
GM_getTab(tab => console.log(tab));
GM_getTabs(tabs => console.log(tabs));
GM_registerMenuCommand *â
- ãããã¢ãããã¼ã¸ã¨å³ã¯ãªãã¯ã¡ãã¥ã¼ã«è¡¨ç¤ºãããã¡ãã¥ã¼ã¢ã¤ãã ãç»é²ãã¾ããã¯ãªãã¯ããã¨
listener颿°ãå¼ã³åºããã¾ãã - ããã©ã«ãã§ã¯ Tampermonkey ã¨åæ§ã«ãåã表示ããã¹ãã®ã¡ãã¥ã¼ã¢ã¤ãã ã¯1ã¤ã ã表示ããã¾ãã
idãæå®ããã¨ã¡ãã¥ã¼ã¢ã¤ãã ãæ´æ°ã§ãã¾ããnameã空æååã§listenerããªãå ´åãå³ã¯ãªãã¯ã¡ãã¥ã¼ã«åºåãç·ã追å ããã¾ãã
function GM_registerMenuCommand(
name: string,
listener?: (inputValue?: any) => void,
options_or_accessKey?:
| {
id?: number | string;
accessKey?: string;
autoClose?: boolean; // ScriptCat åºæã®ãªãã·ã§ã³ãããã©ã«ã㯠trueãfalse ã«ããã¨ã¯ãªãã¯å¾ããããã¢ããã¡ãã¥ã¼ãéããã¾ã¾ã«ãã
nested?: boolean; // ScriptCat åºæã®ãªãã·ã§ã³ãããã©ã«ã㯠trueãfalse ã«ããã¨ãã©ã¦ã¶ã®å³ã¯ãªãã¯ã¡ãã¥ã¼ã¢ã¤ãã ã3é層ç®ãã2é層ç®ã«å¼ãä¸ãã
individual?: boolean; // ScriptCat åºæã®ãªãã·ã§ã³ãããã©ã«ã㯠falseãtrue ã«ããã¨åãã¡ãã¥ã¼ã¢ã¤ãã ããã¼ã¸ããªã
}
| string
): number;
const cmdId = GM_registerMenuCommand("Test Command 01", () => alert("Called 01"));
GM_registerMenuCommand("Test Command 02", () => alert("Called 02"), {id: "custom-id"});
GM_unregisterMenuCommandâ
ID ãæå®ãã¦ç»é²ãããã¡ãã¥ã¼ã¢ã¤ãã ãåé¤ãã¾ãã
declare function GM_unregisterMenuCommand(id: number): void;
GM_unregisterMenuCommand(cmdId);
GM_unregisterMenuCommand("custom-id");
GM_notification *â
éç¥ã¡ãã»ã¼ã¸ãéä¿¡ãã¾ããprogress 㨠buttons æ©è½ãæä¾ãã¾ãï¼Firefox ã§ã¯é対å¿ï¼ãéç¥ã«ããã°ã¬ã¹ãã¼ããã¿ã³ã表示ã§ãã¾ããã¾ããGM_closeNotification 㨠GM_updateNotification ã®2ã¤ã®è¿½å ã¡ã½ãããæä¾ãã¾ãï¼Firefox ã§ã¯é対å¿ï¼ã
declare function GM_notification(
details: GMTypes.NotificationDetails,
ondone?: GMTypes.NotificationOnDone
): void;
declare function GM_notification(
text: string,
title: string,
image: string,
onclick: GMTypes.NotificationOnClick
): void;
declare function GM_closeNotification(id: string): void;
declare function GM_updateNotification(id: string, details: GMTypes.NotificationDetails): void;
declare namespace GMTypes {
interface NotificationDetails {
text?: string;
title?: string;
tag?: string;
image?: string;
highlight?: boolean;
silent?: boolean;
timeout?: number;
url?: string;
onclick?: NotificationOnClick;
ondone?: NotificationOnDone;
progress?: number;
oncreate?: NotificationOnClick;
// æå¤§2ã¤ã¾ã§
buttons?: NotificationButton[];
}
interface NotificationThis extends NotificationDetails {
id: string;
}
type NotificationOnClickEvent = {
event: "click" | "buttonClick";
id: string;
isButtonClick: boolean;
buttonClickIndex: number | undefined;
byUser: boolean | undefined;
preventDefault: () => void;
highlight: NotificationDetails["highlight"];
image: NotificationDetails["image"];
silent: NotificationDetails["silent"];
tag: NotificationDetails["tag"];
text: NotificationDetails["tag"];
timeout: NotificationDetails["timeout"];
title: NotificationDetails["title"];
url: NotificationDetails["url"];
};
type NotificationOnClick = (this: NotificationThis, event: NotificationOnClickEvent) => unknown;
type NotificationOnDone = (this: NotificationThis, user?: boolean) => unknown;
interface NotificationButton {
title: string;
iconUrl?: string;
}
}
GM_notification({ title: "Progress", text: "Loading", progress: 50 });
注æ: GM_closeNotification 㨠GM_updateNotification 㯠ScriptCat åºæã§ããéç¥ãæ´æ°ããã«ã¯ tag ã使ç¨ãã¦ãã ãããâ
GM_notification({ title: "Progress", text: "Loading", progress: 50, tag: "notification01"});
GM_notification({ title: "Progress", text: "Done", progress: 100, tag: "notification01"}); // é²æãæ´æ°
GM_notification({ title: "Progress", text: "Done", progress: 100, tag: "notification01", timeout: 1}); // 1ms å¾ã«éãã
GM_setClipboard *â
ã¯ãªãããã¼ããè¨å®ãã¾ããTampermonkey ã¨ã¯ç°ãªããã³ã¼ã«ããã¯ã¯ã¾ã ãµãã¼ãããã¦ãã¾ããã
declare function GM_setClipboard(
data: string,
info?: string | { type?: string; mimetype?: string }
): void;
GM_setClipboard("Hello World", "text");
GM_xmlhttpRequest *â
-
CSP ãè¿åã§ããã¯ãã¹ãªãªã¸ã³ HTTP ãªã¯ã¨ã¹ãã
@connectã§å®£è¨ããããã¡ã¤ã³ããµãã¼ããã¾ããä¸é¨ã®æ©è½ãæ¬ è½ãã¦ãã¾ããCookie æ©è½ã¯ Firefox ã§ã¯ç¾å¨ãµãã¼ãããã¦ãã¾ãããé常ã®ã¢ã¯ã»ã¹ã«ã¯ã¦ã¼ã¶ã¼èªè¨¼ãå¿ è¦ã§ãã@connectã§è¨è¿°ããããã¹ãã¯ã¦ã¼ã¶ã¼èªè¨¼ãã¹ãããã§ãã¾ãã -
anonymousã¨cookie㯠Tampermonkey ã¨ç°ãªãæ¹æ³ã§å¦çããã¾ããanonymousã true ã§cookieãåå¨ããå ´åãæå®ããã cookie ã®ã¿ãéä¿¡ãããä»ã® cookie ã¯æ·»ä»ããã¾ããã
declare function GM_xmlhttpRequest(details: GMTypes.XHRDetails): GMTypes.AbortHandle<void>;
declare namespace GMTypes {
interface XHRResponse {
finalUrl?: string;
readyState?: 0 | 1 | 2 | 3 | 4;
responseHeaders?: string;
status?: number;
statusText?: string;
response?: any;
responseText?: string;
responseXML?: Document | null;
}
interface XHRProgress extends XHRResponse {
done: number;
lengthComputable: boolean;
loaded: number;
position: number;
total: number;
totalSize: number;
}
type Listener<OBJ> = (event: OBJ) => any;
interface XHRDetails {
method?: "GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "PATCH" | "OPTIONS";
url: string;
headers?: { [key: string]: string };
data?: string | FormData;
cookie?: string;
binary?: boolean;
timeout?: number;
responseType?: "text" | "arraybuffer" | "blob" | "json" | "document" | "stream";
overrideMimeType?: string;
anonymous?: boolean;
fetch?: boolean;
user?: string;
password?: string;
nocache?: boolean;
redirect?: "follow" | "error" | "manual";
onload?: Listener<XHRResponse>;
onloadstart?: Listener<XHRResponse>;
onloadend?: Listener<XHRResponse>;
onprogress?: Listener<XHRProgress>;
onreadystatechange?: Listener<XHRResponse>;
ontimeout?: () => void;
onabort?: () => void;
onerror?: (err: string) => void;
}
}
GM_xmlhttpRequest({
method: "GET",
url: "https://api.example.com/data",
onload: res => console.log(res.responseText)
});
GM_downloadâ
-
ãã¡ã¤ã«ããã¦ã³ãã¼ããã¾ãããããã¼ã¨ãã®ä»ã®ãªãã·ã§ã³ãè¨å®å¯è½ãTampermonkey ã¨æ¯è¼ãã¦ãcookie 㨠anonymous ãªãã·ã§ã³ããµãã¼ããã¦ãã¾ããblob URL ãæ¸¡ããå ´åãç´æ¥ãã¦ã³ãã¼ããéå§ãã
onloadã¤ãã³ãã®ã¿çºç«ãã¾ãããã㯠Tampermonkey ã¨ã¯ç°ãªããããã¯ã°ã©ã¦ã³ãã¹ã¯ãªããããµãã¼ãããããã®ãã®ã§ãã -
Promise ãªãã¸ã§ã¯ããè¿ãã
abort()ã¡ã½ãããæä¾ãã¾ãã -
Tampermonkey ã¨ã¯ç°ãªããScriptCat ã®
nativeãã¦ã³ãã¼ãã¢ã¼ãï¼ããã©ã«ãï¼ã¯@connectãèªèãã¾ãããã¦ã³ãã¼ã URL ã®ãã¹ããã¹ã¯ãªããã®@connect宣è¨ã§ã«ãã¼ããã¦ããªãå ´åãScriptCat ã¯ãã¦ã³ãã¼ãåã«ã¦ã¼ã¶ã¼ã«ç¢ºèªãä¿ãã¾ãã@connectã§ã«ãã¼ããããã¹ãã¯ãµã¤ã¬ã³ãã«ãã¦ã³ãã¼ãããããã©ãã¯ãªã¹ãããããã¹ãã¯å¸¸ã«æå¦ããã¾ãã
declare function GM_download(details: GMTypes.DownloadDetails): GMTypes.AbortHandle<boolean>;
declare function GM_download(url: string, filename: string): GMTypes.AbortHandle<boolean>;
declare namespace GMTypes {
interface DownloadError {
error:
| "not_enabled"
| "not_whitelisted"
| "not_permitted"
| "not_supported"
| "not_succeeded"
| "unknown";
details?: string;
}
interface DownloadDetails {
method?: "GET" | "POST";
downloadMode?: "native" | "browser";
url: string;
name: string;
headers?: { [key: string]: string };
saveAs?: boolean;
timeout?: number;
cookie?: string;
anonymous?: boolean;
onerror?: Listener<DownloadError>;
ontimeout?: () => void;
onload?: Listener<object>;
onprogress?: Listener<XHRProgress>;
}
}
// ã³ã¼ã«ããã¯å½¢å¼
const dl = GM_download({ url: "https://example.com/file.zip", name: "file.zip", onload: () => alert("Done") });
dl.abort();
GM_cookie *â
ãã¼ã¸ã®ã¯ããã¼ãéåæã§æä½ãã¾ããã¯ãã¹ãªãªã¸ã³ãHttpOnlyãããã³ãã¼ãã£ã·ã§ãã³ã°ãããã¯ããã¼ããµãã¼ããã¾ãã
v0.17.0-alpha 以éã
storeã¨tabidé¢é£ã®ãã©ã¡ã¼ã¿ã¯åé¤ããã¾ãããScriptCat ã¯ç¾å¨ã®ã¦ã£ã³ãã¦ã«åºã¥ãã¦ããã©ã¤ãã¼ãã¾ãã¯é常ã®ã¦ã£ã³ãã¦ããã¯ããã¼ãåå¾ãããã©ããã夿ãã¾ãã
æä½ãããã¹ãã @connect ã§å®£è¨ããå¿
è¦ãããã使ç¨ã«ã¯ã¦ã¼ã¶ã¼èªè¨¼ãå¿
è¦ã§ããTampermonkey ã® GM_cookie.list æä½ã¨äºææ§ãããã¾ãããä¸è²«æ§ã®ããã«ããã¯æ¨å¥¨ããã¾ããã
sameSiteã¯ãµãã¼ãããã¦ãã¾ããã
// name 㨠domain ã¯ä¸¡æ¹ã¨ã空ã«ã§ãã¾ãã
declare function GM_cookie(
action: GMTypes.CookieAction,
details: GMTypes.CookieDetails,
ondone: (cookie: GMTypes.Cookie[], error: unknown | undefined) => void
): void;
declare namespace GMTypes {
type CookieAction = "list" | "delete" | "set";
interface CookieDetails {
url?: string;
name?: string;
value?: string;
domain?: string;
path?: string;
secure?: boolean;
session?: boolean;
httpOnly?: boolean;
expirationDate?: number;
partitionKey?: CookieDetailsPartitionKeyType;
}
interface Cookie {
domain: string;
name: string;
value: string;
session: boolean;
hostOnly: boolean;
expirationDate?: number;
path: string;
httpOnly: boolean;
secure: boolean;
}
}
// ã³ã¼ã«ããã¯å½¢å¼
GM_cookie("list", { url: "https://example.com" }, (cookies) => {
console.log(cookies);
GM_cookie("set", {
name: "foo",
value: "bar",
domain: "example.com"
}, (result) => {
console.log(result);
GM_cookie("delete", { name: "foo", domain: "example.com" }, (result) => {
console.log(result);
});
});
});
// Promise å½¢å¼
const cookies = await GM.cookie.list({ url: "https://example.com" });
await GM.cookie.set({ name: "foo", value: "bar", domain: "example.com" });
await GM.cookie.delete("foo", { domain: "example.com" });
注æ: ã¡ã¿ãã¼ã¿ã§ @connect example.com ã使ç¨ãã¦è¨±å¯ããããã¡ã¤ã³ã宣è¨ããå¿
è¦ãããã¾ãã