Skip to content

Instantly share code, notes, and snippets.

@lambda-fairy
Created June 26, 2012 06:44
Show Gist options
  • Save lambda-fairy/2993862 to your computer and use it in GitHub Desktop.
Save lambda-fairy/2993862 to your computer and use it in GitHub Desktop.
KoL auto-adventure script
javascript:
var frm = window.frames[2];
function next(f) {
setTimeout(f, 100);
}
function doClick(elem) {
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
elem.dispatchEvent(evt);
}
function goTo(page, text, f) {
console.log('Going to ' + page);
frm.location.replace(page);
waitFor(text, f);
}
function waitFor(text, f) {
function loop() {
try {
if (frm.document.body.innerHTML.search(text) >= 0) {
f(); return;
}
} catch(e) {
console.log(e);
}
next(loop);
}
next(loop);
}
function fight() {
goTo('http://www.kingdomofloathing.com/adventure.php?snarfblat=293', 'repeat.gif', function() {
var bar = frm.document.getElementsByClassName('blueback')[0];
var img = bar.childNodes[13].childNodes[0];
var src = img.getAttribute('src');
doClick(img);
waitFor('advagain.gif', heal);
});
}
function heal() {
goTo('http://www.kingdomofloathing.com/campground.php?action=rest', 'Back to the Main Map', function() {
next(fight);
});
}
next(fight);
void 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment