Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const doc = eval('document')
- /** @param {import(".").NS} ns */
- export async function main (ns) {
- ns.tail()
- if (ns.getPlayer().city != 'Aevum') {
- if (!ns.travelToCity('Aevum')) { return ns.tprint('ERROR: Sorry, you need at least 200k to travel.') }
- }
- getCity().click()
- let canceled = false
- const cancelHook = function() {
- const btn = [...doc.getElementsByTagName('button')].find(e => e.innerText === 'Cancel')
- if (!btn) {
- return
- }
- const oldFn = btn.onclick
- btn.onclick = () => { canceled = true; oldFn() }
- }
- while (!canceled) {
- let fail = false
- getEcorp().click()
- clickUntrusted('Infil')
- // clickUntrusted("Start");
- console.log('***************************************************************Started')
- while (!infiltrationComplete()) {
- await ns.asleep(1000)
- cancelHook()
- if (getEcorp()) {
- // booted to city!
- fail = true
- break
- }
- console.log('***************************************************************Waiting')
- }
- if (fail) {
- continue
- }
- // clickUntrusted("Sell");
- console.log('***************************************************************Sell')
- getButton('Sell').click()
- await ns.sleep(1000)
- }
- }
- function getCity () {
- for (const elem of doc.querySelectorAll('p')) {
- if (elem.textContent == 'City') {
- return elem
- }
- }
- }
- function getEcorp () {
- return doc.querySelector('[aria-label="ECorp"]')
- }
- function getButton (text) {
- for (const elem of doc.querySelectorAll('button')) {
- if (elem.textContent.toLowerCase().includes(text.toLowerCase())) {
- return elem
- }
- }
- }
- function clickUntrusted (text) {
- const button = getButton(text)
- const handler = Object.keys(button)[1]
- button[handler].onClick({ isTrusted: true })
- }
- function infiltrationComplete () {
- return [...doc.querySelectorAll('h4')].some(e => e.innerText === 'Infiltration successful!')
- }
Add Comment
Please, Sign In to add comment