Skip to content

Instantly share code, notes, and snippets.

@Summertime
Last active March 10, 2022 07:57
Show Gist options
  • Save Summertime/454c81159a96bebc23e53f1252d81eff to your computer and use it in GitHub Desktop.
Save Summertime/454c81159a96bebc23e53f1252d81eff to your computer and use it in GitHub Desktop.
bitburner stuff
const filters = [
/^Running script with [0-9]+ thread\(s\), pid [0-9]+ and args/,
]
function findProp(propName) {
// stolen from talamond
for (let div of eval("document").querySelectorAll("div")) {
let propKey = Object.keys(div)[1];
if (!propKey)
continue;
let props = div[propKey];
if (props.children?.props?.[propName])
return props.children.props[propName];
if (props.children instanceof Array)
for (let child of props.children)
if (child?.props?.[propName])
return child.props[propName];
}
}
/** @param {NS} ns **/
export async function main(ns) {
term = findProp('terminal')
term.print_ ??= term.print
term.print = p => {
if (filters.some(f=>f.test(p)))
return
term.print_(p)
}
}
const NAMESPACE = 'dYsi'
const STORAGE = eval('window.localStorage')
const vars = new Proxy({}, {
get(target, P, reciever) {
return JSON.parse(STORAGE.getItem(NAMESPACE + P))
},
set(target, P, V, reciever) {
STORAGE.setItem(NAMESPACE + P, JSON.stringify(V))
return true
},
deleteProperty(target, P) {
STORAGE.removeItem(NAMESPACE + P)
return true
}
})
export default vars;
/** @param {NS} ns **/
export async function main(ns) {
const args = [...ns.args]
if (args[0] == 'set')
vars[args[1]] = JSON.parse(""+args[2])
if (args[0] == 'get')
ns.tprintf('%s\n', vars[args[1]])
if (args[0] == 'del')
delete vars[args[1]]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment