How to run brainaid’s NMEA proxy from the Sailonline client

Brainaid’s NMEA proxy java applet is a thing of beauty, it truly is. But getting it to run is a bit of a hassle. First you have go to his site, you have to enter your credentials and select a race to be able to log in before you’re finally able to get on to the navigation page where it sits waiting for you to run it. Is there no way to make this any easier?

I’m glad you asked. Sure there is. Short version: you install a browser extension that executes a script while loading the Sailonline client, adding at the page bottom a button that will get the NMEA applet for you. Easy, huh?

Well, let’s get to the nitty gritty:

Firefox:
Install Greasemonkey from https://addons.mozilla.org/en/firefox/addon/greasemonkey/. After installation, the Firefox toolbar will Greasemonkey have been fitted with a new image button/dropdown button pair. Click on the dropdown button and scroll down to the New user script… option. The New User Script dialog window will appear. Enter a name for the script, for example ProxyStart, as well as a namespace name in the Name and Namespace fields, respectively. New user script windowRemove any and all text that may have been automatically added to the Include (one per line) (most likely the web address of the page you’re currently viewing) and Exclude (one per line) (most likely none), and click Ok.

At this point, a Script Editor will automatically appear. Copy the script below and paste it into the editor:

/// ==UserScript==
// @name ProxyStart
// @description Runs brainaid's NMEA proxy from the SOL client page
// @include http://www.sailonline.org/windy/run/*
// @include http://sailonline.org/windy/run/*
// @namespace Schakel
// @version 1
// @grant none
// ==/UserScript==

var myNode       = document.createElement ('div');
myNode.innerHTML = '' + 'Run NMEA proxy!';

myNode.setAttribute ('id', 'myContainer');
document.body.appendChild (myNode);

//--- Activate the new button.
document.getElementById ("myButton").addEventListener (
    "click", ButtonClickAction, false );


// Retrieve token, race-id, and boatname
function ButtonClickAction (zEvent) {
  
  var token = String(getToken());
  var raceID = String( getRaceID() );
  var boatName = String(prompt("Enter your boatname: ", ""));
  
  window.open(getProxyURL(token, raceID, boatName), '_blank');
}

// Build the url from it
function getProxyURL(aToken, aRace, aBoat) {
  var fullURL = String("sol.brainaid.de/sailonline/toolbox/NMEAproxy.jnlp?sid=" +
                          aToken +
                          "&race=" +
                          aRace +
                          "&boat=" +
                          aBoat +
                          "&file=NMEAproxy.jnlp");
  return("http://" + fullURL);
}

Notice the @namespace Schakel definition near the top and change it to match the namespace you entered earlier. Also, notice the @include http://www.sailonline.org/windy/run/* and @include http://sailonline.org/windy/run/* definitions which tell the Greasemonkey on which pages to run this script. Save the script under any name and close the editor.

After making sure Greasemonkey is running and the script is enabled (click the dropdown button and scroll down to Manage user scripts),Run NMEA Proxy button you can go to any Sailonline race and find a button underneath the race client window, as shown here. Enter boat nameClicking it will open a dialog window asking you to enter your boat name. Next, Firefox’ familiar Open/Save file dialog window will appear and you can proceed to run or download brainiad’s NMEA proxy applet as you would.Firefox open/save dialog

Chrome:
Install the Chrome extension Tampermonkey from https://chrome.google.com/webstore/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo. TampermonkeyAs before in Firefox, a new button is added to Chrome’s toolbar. Click the button to open a menu and select the Add a new script… menu option. Tampermonkey will now take you straight to the script editor. Copy and paste the script again and save the script by clicking on the floppy disk icon.
tampermonkeyeditor
I recommend you first check the syntax by clicking the right-most button, Run syntax check, because Chrome/Tampermonkey appear to be less forgiving than Firefox & Greasemonkey.

You can now start any race on Sailonline and run the NMEA applet from the client. If the scrolling of the client screen bothers you, you can just disable the Greasemonkey/Tampermonkey while the applet is running, and press F5 to refresh the client window.

If you have trouble getting the Runproxy button to appear on the client page, particularly in Chrome, it is most likely caused by an url missing in the Includes. That is due to the inconsistant use of http://www.sailonline.org and sailonline.org, tricking your browser into thinking they are different sites. If that happens, note the url and add it (in Tampermonkey using the Settings tab of the script editor; in Greasemonkey using the Options button on the Manage user scripts page).

And there you have it: a monkey to the proxy.