@@ -126,15 +126,15 @@ export default class GMApi {
126126 grant : script . metadata . grant || [ ] ,
127127 connects : script . metadata . connect || [ ] ,
128128 } ;
129-
130129 return {
131130 downloadMode : "browser" ,
132131 // isIncognito
133132 // relaxedCsp
134133 // sandboxMode
135134 scriptWillUpdate : true ,
136135 scriptHandler : "ScriptCat" ,
137- scriptUpdateURL : script . downloadUrl ,
136+ // "" => null
137+ scriptUpdateURL : script . downloadUrl || null ,
138138 scriptMetaStr : script . metadataStr ,
139139 userConfig : parseUserConfig ( script . userConfigStr ) ,
140140 userConfigStr : script . userConfigStr ,
@@ -146,6 +146,9 @@ export default class GMApi {
146146 namespace : script . namespace ,
147147 version : script . metadata . version ?. [ 0 ] ,
148148 author : script . author ,
149+ lastModified : script . updatetime ,
150+ downloadURL : script . downloadUrl || null ,
151+ updateURL : script . checkUpdateUrl || null ,
149152 ...options ,
150153 } ,
151154 } ;
@@ -181,6 +184,57 @@ export default class GMApi {
181184 this . GM_setValue ( name , undefined ) ;
182185 }
183186
187+ @GMContext . API ( { depend : [ "GM_setValue" ] } )
188+ public GM_setValues ( values : object ) {
189+ if ( values == null ) {
190+ throw new Error ( "GM_ setValues: values must not be null or undefined" ) ;
191+ }
192+ if ( typeof values !== "object" ) {
193+ throw new Error ( "GM_setValues: values must be an object" ) ;
194+ }
195+ Object . keys ( values ) . forEach ( ( key ) => {
196+ let value = values [ key as keyof typeof values ] ;
197+ return this . GM_setValue ( key , value ) ;
198+ } ) ;
199+ }
200+
201+ @GMContext . API ( { depend : [ "GM_getValue" ] } )
202+ public GM_getValues ( keysOrDefaults : object | string [ ] | null | undefined ) {
203+ if ( keysOrDefaults == null ) {
204+ // returns all
205+ return this . scriptRes . value ;
206+ }
207+ let result = < { [ key : string ] : any } > { } ;
208+ if ( Array . isArray ( keysOrDefaults ) ) {
209+ // 键名数组
210+ for ( let index = 0 ; index < keysOrDefaults . length ; index ++ ) {
211+ const key = keysOrDefaults [ index ] ;
212+ if ( key in this . scriptRes . value ) {
213+ result [ key ] = this . scriptRes . value [ key ] ;
214+ }
215+ }
216+ } else {
217+ // 对象 键: 默认值
218+ Object . keys ( keysOrDefaults ) . forEach ( ( key ) => {
219+ let defaultValue = keysOrDefaults [ key as keyof typeof keysOrDefaults ] ;
220+ result [ key ] = this . GM_getValue ( key , defaultValue ) ;
221+ } ) ;
222+ }
223+
224+ return result ;
225+ }
226+
227+ @GMContext . API ( { depend : [ "GM_deleteValue" ] } )
228+ public GM_deleteValues ( keys : string [ ] ) {
229+ if ( ! Array . isArray ( keys ) ) {
230+ console . warn ( " GM_deleteValues: keys must be string[]" ) ;
231+ return ;
232+ }
233+ keys . forEach ( ( key ) => {
234+ this . GM_deleteValue ( key ) ;
235+ } ) ;
236+ }
237+
184238 eventId : number = 0 ;
185239
186240 menuMap : Map < number , string > | undefined ;
@@ -736,6 +790,9 @@ export default class GMApi {
736790 close : ( ) => {
737791 tabid && this . GM_closeInTab ( tabid ) ;
738792 } ,
793+ closed : false ,
794+ // 占位
795+ onclose ( ) { } ,
739796 } ;
740797
741798 this . sendMessage ( "GM_openInTab" , [ url , option ] ) . then ( ( id ) => {
@@ -775,7 +832,7 @@ export default class GMApi {
775832 @GMContext . API ( )
776833 GM_getTab ( callback : ( data : any ) => void ) {
777834 this . sendMessage ( "GM_getTab" , [ ] ) . then ( ( data ) => {
778- callback ( data ) ;
835+ callback ( data ?? { } ) ;
779836 } ) ;
780837 }
781838
@@ -795,8 +852,18 @@ export default class GMApi {
795852 }
796853
797854 @GMContext . API ( )
798- GM_setClipboard ( data : string , info ?: string | { type ?: string ; minetype ?: string } ) {
799- this . sendMessage ( "GM_setClipboard" , [ data , info ] ) ;
855+ GM_setClipboard ( data : string , info ?: string | { type ?: string ; minetype ?: string } , cb ?: ( ) => void ) {
856+ this . sendMessage ( "GM_setClipboard" , [ data , info ] )
857+ . then ( ( resp ) => {
858+ if ( typeof cb === "function" ) {
859+ cb ( ) ;
860+ }
861+ } )
862+ . catch ( ( ) => {
863+ if ( typeof cb === "function" ) {
864+ cb ( ) ;
865+ }
866+ } ) ;
800867 }
801868
802869 @GMContext . API ( )
0 commit comments