Repository navigation
Userscript Development
David Reed edited this page Oct 2, 2022
·
4 revisions
Scripts containing // ==UserScript== will be treated as game-only legacy IDKR scripts.
Support for legacy IDKR scripts are supported.
'use strict';
exports.locations = ['game' /* 'all', 'social', 'editor' */];
exports.run = () => {
alert('Hi');
};- Allows comments (
// Comment,/* Block */) - Must be valid JSON (no JS style properties)
- First occurance of
const metadata = {...};is used - End metadata object with semicolon
- Can be anywhere; Preferably after
'use strict';
'use strict';
const metadata = {
// Despite being valid JS syntax, this is parsed as JSON with comments
"name": "Userscript",
"author": "Chief Software",
"description": "A script to demonstrate new powerful APIs",
"version": 0.1,
"locations": ["game"],
"features": {
// Blocked hosts take effect when the page loads
"block_hosts": [
"domain.com"
],
// Command line flags take effect when the client launches
"command_line": [
"--allow-running-insecure-content"
],
"gui": {
"Work": {
"Will alert?": {
"type": "boolean",
"walk": "will_alert",
// Refers to an exported function
"change": "will_alert_change"
}
}
},
"libs": {
// Import the Utils library
"utils": true
},
"config": {
"will_alert": true
}
}
};
// destructure
const { config, gui, libs } = metadata.features;
libs.utils.add_ele('style', () => document.head, {
textContent: '* { color: red !IMPORTANT; }',
});
if(config.will_alert){
console.log('Will alert on GUI update');
}
export function will_alert_change(value, init){
if(value && init)alert('Updated. Hi');
else alert('Changed will alert to: ' + value);
}| Feature | Effect | Description |
|---|---|---|
gui |
Script load | An object organized by category->controls
|
utils |
Script load | An object including libraries to import |
config |
Script load | An object containing a default config. |
block_hosts |
Page load | An array of strings containing hosts to block |
command_line |
Client launch | An array of command-line flags |
- Written to by the GUI
-
features.configalways returns the latest version - Script author will be used as the key in
config->userscripts
The above demo will result in config.json looking like:
{
"userscripts": {
"Chief Software": {
"will_alert": true
},
},
}