2026-10-06 15:03:16 +00:00
# API Reference
2026-10-25 13:03:15 +00:00
BetterCurseForge adds a global object, `window.BetterCurseForge` , to CurseForge's Electron renderer process. Themes, plugins and your own scripts can use it to inject styles, patch methods, read and write settings, and listen for events.
2026-10-06 15:03:16 +00:00
---
2026-10-25 13:03:15 +00:00
## TypeScript definitions
2026-10-06 15:03:16 +00:00
2026-10-25 13:03:15 +00:00
If you're using TypeScript, this gives you types and autocompletion:
2026-10-06 15:03:16 +00:00
```typescript
declare global {
interface Window {
BetterCurseForge: BetterCurseForgeAPI;
}
}
export interface BetterCurseForgeAPI {
/** Active BetterCurseForge runtime version */
readonly version: string;
/** Injects CSS dynamically into < head > . Returns an unmount callback. */
injectCSS(css: string): () => void;
/** Persistent settings storage */
settings: {
get(key?: string): Promise< any > ;
set(key: string, value: any): Promise< boolean > ;
};
/** Runtime method interception and monkey-patching */
patcher: {
before(obj: any, method: string, callback: (args: any[]) => void): () => void;
after(obj: any, method: string, callback: (args: any[], result: any) => any): () => void;
instead(obj: any, method: string, callback: (args: any[], original: Function) => any): () => void;
};
/** Event bus */
on(event: string, callback: (...args: any[]) => void): void;
off(event: string, callback: (...args: any[]) => void): void;
emit(event: string, ...args: any[]): void;
/** Internal subsystem managers */
themes: ThemeManager;
plugins: PluginManager;
ads: AdBlocker;
}
```
---
## Core API
### `BetterCurseForge.version`
- **Type**: `string`
2026-10-25 13:03:15 +00:00
- **Description**: Version of the BetterCurseForge runtime that's currently running.
2026-10-06 15:03:16 +00:00
```javascript
console.log(BetterCurseForge.version); // "1.0.0"
```
---
### `BetterCurseForge.injectCSS(css)`
2026-10-25 13:03:15 +00:00
Adds CSS rules to the document `<head>` .
2026-10-06 15:03:16 +00:00
- **Parameters**:
2026-10-25 13:03:15 +00:00
- `css` *(string)* : The CSS to inject.
- **Returns**: `() => void` . Call it to remove the injected `<style>` tag.
2026-10-06 15:03:16 +00:00
```javascript
// Inject styles
const uninject = BetterCurseForge.injectCSS(`
.some-container {
background-color: #1a102f !important;
}
`);
// Later, remove the styles
uninject();
```
---
## Settings API (`BetterCurseForge.settings`)
2026-10-25 13:03:15 +00:00
Persistent configuration, stored in `%APPDATA%\CurseForge\BetterCurseForge\settings.json` .
2026-10-06 15:03:16 +00:00
### `settings.get(key?)`
2026-10-25 13:03:15 +00:00
Returns the setting for `key` , or the whole settings object if you don't pass a key.
2026-10-06 15:03:16 +00:00
- **Parameters**:
2026-10-25 13:03:15 +00:00
- `key` *(string, optional)* : Name of the setting.
- **Returns**: `Promise<any>` . The value, or `null` if it isn't set.
2026-10-06 15:03:16 +00:00
```javascript
// Retrieve a specific value
const activeTheme = await BetterCurseForge.settings.get('activeCustomTheme');
// Retrieve all settings
const allSettings = await BetterCurseForge.settings.get();
```
### `settings.set(key, value)`
2026-10-25 13:03:15 +00:00
Saves a value and writes it to disk asynchronously.
2026-10-06 15:03:16 +00:00
- **Parameters**:
2026-10-25 13:03:15 +00:00
- `key` *(string)* : Name of the setting.
- `value` *(any)* : Any JSON-serializable value.
- **Returns**: `Promise<boolean>` . `true` if the save worked.
2026-10-06 15:03:16 +00:00
```javascript
await BetterCurseForge.settings.set('myPlugin.fontSize', 14);
```
---
## Patcher API (`BetterCurseForge.patcher`)
2026-10-25 13:03:15 +00:00
Utilities for inspecting, modifying or replacing methods on JavaScript objects and modules. Every function returns an unpatch function.
2026-10-06 15:03:16 +00:00
### `patcher.before(obj, method, callback)`
2026-10-25 13:03:15 +00:00
Runs `callback(args)` **before** the target method is called.
2026-10-06 15:03:16 +00:00
- **Parameters**:
- `obj` *(object)* : Target object.
- `method` *(string)* : Method name on `obj` .
2026-10-25 13:03:15 +00:00
- `callback` *(Function)* : `(args) => void` .
- **Returns**: `() => void` . Call it to restore the original method.
2026-10-06 15:03:16 +00:00
```javascript
const unpatch = BetterCurseForge.patcher.before(console, 'warn', (args) => {
console.log('[Warn Interceptor]', ...args);
});
// Revert patch:
unpatch();
```
---
### `patcher.after(obj, method, callback)`
2026-10-25 13:03:15 +00:00
Runs `callback(args, result)` **after** the target method. Return a value to replace the method's return value.
2026-10-06 15:03:16 +00:00
- **Parameters**:
- `obj` *(object)* : Target object.
- `method` *(string)* : Method name on `obj` .
- `callback` *(Function)* : `(args, result) => any` .
2026-10-25 13:03:15 +00:00
- **Returns**: `() => void` . Unpatch function.
2026-10-06 15:03:16 +00:00
```javascript
const unpatch = BetterCurseForge.patcher.after(service, 'getTitle', (args, result) => {
return `Prefix: ${result}` ;
});
unpatch();
```
---
### `patcher.instead(obj, method, callback)`
2026-10-25 13:03:15 +00:00
Replaces the target method. The callback gets the arguments and a reference to the original method.
2026-10-06 15:03:16 +00:00
- **Parameters**:
- `obj` *(object)* : Target object.
- `method` *(string)* : Method name on `obj` .
- `callback` *(Function)* : `(args, originalFn) => any` .
2026-10-25 13:03:15 +00:00
- **Returns**: `() => void` . Unpatch function.
2026-10-06 15:03:16 +00:00
```javascript
const unpatch = BetterCurseForge.patcher.instead(target, 'openExternalUrl', (args, originalFn) => {
const url = args[0];
if (url.startsWith('https://safe-domain.com')) {
return originalFn(...args);
}
console.warn('Blocked external URL navigation:', url);
});
unpatch();
```
---
2026-10-25 13:03:15 +00:00
## Event system (`BetterCurseForge.on / off / emit`)
2026-10-06 15:03:16 +00:00
2026-10-25 13:03:15 +00:00
BetterCurseForge has an event bus that plugins can use to talk to each other and to react to lifecycle events.
2026-10-06 15:03:16 +00:00
### `BetterCurseForge.on(event, callback)`
2026-10-25 13:03:15 +00:00
Adds a listener for an event.
2026-10-06 15:03:16 +00:00
```javascript
const onReady = () => console.log('BetterCurseForge is ready!');
BetterCurseForge.on('ready', onReady);
```
### `BetterCurseForge.off(event, callback)`
2026-10-25 13:03:15 +00:00
Removes a listener.
2026-10-06 15:03:16 +00:00
```javascript
BetterCurseForge.off('ready', onReady);
```
### `BetterCurseForge.emit(event, ...args)`
2026-10-25 13:03:15 +00:00
Calls every listener registered for the event.
2026-10-06 15:03:16 +00:00
```javascript
BetterCurseForge.emit('custom-event', { detail: 123 });
```
---
2026-10-25 13:03:15 +00:00
## Subsystem managers
2026-10-06 15:03:16 +00:00
### `BetterCurseForge.themes` (`ThemeManager`)
2026-10-25 13:03:15 +00:00
Control custom themes from code:
2026-10-06 15:03:16 +00:00
```javascript
// Get all discovered themes
const themes = BetterCurseForge.themes.getThemes();
// Get active theme filename (or null)
const currentTheme = BetterCurseForge.themes.getActiveThemeName();
// Preview a theme temporarily on screen
BetterCurseForge.themes.previewTheme(themes[0]);
// Revert preview back to active theme
BetterCurseForge.themes.cancelPreview();
// Apply and save a theme permanently
BetterCurseForge.themes.applyTheme(themes[0], true);
// Remove custom theme and revert to native CurseForge skin
BetterCurseForge.themes.removeTheme(true);
```
### `BetterCurseForge.plugins` (`PluginManager`)
2026-10-25 13:03:15 +00:00
Control plugins from code:
2026-10-06 15:03:16 +00:00
```javascript
// Get all installed plugins
const plugins = BetterCurseForge.plugins.getPlugins();
// Toggle a plugin by folder name
await BetterCurseForge.plugins.togglePlugin('compact-mode');
```
### `BetterCurseForge.ads` (`AdBlocker`)
2026-10-25 13:03:15 +00:00
The internal ad blocker runtime:
2026-10-06 15:03:16 +00:00
```javascript
// Contains zero-ad CSS rules and ad container cleanup handlers
console.log(BetterCurseForge.ads);
```