Commits

Marcin Kasperski committed 1b25f5e

Próby przywrócenia działania kolorowania zegarków.

Usunięcie błędu raportowanego przy zoom.

  • Participants
  • Parent commits 0fdf9f6

Comments (0)

Files changed (2)

smtuning/content/overlay.js

 
     // Interpretuje planszę i zgaduje jaki zegar jest używany.
     handleClockColorizingOnBoard : function(doc, view, gameId) {
-        var clockPref = 'data.clock.' + gameId;
-        var clockType = smtext.prefman.getValue(clockPref);
+        var clockType = smtdoc.readSavedGameClockInfo(gameId);
+        //console.log("Hallo" + clockType);
         if (! clockType) { // Jeśli znamy, nie trzeba szukać na nowo
             var clkDesc = smtdoc.xpathFirst(doc, "//table[@id='ContentPlaceHolder1_Table8']//table//td[contains(.,'days +')]/text()");
             var clkRe = /([0-9]+)\s*days\s*\+\s*([0-9]+)/;
-            if (clkDesc.data.match(clkRe)) {
-                if (RegExp.$1 == "5") {
+            var clkMatch = clkDesc.data.match(clkRe);
+            if (clkMatch) {
+                //console.log("Hello" + clkMatch);
+                if (clkMatch[1] == "5") {
                     clockType = "blitz";
                 }
-                else if (RegExp.$1 == "10") {
+                else if (clkMatch[1] == "10") {
                     clockType = "fast";
                 }
-                else if (RegExp.$1 == "30") {
-                    if (RegExp.$2 == "1" ) {
+                else if (clkMatch[1] == "30") {
+                    if (clkMatch[2] == "1" ) {
                         clockType = "standard";
-                    } else if (RegExp.$2 == "3") {
+                    } else if (clkMatch[2] == "3") {
                         clockType = "leisure";
                     }
                 }
                 if (clockType) {
-                    smtext.prefman.setValue(clockPref, clockType);
+                    smtdoc.saveGameClockInfo(gameId, clockType);
                 }
             }
         }
 
     // Modyfikacje listy partii
     patchGameList : function(doc, view, colorizeClock) {
-        var rows = smtdoc.xpath(doc,
-                                "//table[@id='ContentPlaceHolder1_Table1']//tr[contains(@onclick,'window.location.href')]");
+        // smtext.dump("Patching game list");
+        var rows = smtdoc.xpath(
+            doc,
+            "//div[contains(@class,'itemgame')]");
+        alert(rows.snapshotLength);
+        // smtext.dump("Games found: " + rows.snapshotLength);
         for (var i = 0; i < rows.snapshotLength; i++) {
             var row = rows.snapshotItem(i);
-            var link = row.getAttribute("onclick");
-            if (link.match(/game_id=([0-9]+)/)) {
-                var gameId = RegExp.$1;
-                if (colorizeClock) {
-                    var clockType = smtext.prefman.getValue('data.clock.' + gameId, '');
-                    if (clockType) {
-                        //smtext.dump("row " + i + " clock " + clockType);
-                        smtuning.replaceClockIcons(doc, row, clockType);
+            var linkHref = smtdoc.xpathFirstRelative(
+                doc, row, "//a[contains(@href,'game.aspx')]");
+            if(linkHref) {
+                var link = linkHref.getAttribute("href");
+                if (link.match(/game_id=([0-9]+)/)) {
+                    var gameId = RegExp.$1;
+                    if (colorizeClock) {
+                        var clockType = smtdoc.readSavedGameClockInfo(gameId);
+                        if (clockType) {
+                            //smtext.dump("row " + i + " clock " + clockType);
+                            smtuning.replaceClockIcons(doc, row, clockType);
+                        }
                     }
                 }
             }
             return;
         }
 
-        smtdoc.addJavaScript(doc, "smtPieceSet = smtpieces.pieceByName('"
-                             + wantedSetName + "')");
+        smtdoc.addJavaScript(doc, "smtPieceSetName = '" + wantedSetName + "';")
+
+        // To w FF7 zgłasza błąd braku zmiennej smtpieces
+        //smtdoc.addJavaScript(doc, "smtPieceSet = smtpieces.pieceByName('"
+        //                     + wantedSetName + "')");
+
 
         var zoomIn = doc.createElement("img");
         zoomIn.setAttribute("src", "chrome://smtuning/skin/zoomin.png");

smtuning/content/smt_docutil.js

     addStyle : function(doc, cssText) {
         var head = doc.getElementsByTagName('head')[0];
         if (!head) { return; }
-        style = doc.createElement("style")
+        var style = doc.createElement("style")
         style.type = 'text/css';
         style.innerHTML = cssText;
         head.appendChild(style);
     addJavaScript : function(doc, scriptText) {
         var head = doc.getElementsByTagName('head')[0];
         if (!head) { return; }
-        newScript = doc.createElement("script")
+        var newScript = doc.createElement("script")
         newScript.type = 'text/javascript';
         newScript.innerHTML = scriptText;
         head.appendChild(newScript);
 
     zoomIn : function() {
         var oldSize = PieceSize;
+        var smtPieceSet = smtpieces.pieceByName(smtPieceSetName);
         var nextSize = smtPieceSet.nextSizeUp(oldSize);
         if (nextSize) {
             var path = smtPieceSet.piecesPath(nextSize);
 
     zoomOut : function() {
         var oldSize = PieceSize;
+        var smtPieceSet = smtpieces.pieceByName(smtPieceSetName);
         var nextSize = smtPieceSet.nextSizeDown(oldSize);
         if (nextSize) {
             var path = smtPieceSet.piecesPath(nextSize);
         AnalysisBoard[AnaMove] = board;
         DrawAnalysisBoard();
         DisplayTab(4);
+    },
+
+    /////////////////////////////////////////////////////////////////
+    // Save
+    /////////////////////////////////////////////////////////////////
+
+    // Zapisuje jaki zegar jest w danej partii. Pierwszy parametr
+    // to id (tekst), drugi to blitz/fast/standard/
+    saveGameClockInfo : function(gameId, clockType) {
+        //var clockPref = 'data.clock.' + gameId;
+        //smtext.prefman.setValue(clockPref, clockType);
+        //console.log("Saving clock for " + gameId + ": " + clockType);
+        localStorage.setItem("smtuning.clock." + gameId, clockType);
+    },
+
+    // Odczytuje zegar albo null
+    readSavedGameClockInfo : function(gameId) {
+        //var clockPref = 'data.clock.' + gameId;
+        //var clockType = smtext.prefman.getValue(clockPref, null);
+        //dump("Loading");
+        var clockType = localStorage.getItem("smtuning.clock." + gameId, null);
+        return clockType;
     }
 
 };