spellDurations = {
"mana": 120,
"minor mana": 30,
"lesser mana": 60,
"whisper": 50,
"unseen servant": 45,
"insight": 60,
"dark promptings": 60,
"wind sense": 60,
"water sense": 60,
"fire sense": 60,
"wild growth": 45,
"abundance": 60,
"fount": 60,
"minor fount": 30,
"calming murmurs": 45,
"soothing breeze": 45,
"magnificence": 60,
"true strike": 45,
"guided strike": 45,
"perfect strike": 45,
"pulsing light": 45,
"pulsing light II": 60,
"poison ward": 30,
"protection: shadow": 20,
"protection: light": 20,
"protection: water": 20,
"protection: nature": 20,
"protection: fire": 20,
"quenchingsphere": 20,
"stone skin": 50,
"copper skin": 30,
"iron skin": 60,
"steel skin": 120,
"adamant shell": 180,
"dust devil": 20,
"dust devil II": 45,
"whirling step": 45,
"whirling step II": 60,
"whirling step III": 80
}
spellDelays = {};
spellCastHandlers={};
Object.entries(spellDurations).forEach(e=>spellDelays[e[0]]=Math.floor(Math.random()*5*spellDurations[e[0]]));
spellWait=(s=>((spellDelays[s]+Math.floor(Date.now()/100))%(spellDurations[s]*5))/10);
getNodes=((p,s)=>Array.from(p.querySelectorAll(s)));
getNode=((p,s,c)=>getNodes(p,s).find(n=>n.textContent.toLowerCase()==c.toLowerCase()));
autoclickTimer=setInterval(_=>autoclickButtons.forEach(b=>{b.disabled=0;b.click.apply(b)}),100);
autoclickButtons=[];
autoclick = ((s, c) => autoclickButtons.push(getNode(document,s,c)));
[
"scribe scroll", "bind codex", "purchase gem", "imbue lifegem",
"imbue gem (arcane)", "coagulate gem", "imbue gem (fire)", "imbue gem (air)",
"imbue stone", "imbue gem (water)", "imbue gem (light)", "imbue gem (shadow)",
"imbue gem (spirit)", "focus"
//, "craft rune", "map stars", "compile tome", "craft gem"
].forEach(b=>autoclick("button", b));
focusTab=(l=>{try{getNode(document,"u"," "+l+" ").click()}catch{}});
focusTab("spells");
spellbookLoadTimer = setInterval(_ => {
var spellbook = document.querySelector(".spellbook");
if (!spellbook) { return; }
getNodes(spellbook,"tr").filter(n=>getNode(n,"button","Cast")).forEach(n=>
spellCastHandlers[Array.from(n.children).find(c=>c.firstChild.nodeValue).textContent]=
(b=>b.click.bind(b))(getNode(n,"button","Cast")));
spellTimer=setInterval(_=>autocastSpells.forEach(s=>!spellWait(s)&&spellCastHandlers[s]()),100);
focusTab("equip");
equipLoadTimer = setInterval(_ => {
if (!document.querySelector(".inv-equip")) { return; }
appletimer = setInterval((b => (_ => ((a => a[1]-a[0])(document.querySelector("div.stamina").innerText.split("/")) > 10 && b.click())))(getNodes(document, "tr").find(n => n.innerText.match(/apple/)).querySelector("button")), 1000)
clearInterval(equipLoadTimer);
}, 100);
clearInterval(spellbookLoadTimer);
}, 100);
autocastSpells = [ "mana", "lesser mana", "minor mana" ];