Skip to content

User Script API Reference

  • API level: 1 (StarX.apiLevel)
  • Language: Rhino ES6 (Context.VERSION_ES6), optimization level -1 (interpreted only, no bytecode generation)
  • Each script gets its own global scope, with StarX, console, setTimeout, setInterval, clearTimeout and clearInterval installed

Integer, currently 1.

Module version string, for example 1.5.4.

Metadata of this script, available after load:

{
id: 'my_script',
name: 'My script',
namespace: 'local',
version: '1.0.0',
description: 'description',
author: 'you',
scopes: ['exam', 'work'],
matches: [],
runAt: 'document-end',
env: 'native'
}
{
sdkInt: 36,
packageName: 'com.chaoxing.mobile',
processName: 'com.chaoxing.mobile',
isMainProcess: true,
appVersionName: '7.0.4',
appVersionCode: 700004,
moduleVersion: '1.5.4',
hookApiAvailable: true,
onMainThread: true
}
MethodDescription
StarX.now()Millisecond timestamp
StarX.random()Random number in [0, 1)
StarX.sleep(ms)Blocks the script thread, capped at 120000 ms
StarX.toast(msg)Shows a toast (subject to the module toast switch)
StarX.dump(value)Converts any value to a string / JSON text for debugging
StarX.log(...)Writes a log line, same as StarX.console.log

StarX.console provides log / info / warn / error / debug, all written to scripts/logs/<id>.log and logcat.

var id = StarX.setTimeout(fn, ms);
var id = StarX.setInterval(fn, ms);
StarX.clearTimeout(id);
StarX.clearInterval(id);

Timers run on the script’s own executor thread and are cleared when the script is disabled or reloaded.

Per-script key/value storage persisted at scripts/data/<id>.json.

MethodDescription
get(key, def)Reads a string, returns def when absent
set(key, value)Stores a value (non-strings are stringified)
getJson(key, def)Reads and JSON.parses
setJson(key, value)JSON.stringify then store
remove(key)Removes one key
keys()Array of all keys
clear()Clears everything
var r = StarX.http.request({
url: 'https://example.com/api',
method: 'POST', // default GET
body: 'a=1&b=2', // string; JSON.stringify objects yourself
headers: { 'X-Token': 'x' },
timeout: 15000 // milliseconds, 1000..60000
});
// success: r = { ok: true, status: 200, body: '...', headers: { ... } }
// failure: r = { ok: false, status: 0, body: '', error: '...' }
  • Shorthands: StarX.http.get(url, headers) and StarX.http.post(url, body, headers).
  • Default User-Agent is Mozilla/5.0 (Linux; Android <release>; StarX/<module version>).
  • No host cookies are attached; pass what you need in headers.
MethodDescription
get()Reads clipboard text
set(text)Writes clipboard text
MethodReturns
isConfigured()Boolean, whether the module has a usable AI configuration
ask(question, type, options)String or null
askImage(base64, mime)String or null
ocr(base64, mime)String or null
  • type uses the question type codes, default -1.
  • options may be a string, array or object (serialized to JSON before reaching the model).
  • Without an AI configuration everything returns null and nothing throws.

StarX.tiku.query(question, type, options) returns a string or null. Queries the third-party question bank.

StarX.answer.query(question, type, options, images) returns { answer, source } or null.

  • Uses the same pipeline as the module itself (question bank first, AI as fallback).
  • images is an array of base64 strings and may be omitted.
  • Internally times out after 20 seconds and blocks the calling thread; calling it inside a question callback slows that question down.
MethodDescription
last()Payload of the most recent question event, may be null
publish(payload)Manually broadcasts a question to all global scripts
answer(value)Answers inside a question callback, returns true / false

answer normalization: strings are used as-is; numbers and booleans are stringified; arrays whose elements are all single characters join into AC, otherwise they join with commas.

Requires framework API 102 or newer; check with StarX.hook.available().

if (StarX.hook.available()) {
var id = StarX.hook.method('com.example.Foo', 'bar', {
arity: 1, // parameter count, -1 for any
before: function (ctx) {
ctx.args[0] = 'replaced'; // change arguments
// ctx.skip = true; // skip the original method
// ctx.result = 'fake'; // used with skip as the return value
},
after: function (ctx) {
return ctx.result + '!'; // returning non-undefined replaces the result
}
});
StarX.hook.unhook(id);
}

Interceptor context:

{
method: 'bar',
class: 'com.example.Foo',
args: [ ... ],
this: <instance>,
result: <only during after>
}
  • Returns a handleId string; null when the class or method is missing, or when framework API < 102.
  • Both callbacks must return synchronously and run on the thread where the interception happens.
  • All registered hooks are removed when the script is disposed, reloaded or disabled.

Also available: StarX.hook.classExists(name) and StarX.hook.unhookAll().

MethodDescription
list()Array of tracked WebView URLs
inject(js)Injects JS into live WebViews, returns how many were injected
StarX.on(name, fn); // subscribe, returns the callback
StarX.off(name, fn); // unsubscribe; without fn it clears the event
StarX.emit(name, payload); // broadcast to other scripts (not back to yourself)

Callback signature: fn(payload, eventName, fromId).

Framework events, their payloads and timing are documented in the User Script Guide section 6.

  • Every failing API call returns null / false instead of throwing into the script.
  • An exception in an event callback logs event <name> handler failed: <msg> and other callbacks keep running.
  • An exception during script load marks that script as failed and shows the error on its card.
  • StarX.apiLevel lets scripts probe capabilities; the level only increases.
  • New APIs do not change existing semantics; breaking changes bump apiLevel.