API 文件
概覽
此擴充功能的 API 定義基於 Tampermonkey 文件。由於時間和精力限制,目前僅實現了部分 API,並且會持續迭代。此擴充功能擴展或與原始 GM API 不同的 API 在文件中特別標註(使用 *)。部分 API 也提供遵循 GM.* 規則的同步式對應方法。
詳細 API 定義請參閱 scriptcat.d.ts 或編輯器內建提示。此擴充功能特有的 API 請參閱 CatApi 文件。
相關範例可在 example 目錄 找到。
定義
GM_info
取得腳本資訊,包括元資料和執行環境參數。
console.log(GM_info.scriptHandler);
console.log(GM_info.version);
console.log(GM_info.scriptMetaStr);
sandboxMode目前僅有raw值。runAt不受支援。
GM_log *
日誌函數。背景腳本的日誌可在控制面板的執行日誌中查看。
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 下的資料可共享並即時同步。
declare function GM_setValue(name: string, value: any): void;
declare function GM_getValue(name: string, defaultValue?: any): any | undefined;
declare function GM_deleteValue(name: string): void;
GM_setValue("foo", 42);
const v = GM_getValue("foo", 0);
GM_deleteValue("foo");