Permalink
Browse files

Added end of game logging to appengine.

This will collect game data so I can actually test the extension and
make sure there are no regressions.
  • Loading branch information...
drheld committed Apr 14, 2011
1 parent 36f74a6 commit 70b67e87225e45407a14b2a380d8e80b4a324a67
Showing with 68 additions and 6 deletions.
  1. +6 −0 background.html
  2. +17 −0 background.js
  3. +24 −5 dominion.js
  4. +16 −0 jquery.js
  5. +5 −1 manifest.json
View
@@ -0,0 +1,6 @@
+<html>
+ <head>
+ <script src='jquery.js'></script>
+ <script src='background.js'></script>
+ </head>
+</html>
View
@@ -0,0 +1,17 @@
+function handleLogRequest(request) {
+ console.log("Posting: " + JSON.stringify(request))
+ $.post("http://dominion-point-counter.appspot.com/log_game", request);
+}
+
+chrome.extension.onRequest.addListener(
+function(request, sender, sendResponse) {
+ var type = request.type;
+ delete request.type;
+
+ if (type == "log") {
+ handleLogRequest(request);
+ } else {
+ console.log("Unknown request type '" + type + "' in: " +
+ JSON.stringify(request));
+ }
+});
View
@@ -630,12 +630,31 @@ function handle(doc) {
if (doc.constructor == HTMLElement && doc.parentNode.id == "log") {
maybeRewriteName(doc);
handleLogEntry(doc);
+ }
- // Reset exit / faq at end of game.
- if (doc.className == "em" && doc.innerText.indexOf("wins!") != -1) {
- started = false;
- deck_spot.innerHTML = "exit";
- points_spot.innerHTML = "faq";
+ if (doc.constructor == HTMLDivElement && doc.parentNode.id == "choices") {
+ for (var node in doc.childNodes) {
+ if (doc.childNodes[node].innerText == "game log") {
+ // Reset exit / faq at end of game.
+ started = false;
+ deck_spot.innerHTML = "exit";
+ points_spot.innerHTML = "faq";
+
+ // Collect information about the game.
+ var href = doc.childNodes[node].href;
+ var game_id_str = href.substring(href.lastIndexOf("/") + 1);
+ var name = localStorage["name"];
+ if (name == undefined || name == null) name = "Unknown";
+
+ // Post the game information to app-engine for later use for tests, etc.
+ chrome.extension.sendRequest({
+ type: "log",
+ game_id: game_id_str,
+ reporter: name,
+ log: document.body.innerHTML,
+ settings: debugString(localStorage) });
+ break;
+ }
}
}
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -13,7 +13,11 @@
"matches": [ "http://dominion.isotropic.org/*loggedin*" ]
}
],
+ "permissions": [
+ "http://dominion-point-counter.appspot.com/"
+ ],
"description": "Dominion Point Counter",
"name": "Dominion Point Counter",
- "version": "2.0.2"
+ "background_page": "background.html",
+ "version": "2.1"
}

0 comments on commit 70b67e8

Please sign in to comment.