Skip to content

Global Rewriter Api

The rewriter API allows you to modify the bundled code of Gimkit in order to expose values or change certain behaviors. Due to the unpredictable nature of bundling, you cannot assume that variable names will remain the same beteen updates.

addParseHook(pluginName, prefix, modifier): () => void

Creates a hook that will modify the code of a script before it is run. This value is cached, so this hook may not run on subsequent page loads. addParseHook should always be called in the top level of a script.

Parameter Type Description
pluginName string The name of the plugin creating the hook.
prefix string | boolean Limits the hook to only running on scripts beginning with this prefix. Passing true will only run on the index script, and passing false will run on all scripts.
modifier (code) => string A function that will modify the code, which should return the modified code.

Function

A function that removes the hook when called

void

GL.rewriter.addParseHook("MyPlugin", "App", (code) => {
let index = code.indexOf("something");
code = code.slice(0, index) + `console.log("something else")` + code.slice(index);
code += "console.log(someVar)";
return code;
});

createShared(pluginName, id, value): string

Creates a shared value that can be accessed from any script.

Parameter Type Description
pluginName string The name of the plugin creating the shared value.
id string A unique identifier for the shared value.
value any The value to be shared.

string

A string representing the code to access the shared value.

const callback = GL.rewriter.createShared("MyPlugin", "uniqueId", (val) => {
console.log(val);
});
eval(`${callback}("15")`); // Don't actually do this, but it logs 15

exposeVar(pluginName, prefix, exposer): () => void

A utility function that exposes a variable based on regex to get its name.

Parameter Type
pluginName string
prefix string | boolean
exposer { callback: (val) => void; check: string; find: RegExp; multiple: boolean; }
exposer.callback (val) => void
exposer.check? string
exposer.find RegExp
exposer.multiple? boolean

Function

A function that removes the hook when called

void

GL.rewriter.exposeVar("MyPlugin", "App", {
check: "StringThatMustExistInFile",
find: /let (\w+) = something/g,
multiple: false,
callback: (var) => console.log(var)
});

removeParseHooks(pluginName): void

Removes all parse hooks created by a certain plugin

Parameter Type
pluginName string

void


removeRunInScope(pluginName): void

Stops all hooks created by runInScope

Parameter Type
pluginName string

void


removeShared(pluginName): void

Removes all values created by createShared by a certain plugin

Parameter Type
pluginName string

void


removeSharedById(pluginName, id): void

Removes the shared value with a certain id created by createShared

Parameter Type
pluginName string
id string

void


runInScope(pluginName, prefix, callback): () => void

Runs code in the scope of modules when they are loaded, or when runInScope is called with them already loaded. Returning true from the callback will remove the hook.

Parameter Type
pluginName string
prefix string | boolean
callback (code, run, initial) => true | void

Function

A function that removes the hook when called

void

GL.rewriter.runInScope("MyPlugin", "App", (code, run, initial) => {
if(code.includes("something")) {
run(`someVar=15`);
}
});