Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added color coding to rating and download columns

  • Loading branch information...
commit 7e854f5499e267fcbf3b51c52983545d59d71008 1 parent 4e2f31e
@brymck authored
Showing with 15 additions and 6 deletions.
  1. +14 −5 src/js/content.js
  2. +1 −1  src/manifest.json
View
19 src/js/content.js
@@ -1,12 +1,18 @@
var VimRatings = (function() {
- var RPD_DECIMALS = 3;
- var RPD_MIN = -0.05;
- var RPD_MAX = 0.25;
+ var R_MIN = 0;
+ var R_MAX = 1000;
+
+ var DL_MIN = 0;
+ var DL_MAX = 10000;
var RPR_DECIMALS = 2;
var RPR_MIN = -1;
var RPR_MAX = 4;
+ var RPD_DECIMALS = 3;
+ var RPD_MIN = -0.05;
+ var RPD_MAX = 0.25;
+
function stripTags(str) {
return str.replace(/<[^>]+>/g, "");
}
@@ -90,12 +96,15 @@ var VimRatings = (function() {
.after($("<th>").html("Average<br>Rating"));
} else {
scriptId = $("a:first", $tr).attr("href").match(/script_id=(\d+)/)[1];
+ $tds.eq(ratingCol - 1).css("backgroundColor", xlcs.convert(rating, R_MIN, R_MAX));
+ $tds.eq(downloadsCol - 1).css("backgroundColor", xlcs.convert(downloads, DL_MIN, DL_MAX));
$lastTd.after($(getColor(rating / downloads, RPD_DECIMALS, RPD_MIN, RPD_MAX, "td")).attr("align", "right"))
.after($("<td>").addClass(isOddRow ? "rowodd" : "roweven"));
$.get("http://www.vim.org/scripts/script.php", { script_id: scriptId }, function(data) {
- var numbers = data.match(/<b>(\d+)\/(\d+)<\/b>/);
+ var numbers = data.match(/<b>(-?\d+)\/(\d+)<\/b>/);
+ var rpr = (numbers[1] === "0" ? 0 : parseInt(numbers[1], 10) / parseInt(numbers[2], 10));
$lastTd.next("td").replaceWith(
- $(getColor(parseInt(numbers[1], 10) / parseInt(numbers[2], 10), RPR_DECIMALS, RPR_MIN, RPR_MAX, "td")).attr("align", "right")
+ $(getColor(rpr, RPR_DECIMALS, RPR_MIN, RPR_MAX, "td")).attr("align", "right")
);
});
isOddRow = !isOddRow;
View
2  src/manifest.json
@@ -1,7 +1,7 @@
{
"name": "vim_ratings",
"version": "0.8",
- "description": "Show additional rating metrics for vim plugins at vim.org",
+ "description": "Show and color-code average rating and rating per download for vim plugins at vim.org",
"icons": {
"16": "img/icon_16.png",
"48": "img/icon_48.png",
Please sign in to comment.
Something went wrong with that request. Please try again.