Skip to content

Instantly share code, notes, and snippets.

@sina-salahshour
Created October 3, 2026 10:28
Show Gist options
  • Select an option

  • Save sina-salahshour/1f0628b3a8baf04e7bc219b6093f3d14 to your computer and use it in GitHub Desktop.

Select an option

Save sina-salahshour/1f0628b3a8baf04e7bc219b6093f3d14 to your computer and use it in GitHub Desktop.
Bitburner auto hacknet upgrade
(() => {
clearInterval(window.__hacknetBot);
const RESERVE = 0; // money to always keep, e.g. 1e6 to keep $1m
const INTERVAL_MS = 200; // how often to check
const SUF = { '': 1, k: 1e3, m: 1e6, b: 1e9, t: 1e12, q: 1e15, Q: 1e18, s: 1e21, S: 1e24, o: 1e27, n: 1e30 };
const parse = (t) => {
const m = t.replace(/,/g, '').match(/\$\s*(-?[\d.]+(?:e[+-]?\d+)?)\s*([kmbtqQsSon]?)/);
return m ? parseFloat(m[1]) * SUF[m[2]] : NaN;
};
const getMoney = () => {
const cell = [...document.querySelectorAll('th,td,p,span')].find((e) => e.textContent.trim() === 'Money');
return parse(cell?.closest('tr')?.textContent || '');
};
const label = (b) => {
const kind = b.closest('tr')?.textContent.match(/^(Level|RAM|Cores)/)?.[1] || '';
for (let el = b.parentElement; el; el = el.parentElement) {
const names = el.textContent.match(/hacknet-node-\d+/g);
if (names) return names.length === 1 ? `${names[0]} ${kind}` : 'new node';
}
return 'new node';
};
// all buy buttons, sorted cheapest first
const getButtons = () =>
[...document.querySelectorAll('button')]
.filter((b) => !b.disabled && /^(Purchase Hacknet Node|\+\d+)\s*-\s*\$/.test(b.textContent.replace(/\s+/g, ' ').trim()))
.map((b) => ({ b, cost: parse(b.textContent) }))
.filter((x) => !isNaN(x.cost))
.sort((a, b) => a.cost - b.cost);
const tick = () => {
const money = getMoney();
const opts = getButtons();
if (isNaN(money) || !opts.length) return; // not on Hacknet page
const best = opts[0];
if (best.cost <= money - RESERVE) {
console.log(`[hacknet] ${label(best.b)}: ${best.b.textContent.replace(/\s+/g, ' ').trim()}`);
best.b.click();
}
};
window.__hacknetBot = setInterval(tick, INTERVAL_MS);
window.stopHacknet = () => { clearInterval(window.__hacknetBot); console.log('[hacknet] stopped'); };
console.log('[hacknet] started — stopHacknet() to stop');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment