@@ -2305,7 +2305,7 @@ declare global {
23052305 /** Gets the headers of a plugin, such as version, author, and description */
23062306 getHeaders ( name : string ) : ScriptHeaders ;
23072307 /** Gets the exported values of a plugin, if it has been enabled */
2308- get ( name : string ) : any ;
2308+ get < T extends keyof Gimloader . Plugins > ( name : T ) : Gimloader . Plugins [ T ] ;
23092309 /**
23102310 * @deprecated Use {@link get} instead
23112311 * @hidden
@@ -2342,7 +2342,7 @@ declare global {
23422342 /** Gets the headers of a library, such as version, author, and description */
23432343 getHeaders ( name : string ) : ScriptHeaders ;
23442344 /** Gets the exported values of a library */
2345- get ( name : string ) : any ;
2345+ get < T extends keyof Gimloader . Libraries > ( name : T ) : Gimloader . Libraries [ T ] ;
23462346 }
23472347
23482348 class ScopedCommandsApi {
@@ -2415,6 +2415,23 @@ declare global {
24152415 createShared ( id : string , value : any ) : string ;
24162416 /** Removes the shared value with a certain id created by {@link createShared} */
24172417 removeSharedById ( id : string ) : void ;
2418+ /**
2419+ * Runs code in the scope of modules when they are loaded, or when runInScope is called with them already loaded.
2420+ * Returning true from the callback will remove the hook.
2421+ */
2422+ runInScope ( prefix : string | boolean , callback : RunInScopeCallback ) : ( ) => void ;
2423+ /** A utility function that exposes a variable based on regex to get its name. */
2424+ exposeVar ( prefix : string | boolean , exposer : Exposer ) : ( ) => void ;
2425+ }
2426+
2427+ // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
2428+ type RunInScopeCallback = ( code : string , run : ( evalCode : string ) => void ) => true | void ;
2429+
2430+ interface Exposer {
2431+ check ?: string ;
2432+ find : RegExp ;
2433+ callback : ( val : any ) => void ;
2434+ multiple ?: boolean ;
24182435 }
24192436
24202437 class RewriterApi {
@@ -2425,10 +2442,10 @@ declare global {
24252442 * @param pluginName The name of the plugin creating the hook.
24262443 * @param prefix Limits the hook to only running on scripts beginning with this prefix.
24272444 * Passing `true` will only run on the index script, and passing `false` will run on all scripts.
2428- * @param callback The function that will modify the code. Should return the modified code. Cannot have side effects .
2445+ * @param callback A function that will modify the code, which should return the modified code.
24292446 */
2430- addParseHook ( pluginName : string , prefix : string | boolean , callback : ( code : string ) => string ) : ( ) => void ;
2431- /** Removes all hooks created by a certain plugin */
2447+ addParseHook ( pluginName : string , prefix : string | boolean , modifier : ( code : string ) => string ) : ( ) => void ;
2448+ /** Removes all parse hooks created by a certain plugin */
24322449 removeParseHooks ( pluginName : string ) : void ;
24332450 /**
24342451 * Creates a shared value that can be accessed from any script.
@@ -2442,6 +2459,15 @@ declare global {
24422459 removeShared ( pluginName : string ) : void ;
24432460 /** Removes the shared value with a certain id created by {@link createShared} */
24442461 removeSharedById ( pluginName : string , id : string ) : void ;
2462+ /**
2463+ * Runs code in the scope of modules when they are loaded, or when runInScope is called with them already loaded.
2464+ * Returning true from the callback will remove the hook.
2465+ */
2466+ runInScope ( pluginName : string , prefix : string | boolean , callback : RunInScopeCallback ) : ( ) => void ;
2467+ /** Stops all hooks created by {@link runInScope} */
2468+ removeRunInScope ( pluginName : string ) : void ;
2469+ /** A utility function that exposes a variable based on regex to get its name. */
2470+ exposeVar ( pluginName : string , prefix : string | boolean , exposer : Exposer ) : ( ) => void ;
24452471 }
24462472
24472473 class ScopedPatcherApi {
@@ -2836,11 +2862,11 @@ declare global {
28362862 /** Methods for getting info on libraries */
28372863 static libs : Readonly < LibsApi > ;
28382864 /** Gets the exported values of a library */
2839- static lib : ( name : string ) => any ;
2865+ static lib : < T extends keyof Gimloader . Libraries > ( name : T ) => Gimloader . Libraries [ T ] ;
28402866 /** Methods for getting info on plugins */
28412867 static plugins : Readonly < PluginsApi > ;
28422868 /** Gets the exported values of a plugin, if it has been enabled */
2843- static plugin : ( name : string ) => any ;
2869+ static plugin : < T extends keyof Gimloader . Plugins > ( name : T ) => Gimloader . Plugins [ T ] ;
28442870 /** Gimkit's internal react instance */
28452871 static get React ( ) : typeof import ( "react" ) ;
28462872 /** Gimkit's internal reactDom instance */
@@ -2909,11 +2935,11 @@ declare global {
29092935 /** Methods for getting info on libraries */
29102936 libs : Readonly < LibsApi > ;
29112937 /** Gets the exported values of a library */
2912- lib : ( name : string ) => any ;
2938+ lib : < T extends keyof Gimloader . Libraries > ( name : T ) => Gimloader . Libraries [ T ] ;
29132939 /** Methods for getting info on plugins */
29142940 plugins : Readonly < PluginsApi > ;
29152941 /** Gets the exported values of a plugin, if it has been enabled */
2916- plugin : ( name : string ) => any ;
2942+ plugin : < T extends keyof Gimloader . Plugins > ( name : T ) => Gimloader . Plugins [ T ] ;
29172943 /** Gimkit's internal react instance */
29182944 get React ( ) : typeof import ( "react" ) ;
29192945 /** Gimkit's internal reactDom instance */
@@ -2935,6 +2961,14 @@ declare global {
29352961 */
29362962 openSettingsMenu : ( callback : ( ) => void ) => void ;
29372963 }
2964+
2965+ interface Plugins {
2966+ [ name : string ] : any ;
2967+ }
2968+
2969+ interface Libraries {
2970+ [ name : string ] : any ;
2971+ }
29382972 }
29392973 const api : Gimloader . Api ;
29402974 const GL : typeof Gimloader . Api ;
0 commit comments