underscript.utils
Helpers that UnderScript uses itself.
Syntax
underscript.utils;
General
- each(object, callback), some(object, callback)
- Loop over an array, or the keys of an object, like
forEachandsome - sleep(ms, value)
- A promise that waits, then resolves with
value - shuffle(array)
- Shuffle an array
- rand(max, min, inclusive)
- A random whole number
- notify(text, title)
- Show a desktop notification
- translateText(text, { args, fallback, locale })
- Translate a game text key, filling in
args.localetranslates as a specific language.
The page
- global(…keys)
- Read variables from the game’s page. Pass
{ throws: false }last to getundefinedinstead of an error. - globalSet(key, value)
- Replace a variable or function on the game’s page. A replaced function can call the original with
this.super(). - hover
- Tooltips.
hover.tip(text, target, options)adds a tooltip to elements,hover.show(data)andhover.hide()show or hide one by hand.
Building things
- eventEmitter()
- Create an EventEmitter
- Hotkey, mouse
- See plugin.hotkey
- SettingType
- Make your own type of setting for plugin.settings().addType()
- tabManager()
- Build a page of tabs.
addTab(name, content)adds one andrender(true)gives you the element to put on the page. Tabs that don’t fit on one row split into pages with arrows.settings({ labels, tooltip })changes the text of the arrows’ tooltips (labels.previous(page, total),labels.next(page, total)), or setstooltiptounderscript.utils.hoverto use UnderScript’s hover instead of a plaintitle. - VarStore
- Holds a value.
consume()reads it and puts the default back. - rarity
max(rarity),cost(rarity, shiny)anddust(rarity, shiny)for card rarities. A rarity is its name, like'EPIC', or anunderscript.rarity.
Examples
const { sleep, rand } = underscript.utils;
sleep(1000).then(() => console.log(rand(10)));