Last active
June 1, 2020 21:11
-
-
Save necrogami/a10a76f03fc0b8efa40d1e1e4698d796 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Shilla Movement | |
// @namespace https://gist.githubusercontent.com/necrogami/a10a76f03fc0b8efa40d1e1e4698d796/raw/shilla.user.js | |
// @version 0.3.0 | |
// @description try to take over the world! | |
// @author Necrogami/Warlock | |
// @match http://shilla.club/Game/* | |
// @grant GM_addStyle | |
// @require http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js | |
// ==/UserScript== | |
var $ = window.jQuery | |
var link = undefined; | |
let noAttack = [ | |
'Town Guard', | |
]; | |
function _x(STR_XPATH) { | |
var xresult = document.evaluate(STR_XPATH, document, null, XPathResult.ANY_TYPE, null); | |
var xnodes = []; | |
var xres; | |
while (xres = xresult.iterateNext()) { | |
xnodes.push(xres); | |
} | |
return xnodes; | |
} | |
function moveOld(direction) { | |
link = $('a').filter(function () { | |
return this.innerHTML == direction; | |
}).attr('href'); | |
if (typeof link !== "undefined") { | |
window.location.href = link; | |
} | |
} | |
function moveNew(direction) { | |
$('.movementButton').filter(function () { | |
return this.innerHTML == direction; | |
}).click(); | |
} | |
function xpathLink(xlink) { | |
link = $(_x(xlink)).attr('href'); | |
if (typeof link !== "undefined") { | |
window.location.href = link; | |
} | |
} | |
(function () { | |
'use strict'; | |
// Attack | |
$(document).on('keypress', function (e) { | |
switch (e.which) { | |
// Numpad * key | |
// Pickup First Stack | |
case 42: | |
xpathLink('//*[@id="main_world"]/a[2]'); | |
break; | |
// Numpad + key | |
case 43: | |
moveOld('Up'); | |
moveNew('↑'); | |
break; | |
// Numpad - key | |
case 45: | |
moveOld('Down'); | |
moveNew('↓'); | |
break; | |
// Numpad . key | |
// Pickup First Item (1 Item Only) | |
case 46: | |
xpathLink('//*[@id="main_world"]/a'); | |
break; | |
// Numpad 0 key | |
case 48: | |
var name1 = $.inArray($(_x('//*[@id="main_world"]/table/tbody/tr/td[1]/table/tbody/tr[1]/td/b/center')).text(), noAttack); | |
var name2 = $.inArray($(_x('//*[@id="main_world"]/table/tbody/tr[1]/td/b/center')).text(), noAttack); | |
//alert(name1 + name2); | |
if ((name1 + name2) !== 0) { | |
$(_x('//*[@id="attack"]')).click(); | |
} else { | |
alert('You\'ve disabled attacking this creature.'); | |
} | |
break; | |
// Numpad 1 key | |
case 49: | |
moveOld('Southwest'); | |
moveNew('S/W'); | |
break; | |
// Numpad 2 key | |
case 50: | |
moveOld('South'); | |
moveNew('South'); | |
break; | |
// Numpad 3 key | |
case 51: | |
moveOld('Southeast'); | |
moveNew('S/E'); | |
break; | |
// Numpad 4 key | |
case 52: | |
moveOld('West'); | |
moveNew('West'); | |
break; | |
// Numpad 6 key | |
case 54: | |
moveOld('East'); | |
moveNew('East'); | |
break; | |
// Numpad 7 key | |
case 55: | |
moveOld('Northwest'); | |
moveNew('N/W'); | |
break; | |
// Numpad 8 key | |
case 56: | |
moveOld('North'); | |
moveNew('North'); | |
break; | |
// Numpad 9 key | |
case 57: | |
moveOld('Northeast'); | |
moveNew('N/E'); | |
break; | |
// Everything else | |
default: | |
break; | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment