Created
January 4, 2019 00:49
-
-
Save likuilin/786cde5a2e83c6c5ac368779debc0bbe 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 Pardus Ship2Ship Bot-Key | |
// @version 0.1 | |
// @author kuilin | |
// @match http*://*.pardus.at/ship2ship_transfer.php* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
let loadScript = function () { | |
//put name in title | |
document.title = document.getElementsByTagName("br")[5].parentNode.textContent.trim().split("\n").pop().split(/ has \d+t of free space./g)[0]; | |
//no-nav-bounce reload button | |
let url = window.location.origin + window.location.pathname + "?playerid=" + document.querySelector('input[name="playerid"]').value; | |
let btn = document.querySelector('input[value="Transfer"]'); | |
let newBtn = document.createElement('span'); | |
newBtn.innerHTML = ' <span id="errorDiv" style="color: red;font-weight: bold;"></span>'; | |
btn.parentNode.insertBefore(newBtn, btn.nextSibling); | |
let scriptReload = function () { | |
let xhr = new XMLHttpRequest(); | |
xhr.onreadystatechange = function () { | |
if (xhr.readyState != 4) return; | |
let response = xhr.responseText; | |
//if we're back on the nav screen, or elsewhere... stop and error | |
if (!response.includes("<form action='ship2ship_transfer.php' method='post' id='ship2ship_transfer'>")) { | |
document.getElementById("errorDiv").innerHTML = "<br><br>Target is not on current tile."; | |
return; | |
} | |
//this is one of the very few times this is actually appropriate | |
document.write(response); | |
document.close(); | |
setTimeout(loadScript, 100); | |
} | |
xhr.open('GET', url); | |
xhr.send(); | |
} | |
document.addEventListener("keypress", e=>{ | |
if (e.key == " ") { | |
eval(document.querySelector('a[href*="res_8"]').href.split(":")[1]); | |
document.querySelector('input[value="Transfer"]').click(); | |
} else if (e.key == "r") { | |
console.log("asdf"); | |
scriptReload(); | |
} | |
}, false); | |
} | |
loadScript(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment