michaeljb/Goko-Live-Log-Viewer — pull request #20 by aiannacc (2013-08-04 12:37:40+00:00)
Title: GokoSalvager as Firefox extension

Added source code for the firefox extension. Includes automatch and the logviewer.

firefox/package.json describes the extension
firefox/lib/main.js is the brains of the operation, which specifies what sites to modify and which scripts to run on them.

Each script consists of a function that adds/modifies all the FS. methods we need (like "foo" in the log viewer js), followed by code to append that function's source to the main goko page (gameClient.html). Appending the source ensures that the code runs in the the Goko JS context/namespace without resorting to the security risks of "unsafeWindow."

For Firefox, this is accomplished using the pageMod function, which accepts an option specifying when to run the scripts (see lib/main.js). This approach should work for Safari and Chrome as well, just so long as they can be configured to run the scripts when the DOMContentLoaded event triggers.

Building the FF extension requires the Firefox Add-on SDK. Download the SDK, put the binary directory in your path, and run "cfx xpi" from the firefox directory. This builds the "salvager.xpi" file.

I also fixed a minor timing problem in Goko_Live_Log_Viewer.user.js that somehow doesn't reveal itself in GM or Safari/Chrome. The object FS.Dominion.DeckBuilder doesn't exist (and therefore its prototype cannot have it's methods modified) at the moment that DOMContentLoaded triggers. It exists very shortly thereafter, but the existing code made it possible for the script to find that FS.Dominion.DeckBuilder was undefined. I added a setInterval loop that waits for this object to exist before running the script. It waits less than a second, and shouldn't cause problems for the other browsers' versions.

Finally, note that firefox/data/logviewer.js is an exact copy of Goko_Live_Log_Viewer.user.js. I needed it because I don't know how to set up a rake task to copy Goko_Live_Log_Viewer.user.js into the firefox directory before building the xpi.