@@ -203,6 +203,105 @@ declare function GM_cookie(
203203 ondone : ( cookie : GMTypes . Cookie [ ] , error : unknown | undefined ) => void
204204) : void ;
205205
206+ /**
207+ * GM.* API (兼容 Greasemonkey4/Tampermonkey 4+ 的 Promise 风格)
208+ */
209+ declare const GM : {
210+ /** 脚本信息 */
211+ readonly info : typeof GM_info ;
212+
213+ /** 获取一个值 */
214+ getValue < T = any > ( name : string , defaultValue ?: T ) : Promise < T > ;
215+
216+ /** 获取多个值, 如果keysOrDefaults是一个对象, 则使用对象的值作为默认值 */
217+ getValues ( keysOrDefaults : { [ key : string ] : any } | string [ ] | null | undefined ) : Promise < { [ key : string ] : any } > ;
218+
219+ /** 设置一个值 */
220+ setValue ( name : string , value : any ) : Promise < void > ;
221+
222+ /** 设置多个值, values是一个对象, 键为值的名称, 值为值的内容 */
223+ setValues ( values : { [ key : string ] : any } ) : Promise < void > ;
224+
225+ /** 删除一个值 */
226+ deleteValue ( name : string ) : Promise < void > ;
227+
228+ /** 删除多个值, names是一个字符串数组 */
229+ deleteValues ( names : string [ ] ) : Promise < void > ;
230+
231+ /** 获取所有已保存值的 key 列表 */
232+ listValues ( ) : Promise < string [ ] > ;
233+
234+ /** 值变更监听 */
235+ addValueChangeListener ( name : string , listener : GMTypes . ValueChangeListener ) : Promise < number > ;
236+ removeValueChangeListener ( listenerId : number ) : Promise < void > ;
237+
238+ /** 支持level和label */
239+ log ( message : string , level ?: GMTypes . LoggerLevel , labels ?: GMTypes . LoggerLabel ) : Promise < void > ;
240+
241+ /** 获取资源文本 */
242+ getResourceText ( name : string ) : Promise < string | undefined > ;
243+
244+ /** 获取资源URL */
245+ getResourceURL ( name : string , isBlobUrl ?: boolean ) : Promise < string | undefined > ;
246+
247+ /** 注册菜单 */
248+ registerMenuCommand (
249+ name : string ,
250+ listener ?: ( inputValue ?: any ) => void ,
251+ options_or_accessKey ?:
252+ | {
253+ id ?: number | string ;
254+ accessKey ?: string ; // 菜单快捷键
255+ autoClose ?: boolean ; // 默认为 true
256+ title ?: string ; // 菜单提示
257+ // ScriptCat 扩展
258+ icon ?: string ; // 菜单图标
259+ // ScriptCat 扩展
260+ closeOnClick ?: boolean ; // 点击菜单后是否关闭, 与autoClose含义相同
261+ }
262+ | string
263+ ) : Promise < number | string | undefined > ;
264+
265+ /** 注销菜单 */
266+ unregisterMenuCommand ( id : number | string ) : Promise < void > ;
267+
268+ /** 样式注入 */
269+ addStyle ( css : string ) : Promise < void > ;
270+
271+ /** 通知 */
272+ notification ( details : GMTypes . NotificationDetails , ondone ?: GMTypes . NotificationOnDone ) : Promise < void > ;
273+ notification ( text : string , title : string , image : string , onclick ?: GMTypes . NotificationOnClick ) : Promise < void > ;
274+ closeNotification ( id : string ) : Promise < void > ;
275+ updateNotification ( id : string , details : GMTypes . NotificationDetails ) : Promise < void > ;
276+
277+ /** 设置剪贴板 */
278+ setClipboard ( data : string , info ?: string | { type ?: string ; mimetype ?: string } ) : Promise < void > ;
279+
280+ /** 添加元素 */
281+ addElement ( tag : string , attributes : any ) : Promise < HTMLElement > ;
282+ addElement ( parentNode : Element , tag : string , attrs : any ) : Promise < HTMLElement > ;
283+
284+ /** XMLHttpRequest */
285+ xmlHttpRequest ( details : GMTypes . XHRDetails ) : Promise < GMTypes . XHRResponse > ;
286+
287+ /** 下载 */
288+ download ( details : GMTypes . DownloadDetails < string | Blob | File > ) : Promise < boolean > ;
289+ download ( url : string , filename : string ) : Promise < boolean > ;
290+
291+ /** Tab 存储 */
292+ getTab ( ) : Promise < object > ;
293+ saveTab ( obj : object ) : Promise < void > ;
294+ getTabs ( ) : Promise < { [ key : number ] : object } > ;
295+
296+ /** 打开新标签页 */
297+ openInTab ( url : string , options : GMTypes . OpenTabOptions ) : Promise < GMTypes . Tab | undefined > ;
298+ openInTab ( url : string , loadInBackground : boolean ) : Promise < GMTypes . Tab | undefined > ;
299+ openInTab ( url : string ) : Promise < GMTypes . Tab | undefined > ;
300+
301+ /** Cookie 操作 */
302+ cookie ( action : GMTypes . CookieAction , details : GMTypes . CookieDetails ) : Promise < GMTypes . Cookie [ ] > ;
303+ } ;
304+
206305/**
207306 * 设置浏览器代理
208307 * @deprecated 正式版中已废弃,后续可能会在beta版本中添加
0 commit comments