Last active
November 14, 2018 01:52
-
-
Save likuilin/3e683b5f207162d3c1976b3e10c56dd6 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 Transfer Helper | |
// @version 0.1 | |
// @author kuilin | |
// @match http*://*.pardus.at/ship2ship_transfer.php* | |
// @updateURL https://gist.github.com/likuilin/3e683b5f207162d3c1976b3e10c56dd6/raw/s2s_transfer_name_title.user.js | |
// @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 = ' <input type="reset" onclick="scriptReload()" value="Reload" /><span id="errorDiv" style="color: red;font-weight: bold;"></span>'; | |
btn.parentNode.insertBefore(newBtn, btn.nextSibling); | |
window.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>Error: 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(); | |
} | |
} | |
loadScript(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment