Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getQuery(name) {
- name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
- var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
- results = regex.exec(location.search);
- return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
- }
- function getQueryFromHaystack(haystack, name) {
- name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
- var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
- results = regex.exec(haystack);
- return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
- }
- function getXML() {
- if (xmlConfig === undefined) {
- if (window.XMLHttpRequest) {
- xmlhttp = new XMLHttpRequest();
- } else {
- xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
- }
- xmlhttp.open("GET", window.location.protocol + "//" + window.location.host + "/interface.php?func=get_config", false);
- xmlhttp.send();
- xmlConfig = xmlhttp.responseXML;
- }
- return xmlConfig;
- }
- function getWorldSpeed() {
- return parseFloat(getXML().getElementsByTagName("speed")[0].childNodes[0].nodeValue);
- }
- function getUnitSpeed() {
- return parseFloat(getXML().getElementsByTagName("unit_speed")[0].childNodes[0].nodeValue);
- }
- var xmlConfig;
- var speed = [[9, "Scout"], [10, "LC"], [11, "HC"], [18, "Axe"], [22, "Sword"], [30, "Ram"], [35, "Noble"]];
- var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
- function main(doc, href) {
- if (getQueryFromHaystack(href, "mode") === "incomings" && getQueryFromHaystack(href, "screen") === "overview_villages") {
- $("#incomings_table .row_a, #incomings_table .row_b", doc).each(function() {
- $.ajax($($("a", this).get(0)).attr("href"), {
- context: $($("a", this).get(0)),
- complete: function(jqXHR, textStatus){
- if (textStatus === "success"){
- var doca = $("<div></div>");
- doca.get(0).id = "NAIT";
- a = jqXHR.responseText;
- b = this.attr("href");
- doca.html(jqXHR.responseText);
- var name = main(doca, this.attr("href"));
- this.html(name);
- }
- }
- });
- });
- } else if (getQueryFromHaystack(href, "screen") === "info_command") {
- var data = {};
- var table = $("#content_value table", doc);
- data["origin_player"] = $($("tr:has(td:contains('Origin')) td", table).get(2)).text();
- data["origin_village"] = $($("tr:has(td:contains('Village')) td", table).get(1)).text().split("(")[1].split(")")[0];
- data["dest_player"] = $($("tr:has(td:contains('Destination')) td", table).get(2)).text();
- data["dest_village"] = $($("tr:has(td:contains('Village')) td", table).get(3)).text().split("(")[1].split(")")[0];
- data["time_left"] = $($("tr:has(td:contains('Arrival in')) td", table).get(1)).text();
- time = data["time_left"].split(":");
- var seconds = parseInt(time[time.length-1]),
- minutes = parseInt(time[time.length-2]),
- hours = parseInt(time[time.length-3]);
- data["seconds_left"] = (hours * 3600) + (minutes * 60) + seconds;
- data["distance"] = Math.floor(Math.sqrt(Math.pow(data["origin_village"].split("|")[0] - data["dest_village"].split("|")[0], 2) + Math.pow(data["origin_village"].split("|")[1] - data["dest_village"].split("|")[1], 2)) * 100 + 0.5) / 100;
- data["time_arrival"] = $($("tr:has(td:contains('Arrival:')) td", table).get(1)).text();
- data["slowest_unit"] = "";
- var nextThing = true;
- for (var i=0; i<speed.length; i++){
- var secondsForUnit = speed[i][0] / (getWorldSpeed() * getUnitSpeed()) * 60;
- if (data["seconds_left"] <= secondsForUnit && nextThing){
- data["slowest_unit"] = speed[i][1];
- data["time_sent"] = new Date((new Date(data["time_arrival"].replace(/\:\d{3}/, ""))) - (speed[i][0] / (getWorldSpeed() * getUnitSpeed()) * 60000));
- timeBack = (new Date(new Date(data["time_arrival"]) + (speed[i][0] / (getWorldSpeed() * getUnitSpeed()) * 60000))).toLocaleString();
- data["time_back"] = months[timeBack.getMonth()] + " " + timeBack.getDate() + " " + timeBack.getFullYear() + " " + (timeBack.getHours() < 10 ? "0" + timeBack.getHours() : timeBack.getHours()) + ":" + (timeBack.getMinutes() < 10 ? "0" + timeBack.getMinutes() : timeBack.getMinutes()) + ":" + (timeBack.getSeconds() < 10 ? "0" + timeBack.getSeconds() : timeBack.getSeconds());
- nextThing = false;
- }
- }
- var name = format;
- name = name.replace(/\{SlowestUnit\}/g, data["slowest_unit"]);
- name = name.replace(/\{AttackingPlayer\}/g, data["origin_player"]);
- name = name.replace(/\{AttackingVil\}/g, data["origin_village"]);
- name = name.replace(/\{DefendingPlayer\}/g, data["dest_player"]);
- name = name.replace(/\{DefendingVil\}/g, data["dest_village"]);
- name = name.replace(/\{SecondsLeft\}/g, data["seconds_left"]);
- name = name.replace(/\{SentTime\}/g, data["time_sent"]);
- name = name.replace(/\{BackTime\}/g, data["time_back"]);
- $("th .quickedit .rename-icon", table).click();
- setTimeout(function(){ $("th .quickedit input[type='text']", table).val(name); setTimeout(function(){ $("th .quickedit input[type='button']", table).click(); }, 250); }, 100);
- return name;
- }
- }
- main(document, window.location.href);
Advertisement
Add Comment
Please, Sign In to add comment