From 2fd33078775970baf6deb2154b0e3c75fe375d26 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Sun, 18 May 2014 00:07:49 -0400 Subject: [PATCH] Update /shared.php row colors after updating them. --- main.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index 1475a13..61b7147 100644 --- a/main.js +++ b/main.js @@ -422,6 +422,22 @@ function hook_edit(anime_id) { }); } +function update_shared_row_colors(row, our_pos) { + var our_cell = $(row.find("td")[our_pos]); + var their_cell = $(row.find("td")[our_pos == 1 ? 2 : 1]); + var diff = our_cell.text() - their_cell.text(); + + if (!diff) { + row.find("td").css("background-color", "#f6f6f6"); + our_cell.add(their_cell).find("span").css("color", ""); + } + else { + row.find("td").css("background-color", ""); + our_cell.css("color", diff > 0 ? "#FF0000" : "#0000FF"); + their_cell.css("color", diff > 0 ? "#0000FF" : "#FF0000"); + } +} + function hook_shared() { var our_profile = $("#nav a:first").attr("href"), our_pos; var profile_links = $("#content h2:first").find("a").slice(1); @@ -455,6 +471,7 @@ function hook_shared() { diff_sum += diff; diff_cell.text(round_score(diff)); diff_nums++; + update_shared_row_colors($(row), our_pos); } }); @@ -466,8 +483,10 @@ function hook_shared() { }); mean_score = round_score(score_sum / score_nums); - if (!isNaN(mean_score)) + if (!isNaN(mean_score)) { $(shared_means.find("td")[our_pos]).find("span").text(mean_score); + update_shared_row_colors(shared_means, our_pos); + } mean_diff = Math.round(diff_sum / diff_nums * 100) / 100; if (!isNaN(mean_diff))