Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Gyran committed Mar 12, 2012
0 parents commit cc96430
Show file tree
Hide file tree
Showing 24 changed files with 356 additions and 0 deletions.
151 changes: 151 additions & 0 deletions init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/***
Ratiocolors!
Change the color of the ratio column according to the ratio
Written by Gyran
***/

/***
TODO:
Fix a working settings tab, currently only displaying your levels and colors. Currently only works in webkit browsers
****/


plugin.loadLang();
plugin.loadMainCSS();

/*** Settings ***/
// Diffrent color between diffrents levels. First level must be 0.
levels = [0, 1, 3, 30];

// Colors of the diffrent levels. [r, g, b]
colors = [ [255, 0, 0],
[255, 255, 0],
[0, 255, 0],
[123, 17, 203]
];

/* Example
If ratio is 0 the color will be the first definde color. The the more the ratio approach
the next level the more it goes towards the next color. When the ratio is more then
the last level it will have the color of the last color.
*/

/****************/

function colorSub(a, b){
return [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
}

function colorAdd(a, b){
return [a[0] + b[0], a[1] + b[1], a[2] + b[2]];
}

function colorMul(a, mul){
return [Math.floor(a[0] * mul), Math.floor(a[1] * mul), Math.floor(a[2] * mul)];
}

function colorRGB(color){
return "rgb(" + color[0] + ", " + color[1] + ", " + color[2] + ")";
}

theWebUI.setRatioColors = function(){
$(".stable-List-col-6").each(function(index) {
ratio = $(this).children("div")[0].innerHTML
color = null;
proc = 0;

$.each(levels, function(index, level){
if(ratio < level){
leveldiff = level - levels[index - 1];
proc = (ratio - levels[index - 1]) / leveldiff;

diffColor = colorSub(colors[index], colors[index - 1]);

color = colorAdd(colorMul(diffColor, proc), colors[index - 1]);

return false;
}
});

if(color == null){
color = colors[colors.length - 1];
}

$(this).css("background-color", colorRGB(color));
});

};

plugin.onLangLoaded = function() {
if(this.enabled) {
error = false;

// Error checking
if(colors.length != levels.length){
log(theUILang.ratiocolorLengthError);
error = true;
}
if(levels[0] != 0){
log(theUILang.ratiocolorLevel0);
error = true;
}
if(!error){
plugin.tempFunc = theWebUI.tables.trt.obj.refreshRows;
theWebUI.tables.trt.obj.refreshRows = function(height, fromScroll){
plugin.tempFunc.call(theWebUI.tables.trt.obj, height, fromScroll);
theWebUI.setRatioColors();
};

rcSettingsDiv = $('<div>').attr("id","st_ratiocolor");
fieldset = $('<fieldset>').html("<legend>" + theUILang.ratiocolorLegend + "</legend>");
fieldset.append(theWebUI.ratiocolorLevelsbar(levels, colors));


// New level add
divAdd = $('<div>').attr("id", "ratiocolorAddNewLevel");
divAdd.html('Level: <input id="rcAddLvl" type="text" /><br />Color: #<input id="rcAddColor" type="text" />')
btnAdd = $('<input>').attr("type", "button").attr("value", "New level");
btnAdd.click(function()
{
levels.push($("#rcAddLvl").val());
//colors.add($("#rcAddColor").val());
colors.push([255,255,255]);

theWebUI.updateRatiocolorsLevelsBar(levels, colors);

});
divAdd.append(btnAdd);
fieldset.append(divAdd);



rcSettingsDiv.append(fieldset);
this.attachPageToOptions(rcSettingsDiv[0], theUILang.ratiocolorSettings);
}
}
}

theWebUI.ratiocolorLevelsbar = function(levels, colors){
div = $("<div>").attr("id","ratiocolorLevelsbar");
width = Math.floor(100/(colors.length-1)) + "%";
for(i=1;i<colors.length;++i)
{
level = $("<div>").addClass("level").html(levels[i]);
level.attr("style", "background-image: -webkit-gradient(linear, 0% 0%, 100% 0%, from(" + colorRGB(colors[i-1]) + "), to(" + colorRGB(colors[i]) + "));");
level.css("width", width);
div.append(level[0]);

}
return div;
}

theWebUI.updateRatiocolorsLevelsBar = function(levels, colors)
{
$('#ratiocolorLevelsbar').html(theWebUI.ratiocolorLevelsbar(levels, colors).html());
}

plugin.onRemove = function()
{
this.removePageFromOptions("st_ratiocolors");
}

9 changes: 9 additions & 0 deletions lang/cs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@


theUILang.ratiocolorName = "Ratiocolor";
theUILang.ratiocolorColors = "Colors in hex sperated by ',' (Format: 0000ff,ff0000,...)";
theUILang.ratiocolorLevels = "Levels seperated by ','. Must start with 0 (Format: 0,0.5,1,...)";
theUILang.ratiocolorLengthError = "Ratiocolor: There must be the same numbers of levels and colors";
theUILang.ratiocolorLevel0 = "Ratiocolor: The first level must be 0";

thePlugins.get("ratiocolor").langLoaded();
9 changes: 9 additions & 0 deletions lang/da.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@


theUILang.ratiocolorName = "Ratiocolor";
theUILang.ratiocolorColors = "Colors in hex sperated by ',' (Format: 0000ff,ff0000,...)";
theUILang.ratiocolorLevels = "Levels seperated by ','. Must start with 0 (Format: 0,0.5,1,...)";
theUILang.ratiocolorLengthError = "Ratiocolor: There must be the same numbers of levels and colors";
theUILang.ratiocolorLevel0 = "Ratiocolor: The first level must be 0";

thePlugins.get("ratiocolor").langLoaded();
9 changes: 9 additions & 0 deletions lang/de.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@


theUILang.ratiocolorName = "Ratiocolor";
theUILang.ratiocolorColors = "Colors in hex sperated by ',' (Format: 0000ff,ff0000,...)";
theUILang.ratiocolorLevels = "Levels seperated by ','. Must start with 0 (Format: 0,0.5,1,...)";
theUILang.ratiocolorLengthError = "Ratiocolor: There must be the same numbers of levels and colors";
theUILang.ratiocolorLevel0 = "Ratiocolor: The first level must be 0";

thePlugins.get("ratiocolor").langLoaded();
9 changes: 9 additions & 0 deletions lang/en.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@


theUILang.ratiocolorName = "Ratiocolor";
theUILang.ratiocolorLengthError = "Ratiocolor: There must be the same numbers of levels and colors";
theUILang.ratiocolorLevel0 = "Ratiocolor: The first level must be 0";
theUILang.ratiocolorLegend = "Ratiocolor";
theUILang.ratiocolorSettings = "Ratiocolor";

thePlugins.get("ratiocolor").langLoaded();
9 changes: 9 additions & 0 deletions lang/es.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@


theUILang.ratiocolorName = "Ratiocolor";
theUILang.ratiocolorColors = "Colors in hex sperated by ',' (Format: 0000ff,ff0000,...)";
theUILang.ratiocolorLevels = "Levels seperated by ','. Must start with 0 (Format: 0,0.5,1,...)";
theUILang.ratiocolorLengthError = "Ratiocolor: There must be the same numbers of levels and colors";
theUILang.ratiocolorLevel0 = "Ratiocolor: The first level must be 0";

thePlugins.get("ratiocolor").langLoaded();
9 changes: 9 additions & 0 deletions lang/fi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@


theUILang.ratiocolorName = "Ratiocolor";
theUILang.ratiocolorColors = "Colors in hex sperated by ',' (Format: 0000ff,ff0000,...)";
theUILang.ratiocolorLevels = "Levels seperated by ','. Must start with 0 (Format: 0,0.5,1,...)";
theUILang.ratiocolorLengthError = "Ratiocolor: There must be the same numbers of levels and colors";
theUILang.ratiocolorLevel0 = "Ratiocolor: The first level must be 0";

thePlugins.get("ratiocolor").langLoaded();
9 changes: 9 additions & 0 deletions lang/fr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@


theUILang.ratiocolorName = "Ratiocolor";
theUILang.ratiocolorColors = "Colors in hex sperated by ',' (Format: 0000ff,ff0000,...)";
theUILang.ratiocolorLevels = "Levels seperated by ','. Must start with 0 (Format: 0,0.5,1,...)";
theUILang.ratiocolorLengthError = "Ratiocolor: There must be the same numbers of levels and colors";
theUILang.ratiocolorLevel0 = "Ratiocolor: The first level must be 0";

thePlugins.get("ratiocolor").langLoaded();
9 changes: 9 additions & 0 deletions lang/hu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@


theUILang.ratiocolorName = "Ratiocolor";
theUILang.ratiocolorColors = "Colors in hex sperated by ',' (Format: 0000ff,ff0000,...)";
theUILang.ratiocolorLevels = "Levels seperated by ','. Must start with 0 (Format: 0,0.5,1,...)";
theUILang.ratiocolorLengthError = "Ratiocolor: There must be the same numbers of levels and colors";
theUILang.ratiocolorLevel0 = "Ratiocolor: The first level must be 0";

thePlugins.get("ratiocolor").langLoaded();
9 changes: 9 additions & 0 deletions lang/it.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@


theUILang.ratiocolorName = "Ratiocolor";
theUILang.ratiocolorColors = "Colors in hex sperated by ',' (Format: 0000ff,ff0000,...)";
theUILang.ratiocolorLevels = "Levels seperated by ','. Must start with 0 (Format: 0,0.5,1,...)";
theUILang.ratiocolorLengthError = "Ratiocolor: There must be the same numbers of levels and colors";
theUILang.ratiocolorLevel0 = "Ratiocolor: The first level must be 0";

thePlugins.get("ratiocolor").langLoaded();
9 changes: 9 additions & 0 deletions lang/lv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@


theUILang.ratiocolorName = "Ratiocolor";
theUILang.ratiocolorColors = "Colors in hex sperated by ',' (Format: 0000ff,ff0000,...)";
theUILang.ratiocolorLevels = "Levels seperated by ','. Must start with 0 (Format: 0,0.5,1,...)";
theUILang.ratiocolorLengthError = "Ratiocolor: There must be the same numbers of levels and colors";
theUILang.ratiocolorLevel0 = "Ratiocolor: The first level must be 0";

thePlugins.get("ratiocolor").langLoaded();
9 changes: 9 additions & 0 deletions lang/nl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@


theUILang.ratiocolorName = "Ratiocolor";
theUILang.ratiocolorColors = "Colors in hex sperated by ',' (Format: 0000ff,ff0000,...)";
theUILang.ratiocolorLevels = "Levels seperated by ','. Must start with 0 (Format: 0,0.5,1,...)";
theUILang.ratiocolorLengthError = "Ratiocolor: There must be the same numbers of levels and colors";
theUILang.ratiocolorLevel0 = "Ratiocolor: The first level must be 0";

thePlugins.get("ratiocolor").langLoaded();
9 changes: 9 additions & 0 deletions lang/pl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@


theUILang.ratiocolorName = "Ratiocolor";
theUILang.ratiocolorColors = "Colors in hex sperated by ',' (Format: 0000ff,ff0000,...)";
theUILang.ratiocolorLevels = "Levels seperated by ','. Must start with 0 (Format: 0,0.5,1,...)";
theUILang.ratiocolorLengthError = "Ratiocolor: There must be the same numbers of levels and colors";
theUILang.ratiocolorLevel0 = "Ratiocolor: The first level must be 0";

thePlugins.get("ratiocolor").langLoaded();
9 changes: 9 additions & 0 deletions lang/pt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@


theUILang.ratiocolorName = "Ratiocolor";
theUILang.ratiocolorColors = "Colors in hex sperated by ',' (Format: 0000ff,ff0000,...)";
theUILang.ratiocolorLevels = "Levels seperated by ','. Must start with 0 (Format: 0,0.5,1,...)";
theUILang.ratiocolorLengthError = "Ratiocolor: There must be the same numbers of levels and colors";
theUILang.ratiocolorLevel0 = "Ratiocolor: The first level must be 0";

thePlugins.get("ratiocolor").langLoaded();
9 changes: 9 additions & 0 deletions lang/ru.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@


theUILang.ratiocolorName = "Ratiocolor";
theUILang.ratiocolorColors = "Colors in hex sperated by ',' (Format: 0000ff,ff0000,...)";
theUILang.ratiocolorLevels = "Levels seperated by ','. Must start with 0 (Format: 0,0.5,1,...)";
theUILang.ratiocolorLengthError = "Ratiocolor: There must be the same numbers of levels and colors";
theUILang.ratiocolorLevel0 = "Ratiocolor: The first level must be 0";

thePlugins.get("ratiocolor").langLoaded();
9 changes: 9 additions & 0 deletions lang/sk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@


theUILang.ratiocolorName = "Ratiocolor";
theUILang.ratiocolorColors = "Colors in hex sperated by ',' (Format: 0000ff,ff0000,...)";
theUILang.ratiocolorLevels = "Levels seperated by ','. Must start with 0 (Format: 0,0.5,1,...)";
theUILang.ratiocolorLengthError = "Ratiocolor: There must be the same numbers of levels and colors";
theUILang.ratiocolorLevel0 = "Ratiocolor: The first level must be 0";

thePlugins.get("ratiocolor").langLoaded();
9 changes: 9 additions & 0 deletions lang/sr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@


theUILang.ratiocolorName = "Ratiocolor";
theUILang.ratiocolorColors = "Colors in hex sperated by ',' (Format: 0000ff,ff0000,...)";
theUILang.ratiocolorLevels = "Levels seperated by ','. Must start with 0 (Format: 0,0.5,1,...)";
theUILang.ratiocolorLengthError = "Ratiocolor: There must be the same numbers of levels and colors";
theUILang.ratiocolorLevel0 = "Ratiocolor: The first level must be 0";

thePlugins.get("ratiocolor").langLoaded();
9 changes: 9 additions & 0 deletions lang/tr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@


theUILang.ratiocolorName = "Ratiocolor";
theUILang.ratiocolorColors = "Colors in hex sperated by ',' (Format: 0000ff,ff0000,...)";
theUILang.ratiocolorLevels = "Levels seperated by ','. Must start with 0 (Format: 0,0.5,1,...)";
theUILang.ratiocolorLengthError = "Ratiocolor: There must be the same numbers of levels and colors";
theUILang.ratiocolorLevel0 = "Ratiocolor: The first level must be 0";

thePlugins.get("ratiocolor").langLoaded();
9 changes: 9 additions & 0 deletions lang/uk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@


theUILang.ratiocolorName = "Ratiocolor";
theUILang.ratiocolorColors = "Colors in hex sperated by ',' (Format: 0000ff,ff0000,...)";
theUILang.ratiocolorLevels = "Levels seperated by ','. Must start with 0 (Format: 0,0.5,1,...)";
theUILang.ratiocolorLengthError = "Ratiocolor: There must be the same numbers of levels and colors";
theUILang.ratiocolorLevel0 = "Ratiocolor: The first level must be 0";

thePlugins.get("ratiocolor").langLoaded();
9 changes: 9 additions & 0 deletions lang/vi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@


theUILang.ratiocolorName = "Ratiocolor";
theUILang.ratiocolorColors = "Colors in hex sperated by ',' (Format: 0000ff,ff0000,...)";
theUILang.ratiocolorLevels = "Levels seperated by ','. Must start with 0 (Format: 0,0.5,1,...)";
theUILang.ratiocolorLengthError = "Ratiocolor: There must be the same numbers of levels and colors";
theUILang.ratiocolorLevel0 = "Ratiocolor: The first level must be 0";

thePlugins.get("ratiocolor").langLoaded();
9 changes: 9 additions & 0 deletions lang/zh-cn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@


theUILang.ratiocolorName = "Ratiocolor";
theUILang.ratiocolorColors = "Colors in hex sperated by ',' (Format: 0000ff,ff0000,...)";
theUILang.ratiocolorLevels = "Levels seperated by ','. Must start with 0 (Format: 0,0.5,1,...)";
theUILang.ratiocolorLengthError = "Ratiocolor: There must be the same numbers of levels and colors";
theUILang.ratiocolorLevel0 = "Ratiocolor: The first level must be 0";

thePlugins.get("ratiocolor").langLoaded();
9 changes: 9 additions & 0 deletions lang/zh-tw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@


theUILang.ratiocolorName = "Ratiocolor";
theUILang.ratiocolorColors = "Colors in hex sperated by ',' (Format: 0000ff,ff0000,...)";
theUILang.ratiocolorLevels = "Levels seperated by ','. Must start with 0 (Format: 0,0.5,1,...)";
theUILang.ratiocolorLengthError = "Ratiocolor: There must be the same numbers of levels and colors";
theUILang.ratiocolorLevel0 = "Ratiocolor: The first level must be 0";

thePlugins.get("ratiocolor").langLoaded();
4 changes: 4 additions & 0 deletions plugin.info
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
plugin.description: Change color of ratio column depending on ratio
plugin.author: Gyran
plugin.version: 0.5
plugin.help: http://forums.rutorrent.org/index.php?topic=929.0
Loading

0 comments on commit cc96430

Please sign in to comment.