Permalink
Browse files

added Reversi improvements

  • Loading branch information...
1 parent 31bcef0 commit 13f417dde0a89120c37ba87b95dac4760e3b74bf U-Trevor-PC\Trevor committed Sep 27, 2010
Showing with 102 additions and 54 deletions.
  1. +5 −1 background.html
  2. +2 −1 manifest.json
  3. +30 −12 options.html
  4. +16 −0 src/requests.js
  5. +20 −0 src/reversi_style.js
  6. +29 −40 src/shogi_piece_set.js
View
6 background.html 100644 → 100755
@@ -2,12 +2,16 @@
<script>
// Set default values
if (localStorage.style == undefined) localStorage.style = "default";
+ if (localStorage.background == undefined) localStorage.background = false;
+ if (localStorage.go == undefined) localStorage.go = false;
// Add localStorage request handler
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {
if (request.localstorage == "style")
- sendResponse({style: localStorage.style});
+ sendResponse({style: localStorage.style});
+ else if (request.localstorage == "reversiStyle")
+ sendResponse({green: localStorage.background, go: localStorage.go});
else
sendResponse({});
}
View
3 manifest.json 100644 → 100755
@@ -11,7 +11,8 @@
"content_scripts": [
{
"matches": ["http://www.littlegolem.net/jsp/game/game.jsp*"],
- "js": ["lib/jquery.js", "src/shogi_piece_set.js"],
+ "js": ["lib/jquery.js", "src/shogi_piece_set.js",
+ "src/reversi_style.js", "src/requests.js"],
"run_at": "document_end"
}
],
View
42 options.html 100644 → 100755
@@ -1,23 +1,29 @@
<html>
-<head><title>BiggerGolem Options</title></head>
+<head><title>BiggerGolem Options</title>
<script type="text/javascript">
// Saves options to localStorage.
function save_options() {
var select = document.getElementById("style");
var style = select.children[select.selectedIndex].value;
- localStorage["style"] = style;
+ localStorage["style"] = style;
+
+ var reversiOpts = document.getElementById("reversi");
+ localStorage["background"] = reversiOpts.green.checked;
+ localStorage["go"] = reversiOpts.go.checked;
// Update status to let user know options were saved.
var status = document.getElementById("status");
- status.innerHTML = "Options saved.";
+ status.innerHTML = "Options saved.";
setTimeout(function() {
status.innerHTML = "";
}, 750);
}
// Restores select box state to saved value from localStorage.
function restore_options() {
- var selected_style = localStorage["style"];
+ var selected_style = localStorage["style"];
+ var selected_reversiGreen = localStorage["background"];
+ var selected_reversiGo = localStorage["go"];
if (!selected_style) {
return;
}
@@ -28,21 +34,33 @@
child.selected = "true";
break;
}
- }
+ }
+ var reversiOpts = document.getElementById("reversi");
+ if (selected_reversiGreen == "true") reversiOpts.green.checked = true;
+ if (selected_reversiGo == "true") reversiOpts.go.checked = true;
}
</script>
+</head>
<body onload="restore_options()">
- Shogi Piece Style:
- <select id="style">
- <option value="default">Default</option>
- <option value="Ryoko">Ryoko</option>
- <option value="Kinki">Kinki</option>
- </select>
+ <fieldset>
+ <legend style="font-size:0.8em;font-weight:bold;background:#CCCCCC">Shogi Piece Set</legend>
+ <select id="style">
+ <option value="default">Default</option>
+ <option value="Ryoko">Ryoko</option>
+ <option value="Kinki">Kinki</option>
+ </select>
+ </fieldset><br>
- <br>
+ <fieldset>
+ <legend style="font-size:0.8em;font-weight:bold;background:#CCCCCC">Reversi Board Options</legend>
+ <form id="reversi">
+ <input type="checkbox" name="green" /><label for="green">Green background</label>
+ <input type="checkbox" name="go" /><label for="go">Use Go stones</label>
+ </form>
+ </fieldset>
<div id="status"> </div> <br>
<button onclick="save_options()">Save</button>
</body>
View
@@ -0,0 +1,16 @@
+var game_name = $("body>table:nth-child(3)>tbody>tr>td>font>b").text();
+
+if (game_name.indexOf("Reversi") >= 0) {
+ chrome.extension.sendRequest({localstorage: "reversiStyle"},
+ function(response) {
+ set_reversi_style(response.green,response.go);
+ });
+}
+
+if (game_name.indexOf("Shogi") >= 0) {
+ set_style("blank");
+ chrome.extension.sendRequest({localstorage: "style"},
+ function(response) {
+ set_style(response.style);
+ });
+}
View
@@ -0,0 +1,20 @@
+function set_reversi_style(green,go) {
+ var lastMove = $("table[bordercolor] td[bgcolor='#FF9115']");
+ var lastMoveImg = $("table[bordercolor] td[bgcolor='#FF9115'] img");
+ if (green == "true") {
+ if (lastMove.length) lastMove[0].style.backgroundColor = "#00EE00";
+ var tds = $("table[bordercolor] td[bgcolor!='#FF9115']:has(img)");
+ for (var i = 0; i < tds.length; i++) tds[i].style.backgroundColor = "#008800";
+ }
+ if (go == "true") {
+ if (lastMove.length) {
+ var lastMoveColor = lastMoveImg[0].src.match(/\/reversi\/([bw])\.gif/)[1];
+ $(lastMoveImg[0]).attr("src","/iphone/images/go/35_"+lastMoveColor+"sx.png");
+ }
+ var imgs = $("table[bordercolor] img[src*=reversi]");
+ for (var i = 0; i < imgs.length; i++) {
+ var color = imgs[i].src.match(/\/reversi\/([bw])\.gif/)[1];
+ $(imgs[i]).attr("src","/iphone/images/go/35_"+color+"s.png");
+ }
+ }
+}
View
69 src/shogi_piece_set.js 100644 → 100755
@@ -1,50 +1,39 @@
-var game_name = $("body>table:nth-child(3)>tbody>tr>td>font>b").text();
-var style = "blank";
-
function set_style(style) {
- if (game_name.indexOf("Shogi") >= 0) {
- var divs = $("div");
- for (var i = 0; i < divs.length; i++) {
- var piece_pos = divs[i].style.backgroundImage.search(/shogi\d\d/);
- if (piece_pos >= 0) {
- if (style == "blank") {
- divs[i].style.backgroundImage = "/*" + divs[i].style.backgroundImage.substr(piece_pos, 7) + "*/";
- divs[i].style.visibility = "hidden";
- } else {
- var piece = divs[i].style.backgroundImage.substr(piece_pos, 7);
- if (style != "default") {
- divs[i].style.backgroundImage = "url(" + chrome.extension.getURL("img/shogi/kanji/" + style + "/" + piece + ".png") + ")";
- divs[i].style.height = "48px";
- }
- divs[i].style.visibility = "visible";
+ var divs = $("div");
+ for (var i = 0; i < divs.length; i++) {
+ var piece_pos = divs[i].style.backgroundImage.search(/shogi\d\d/);
+ if (piece_pos >= 0) {
+ if (style == "blank") {
+ divs[i].style.backgroundImage = "/*" + divs[i].style.backgroundImage.substr(piece_pos, 7) + "*/";
+ divs[i].style.visibility = "hidden";
+ } else {
+ var piece = divs[i].style.backgroundImage.substr(piece_pos, 7);
+ if (style != "default") {
+ divs[i].style.backgroundImage = "url(" + chrome.extension.getURL("img/shogi/kanji/" + style + "/" + piece + ".png") + ")";
+ divs[i].style.height = "48px";
}
+ divs[i].style.visibility = "visible";
}
}
+ }
- // Might also be a promotion box.
- if ($("body>table:nth-child(3) div").length == 43) {
- promotion_pieces = $("body>table:nth-child(3) div:eq(41)>img");
- for (var i = 0; i < promotion_pieces.length; i++) {
- if (style == "blank") {
- var piece_pos = promotion_pieces[i].src.search(/shogi\d\d/);
- promotion_pieces[i].className = promotion_pieces[i].src.substr(piece_pos, 7);
- //promotion_pieces[i].removeAttribute("src");
- promotion_pieces[i].style.visibility = "hidden";
- } else {
- var piece = promotion_pieces[i].className;
- if (piece == undefined || piece == "") { piece = promotion_pieces[i].src.substr(promotion_pieces[i].src.search(/shogi\d\d/), 7); }
- if (style != "default") {
- promotion_pieces[i].src = "url(" + chrome.extension.getURL("img/shogi/kanji/" + style + "/" + piece + ".png") + ")";
- }
- promotion_pieces[i].style.visibility = "visible";
+ // Might also be a promotion box.
+ if ($("body>table:nth-child(3) div").length == 43) {
+ promotion_pieces = $("body>table:nth-child(3) div:eq(41)>img");
+ for (var i = 0; i < promotion_pieces.length; i++) {
+ if (style == "blank") {
+ var piece_pos = promotion_pieces[i].src.search(/shogi\d\d/);
+ promotion_pieces[i].className = promotion_pieces[i].src.substr(piece_pos, 7);
+ //promotion_pieces[i].removeAttribute("src");
+ promotion_pieces[i].style.visibility = "hidden";
+ } else {
+ var piece = promotion_pieces[i].className;
+ if (piece == undefined || piece == "") { piece = promotion_pieces[i].src.substr(promotion_pieces[i].src.search(/shogi\d\d/), 7); }
+ if (style != "default") {
+ promotion_pieces[i].src = "url(" + chrome.extension.getURL("img/shogi/kanji/" + style + "/" + piece + ".png") + ")";
}
+ promotion_pieces[i].style.visibility = "visible";
}
}
}
}
-
-set_style("blank");
-chrome.extension.sendRequest({localstorage: "style"},
- function(response) {
- set_style(response.style);
- });

0 comments on commit 13f417d

Please sign in to comment.