API 문ì
ê°ìâ
ì´ íì¥ íë¡ê·¸ë¨ì API ì ìë Tampermonkey 문ì를 기ë°ì¼ë¡ í©ëë¤. ìê°ê³¼ ë
¸ë ¥ì ì ì½ì¼ë¡ íì¬ ì¼ë¶ APIë§ êµ¬íëìì¼ë©° ê³ì ë°ë³µë ê²ì
ëë¤. ì´ íì¥ íë¡ê·¸ë¨ì´ íì¥íê±°ë ìë GM APIì ë¤ë¥¸ 모ë APIë 문ììì í¹ë³í íìë©ëë¤(* ì¬ì©). ì¼ë¶ APIë GM.* ê·ì¹ì ë°ë¥´ë ë기 ì¤íì¼ ëì물ë ì ê³µí©ëë¤ â ìì¸í ë´ì©ì 문ì ì½í
ì¸ ë¥¼ 참조íì¸ì.
ìì¸í API ì ìë 문ìê° íì ìµì ì´ ìë ì ìì¼ë¯ë¡ scriptcat.d.ts ëë 기본 ì ê³µ í¸ì§ê¸° íí¸ë¥¼ 참조íì¸ì. ì´ íì¥ íë¡ê·¸ë¨ì í¹íë APIë CatApi 문ì를 참조íì¸ì.
ìì ëë í°ë¦¬ìì ê´ë ¨ ìì ë ì°¾ì ì ììµëë¤.
ì ìâ
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ë¡ í¸ì¶ëë©´ ScriptCatì undefined를 ê°ì¼ë¡ ì ì¥íë Tampermonkey/GreaseMonkeyì ë¬ë¦¬ í´ë¹ í¤ë¥¼ ìì í©ëë¤.â
ì°¸ê³ : ë°ì´í° ìì
ì ë¹ë기ì´ë¯ë¡ 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 {
/**
* ì íì´ ì´ë¦´ ë ì´ì ì ë°ëì§ ì¬ë¶ë¥¼ ê²°ì í©ëë¤.
*
* - `true` â ì íì´ ì¦ì ì ê²½ì¼ë¡ ì íë©ëë¤.
* - `false` â ì íì´ ë°±ê·¸ë¼ì´ëìì ì´ë¦¬ë©° íì¬ íì´ì§ìì ì´ì ì ë¹¼ìì§ ììµëë¤.
*
* 기본ê°: true
*/
active?: boolean;
/**
* ì íì´ ì½ì
ëë ìì¹ë¥¼ ê²°ì í©ëë¤.
*
* - `boolean`ì´ë©´:
* - `true` â íì¬ í ë°ë¡ ë¤ì ì½ì
ë©ëë¤.
* - `false` â ì°½ ëì ì½ì
ë©ëë¤.
* - `number`ì´ë©´:
* - `0` â íì¬ íë³´ë¤ í ìì¹ ìì ì½ì
ë©ëë¤.
* - `1` â íì¬ íë³´ë¤ í ìì¹ ë¤ì ì½ì
ë©ëë¤.
*
* 기본ê°: true
*/
insert?: boolean | number;
/**
* ë¶ëª¨ í(ì¦ `openerTabId`)ì´ ì¤ì ëëì§ ì¬ë¶ë¥¼ ê²°ì í©ëë¤.
*
* - `true` â ë¸ë¼ì°ì ê° ìì íì ì° íì ì¶ì í ì ìì¼ë©°,
* ì´ë ì¼ë¶ íì¥ íë¡ê·¸ë¨(í í¸ë¦¬ ê´ë¦¬ì ë±)ì´ ë¶ëª¨/ìì ê´ê³ë¥¼ ìë³íë ë° ëìì´ ë©ëë¤.
*
* 기본ê°: true
*/
setParent?: boolean;
/**
* ìí¬ë¦¿(incognito) ì°½ìì íì ì´ì§ ì¬ë¶.
*
* ì°¸ê³ : ScriptCatì manifest.jsonì `"incognito": "split"`ì¼ë¡ ì¤ì íë¯ë¡
* ì¼ë° ì°½ìì ì¤íí ë tabId/windowId를 ì¬ì©í ì ìì¼ë©°
* "ì í ì´ê¸°" ìì
ë§ ìíí ì ììµëë¤.
*
* 기본ê°: false
*/
incognito?: boolean;
/**
* ë ê±°ì í¸í íë, Tampermonkeyë§ ì§ìí©ëë¤.
* ì미ë `active`ì **ë°ë**ì
ëë¤:
*
* - `true` â `active = false`ì ëì¼ (백그ë¼ì´ëìì ë¡ë).
* - `false` â `active = true`ì ëì¼ (ì ê²½ìì ë¡ë).
*
* â ï¸ ê¶ì¥íì§ ìì: `active`ì ê²¹ì¹ê³ í¼ëí기 ì½ìµëë¤.
*
* 기본ê°: false
* @deprecated ëì `active`를 ì¬ì©íì¸ì
*/
loadInBackground?: boolean;
/**
* ì íì ë¸ë¼ì°ì í 모ìì ì¼ìª½ì ê³ ì í ì§ ì¬ë¶.
*
* - `true` â ì íì´ ê³ ì ë©ëë¤.
* - `false` â ì¼ë° í.
*
* 기본ê°: false
*/
pinned?: boolean;
/**
* `chrome.tabs.create` ëì `window.open`ì ì¬ì©íì¬ ì íì ì½ëë¤.
* `vscode://`, `m3u8dl://` ê°ì í¹ì íë¡í ì½ì´ ìë ë§í¬ë¥¼ ì´ ë ì ì©í©ëë¤.
* ì´ ì´ê¸° ë°©ë²ì ì¬ì©íë©´ ë¤ë¥¸ 매ê°ë³ìë í¨ê³¼ê° ììµëë¤.
*
* ê´ë ¨: Issue #178 #1043
* 기본ê°: false
*/
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_closeInTabâ
GM_openInTabì¼ë¡ ì° íì ë«ìµëë¤.
declare function GM_closeInTab(tabId: string): void;
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ì ì¼ì¹íëë¡ ëì¼í íì í ì¤í¸ì ë©ë´ í목ì í ë²ë§ íìë©ëë¤.
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(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ë¡ ì ì¸ë ëë©ì¸ì ì§ìí©ëë¤. ì¼ë¶ 기ë¥ì´ ëë½ëìì¼ë©° ì¿ í¤ ê¸°ë¥ì íì¬ Firefoxìì ì§ìëì§ ììµëë¤. ì¼ë° ì¡ì¸ì¤ìë ì¬ì©ì ì¸ì¦ì´ íìí©ëë¤.@connectë¡ ì¤ëª ë í¸ì¤í¸ë ì¬ì©ì ì¸ì¦ì ê±´ëë¸ ì ììµëë¤. -
anonymousë°cookieë Tampermonkeyì ë¤ë¥´ê² ì²ë¦¬ë©ëë¤:anonymousê° trueì´ê³cookieê° ìì¼ë©´ ë¤ë¥¸ ì¿ í¤ ìì´ ì§ì ë ì¿ í¤ë§ ì ì¡ë©ëë¤. -
í¹ì í¤ëë ì§ìë©ëë¤:
- user-agent
- origin
- referer
- cookie
- host
- ...
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"; // streamì íì¬ ë²ì ìì ìë¹í 기본ì ì¸ êµ¬íì
ëë¤
overrideMimeType?: string;
anonymous?: boolean;
fetch?: boolean;
user?: string;
password?: string;
nocache?: boolean;
redirect?: "follow" | "error" | "manual"; // Tampermonkeyì ì¼ê´ì±ì ì ì§í기 ìí´ maxRedirectsë v0.17.0 ì´í redirectë¡ ëì²´ëì´ ì¬ì© ì¤ë¨ëììµëë¤. redirectë fetch 모ë를 ê°ì í©ëë¤
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ë¡ ì²ë¦¬ëë í¸ì¤í¸ë ìëì¼ë¡ ë¤ì´ë¡ëëë©° ë¸ë리ì¤í¸ í¸ì¤í¸ë íì ê±°ë¶ë©ëë¤.browserë¤ì´ë¡ë 모ëë ì´ ê²ì¬ ëìì´ ìëëë¤. (Tampermonkeyìì@connectëGM_xmlhttpRequestìë§ ì ì©ëë©°GM_downloadìë ì ì©ëì§ ììµëë¤.)
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ì ì¬ì©íì¬ íì©ë ëë©ì¸ì ì ì¸í´ì¼ í©ëë¤.