Commits

Marcin Kasperski committed f2aa565

Znowu działa podmienianie zegarków.

Przy tym pamięta je w storage a nie w aboutsach

  • Participants
  • Parent commits 1b25f5e

Comments (0)

Files changed (3)

File smtuning/content/overlay.js

     // Funkcja pomocnicza. W podanym bloku wyszukuje wszystkie ikony
     // zegarka i podmienia na zadane. block należy podać tylko gdy nie jest null
     replaceClockIcons : function(doc, block, clockType) {
-        var pfx = "";
         if( block ) {
-            pfx = "td";
+            // pass
         } else {
             block = doc;
         }
+
+        // Obsługujemy dwa warianty. Stary - gdzie są po prosu
+        // obrazki src clock.gif i clocka.gif - oraz nowy - gdzie
+        // mamy spany klasy clock i clock_running.
+        // 
+        smtext.dump("Trying to replace clock to " + clockType + " in " + block.innerHTML);
+
         var nodes = smtdoc.xpathRelative(
             doc, block,
-            pfx + "//img[contains(@src,'/clock.gif')]");
+            ".//img[contains(@src,'/clock.gif')]");
+        for (var i = 0; i < nodes.snapshotLength; i++) {
+            smtext.dump("Old style clock.gif");
+            var thisImg = nodes.snapshotItem(i);
+            thisImg.setAttribute("src","chrome://smtuning/skin/clock/clock_" + clockType + ".gif");
+        }
+
+        var nodes = smtdoc.xpathRelative(
+            doc, block,
+            ".//img[contains(@src,'/clocka.gif')]");
+        for (var i = 0; i < nodes.snapshotLength; i++) {
+            smtext.dump("Old style clocka.gif");
+            var thisImg = nodes.snapshotItem(i);
+            thisImg.setAttribute("src","chrome://smtuning/skin/clock/clocka_" + clockType + ".gif");
+        }
+
+        var nodes = smtdoc.xpathRelative(
+            doc, block,
+            ".//span[contains(@class,'clock')]");
         for (var i = 0; i < nodes.snapshotLength; i++) {
             var thisImg = nodes.snapshotItem(i);
-            //smtext.dump("Patching " + thisImg.getAttribute("src") + " to " + clockType);
-            thisImg.setAttribute("src","chrome://smtuning/skin/clock/clock_" + clockType + ".gif");
-        }
-        var nodes = smtdoc.xpathRelative(
-            doc, block,
-            pfx + "//img[contains(@src,'/clocka.gif')]");
-        for (var i = 0; i < nodes.snapshotLength; i++) {
-            var thisImg = nodes.snapshotItem(i);
-            //smtext.dump("Patching " + thisImg.getAttribute("src") + " to " + clockType);
-            thisImg.setAttribute("src","chrome://smtuning/skin/clock/clocka_" + clockType + ".gif");
+            var thisClass = thisImg.getAttribute("class");
+            smtext.dump("new style elem of class " + thisClass);
+            thisClass = thisClass.replace(/\b(clock_running|clock)\b/, "$1_" + clockType);
+            thisImg.setAttribute("class", thisClass);
+            smtext.dump("class set to " + thisClass);
         }
     },
 
         var rows = smtdoc.xpath(
             doc,
             "//div[contains(@class,'itemgame')]");
-        alert(rows.snapshotLength);
-        // smtext.dump("Games found: " + rows.snapshotLength);
+        smtext.dump("Games found: " + rows.snapshotLength);
         for (var i = 0; i < rows.snapshotLength; i++) {
             var row = rows.snapshotItem(i);
             var linkHref = smtdoc.xpathFirstRelative(
-                doc, row, "//a[contains(@href,'game.aspx')]");
+                doc, row, ".//a[contains(@href,'game.aspx')]");
             if(linkHref) {
                 var link = linkHref.getAttribute("href");
-                if (link.match(/game_id=([0-9]+)/)) {
+                smtext.dump("Found link " + link);
+                if (link.match(/game_id=([0-9][0-9]*)/)) {
                     var gameId = RegExp.$1;
+                    smtext.dump("Matched game id: " + gameId);
                     if (colorizeClock) {
                         var clockType = smtdoc.readSavedGameClockInfo(gameId);
+                        smtext.dump("Clock type: " + clockType);
                         if (clockType) {
                             //smtext.dump("row " + i + " clock " + clockType);
                             smtuning.replaceClockIcons(doc, row, clockType);
                         }
                     }
+                } else {
+                    smtext.dump("Can not find game id in link " + link);
                 }
+            } else {
+                smtext.dump("linkHref not found in row " + int2string(i));
             }
         }
     },

File smtuning/content/smt_docutil.js

         return document.evaluate(query, document, null,
                                  XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
     },
-    // Szukanie w bloku under a nie całym dokumencie
+    // Szukanie w bloku under a nie całym dokumencie. Uwaga, by
+    // to działało z sensem trzeba dawać query zaczynające się
+    // od           .//
     xpathRelative : function(document, under, query) {
         return document.evaluate(query, under, null,
                                  XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
         //var clockPref = 'data.clock.' + gameId;
         //smtext.prefman.setValue(clockPref, clockType);
         //console.log("Saving clock for " + gameId + ": " + clockType);
-        localStorage.setItem("smtuning.clock." + gameId, clockType);
+    
+        //storage = localStorage;
+        var storage = globalStorage["schemingmind.com"];
+
+        storage.setItem("smtuning.clock." + gameId, clockType);
     },
 
     // Odczytuje zegar albo null
         //var clockPref = 'data.clock.' + gameId;
         //var clockType = smtext.prefman.getValue(clockPref, null);
         //dump("Loading");
-        var clockType = localStorage.getItem("smtuning.clock." + gameId, null);
+        // storage = localStorage;
+        var storage = globalStorage["schemingmind.com"];
+
+        var clockType = storage.getItem("smtuning.clock." + gameId, null);
         return clockType;
     }
 

File smtuning/skin/smtuning_document.css

 .highlighted_check_black {
   border: 2px ridge black;  
   background-color: #777;
+}
+
+/*
+.clock {
+  background-image:url(images/clock.gif);
+  padding-left:16px;
+}
+.clock_running {
+  background-image:url(images/clocka.gif);
+}
+*/
+.clock_blitz {
+  background-image:url(chrome://smtuning/skin/clock/clock_blitz.gif);
+  padding-left:16px;
+}
+.clock_running_blitz {
+  background-image:url(chrome://smtuning/skin/clock/clocka_blitz.gif);
+  padding-left:16px;
+}
+.clock_standard {
+  background-image:url(chrome://smtuning/skin/clock/clock_standard.gif);
+  padding-left:16px;
+}
+.clock_running_standard {
+  background-image:url(chrome://smtuning/skin/clock/clocka_standard.gif);
+  padding-left:16px;
+}
+.clock_fast {
+  background-image:url(chrome://smtuning/skin/clock/clock_fast.gif);
+  padding-left:16px;
+}
+.clock_running_fast {
+  background-image:url(chrome://smtuning/skin/clock/clocka_fast.gif);
+  padding-left:16px;
+}
+.clock_leisure {
+  background-image:url(chrome://smtuning/skin/clock/clock_leisure.gif);
+  padding-left:16px;
+}
+.clock_running_leisure {
+  background-image:url(chrome://smtuning/skin/clock/clocka_leisure.gif);
+  padding-left:16px;
 }