NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript==
// @name WF2 Show fleet direction
// @namespace sk.seko
// @description Displays horizontal & vertical fleet direction ("o'clock")
// @updateURL https://openuserjs.org/meta/rsenderak/wf2-fleet-helper.meta.js
// @downloadURL https://openuserjs.org/install/rsenderak/wf2-fleet-helper.user.js
// @license MIT
// @match https://*.atmoburn.com/fleet.php*
// @match https://*.atmoburn.com/fleet/*
// @version 4.1.2
// @grant none
// ==/UserScript==
// Version 1.0 = Initial version
// Version 1.1 = fixed (removed) forgotten alert dialog
// Version 1.2 = Fixed @include after server protocol change from http to https
// Version 2.0 = Fixed for new WF (WF2); added vertical direction in degrees
// Version 3.0 = Atmoburn
// Version 3.1 = Fixed include
// Version 4.1 = Tweaks & fixes
// Version 4.1.1 = esversion set to 11
// Version 4.1.2 = small visual fix
/* jshint esversion: 11 */
/* jshint node: true */
"use strict";
var globalRegex = /^\s*(\-*\d+)[,\s]+(\-*\d+)[,\s]+(\-*\d+)/;
function xlog(msg) {
console.log(`WF2SFD: ${msg}`);
}
function parse_xyz(s) {
return s.match(globalRegex);
}
function rad2deg(angle) {
return angle * 57.29577951308232; // angle / Math.PI * 180
}
function clock(p1, p2) {
const dx = p2[1] - p1[1];
const dy = p2[2] - p1[2];
if (dx == 0 && dy == 0) {
return '-';
}
var 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;
}
function vert(p1, p2) {
const dz = p2[3] - p1[3];
if (dz == 0) {
return 0;
}
const dx = p2[1] - p1[1];
const dy = p2[2] - p1[2];
const dxy = Math.round(Math.sqrt(dx*dx + dy*dy));
if (dxy == 0) {
return dz > 0 ? 90 : -90;
}
let vert = Math.round(rad2deg(Math.atan2(dz, dxy)));
if (vert < -90) {
vert = -180 - vert;
} else if (vert > 90) {
vert = 180 - vert;
}
return vert;
}
function showIt() {
//xlog("showIt " + ignoreNext);
if (ignoreNext) {
ignoreNext = false;
return;
}
const p2 = document.evaluate("//div[@id='missionPosition']//a/text()[contains(.,' global')]",
document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if (!p2 || !p2.textContent || p2.textContent.indexOf(" global") < 0) {
return;
}
const p1 = document.evaluate("//div[@id='navData']//div[@id='positionRight']//a/text()[contains(.,' global')]",
document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if (!p1 || !p1.textContent || p1.textContent.indexOf(" global") < 0) {
return;
}
const t1 = parse_xyz(p1.textContent);
const t2 = parse_xyz(p2.textContent);
const c = clock(t1, t2);
const v = vert (t1, t2);
const elem = document.createElement('span');
const bs = " "; // big HTML space
elem.innerHTML=`${bs}[<big>${c}′</big><small>${bs}${v}º</small>]`;
elem.style.color = "yellow";
elem.title = "Horizontal direction (in o'clock notation), and vertical direction (in degrees)";
ignoreNext = true;
eta.appendChild(elem);
}
var ignoreNext = false;
var eta = document.getElementById('mEta');
new MutationObserver(showIt).observe(eta, { attributes: false, childList: true, subtree: true });