NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name WF horizontal fleet direction // @namespace sk.seko // @description Displays horizontal fleet direction ("o'clock"); for new UI // @include http://*.war-facts.com/fleet.php* // @version 1.1 // @grant none // ==/UserScript== // Version 1.0 = Initial version // Version 1.1 = fixed (removed) forgotten alert dialog var globalRegex = /^\s*(\-*\d+)[,\s]+(\-*\d+)[,\s]+(\-*\d+)/ function parse_xyz(s) { return s.match(globalRegex); } function rad2deg(angle) { return angle * 57.29577951308232; // angle / Math.PI * 180 } function clock(p1, p2) { var dx = p2[1] - p1[1] var dy = p2[2] - p1[2] var dxy = Math.round(4000* Math.sqrt(dx*dx + dy*dy)); if (dxy > 0) { horiz = Math.round((rad2deg(Math.atan2(-dy, dx)) - 90 + 180) / 360 * 12); if (horiz < 0) { horiz += 12; } else if (horiz < 1) { horiz = 12; } return horiz; } else { return '-'; } } function later() { // table title element var pos1 = document.evaluate("//div[@id='navData']/div[2]/div[2]/div[last()]/a/text()", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; var pos2 = document.evaluate("//div[@id='mCoordinates']/a[last()]/text()", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; if (pos2 == null) { setTimeout(later, 1000) } else { if (pos1.textContent.indexOf(" global") > -1 && pos2.textContent.indexOf(" global") > -1) { var eta = document.evaluate("//span[@id='mEta']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; t1 = parse_xyz(pos1.textContent); t2 = parse_xyz(pos2.textContent); c = clock(t1, t2) eta.appendChild(document.createTextNode(', H.dir: ' + c + " o'clock")); } } } setTimeout(later, 1000)