Raw Source
Sanya_Zol / joyreactor.cc Comment Colorizer

// ==UserScript==
// @name            joyreactor.cc Comment Colorizer
// @description     Colorizes comments by rating
// @author          Sanya_Zol (Alexander Zolotarev)
// @icon            http://joyreactor.cc/favicon.ico
// @homepageURL     http://userscripts.org/scripts/show/485580
// @downloadURL     http://userscripts.org/scripts/source/485580.user.js
// @updateURL       http://userscripts.org/scripts/source/485580.meta.js
// @namespace       Sanya_Zol
// @version         0.1.0
// @include         http://joyreactor.cc/*
// @run-at          document-end
// @grant           none
// ==/UserScript==

(function(){
	var f = function($){
		// var ZolCalcColor = function(r){var sub = (255-Math.min( Math.round( Math.abs(r)*10 ), 255 )+256).toString(16).substr(1); return '#'+( (r>0)?(sub+'ff'+sub):('ff'+sub+sub) );};
		var ZolCalcColor_max = 255/Math.log(300);
		var ZolCalcColor = function(r){
			r=Math.round(r*10);
			// var sub = (255-Math.min( Math.round( Math.log(Math.abs(r)+1)*ZolCalcColor_max ), 255 )+256).toString(16).substr(1);
			var sub = (255-Math.min( Math.round( Math.log(Math.abs(r)+1)*ZolCalcColor_max ), 255 ) );
			// return '#'+( (r>0)?(sub+'ff'+sub):('ff'+sub+sub) );
			return ( (r>0)?(sub+',255,'+sub):('255,'+sub+','+sub) );
		};
		var ZolGradient = function(a,gr){
			a.css({background:'linear-gradient(to right, rgba('+gr+',0) 0%,rgba('+gr+',0) 20%,rgba('+gr+',1) 98%,rgba('+gr+',1) 100%)'});
		};
		$('div.post_comment_list span.comment_rating').css({"float":'right',fontWeight:'bold',color:'#000'});
		$('div.post_comment_list div.txt').each(function(){
			var cr = $(this).find('span.comment_rating > span');
			var r = cr.html().split(' ',2);
			if(r.length<2){return;}
			r = r[1].replace(/[^0-9.-]+/g,'');
			var R=parseFloat(r);
			cr.html( (R>0)?('+'+r):r );
			if(isNaN(R)){return;}
			ZolGradient($(this),ZolCalcColor(R));
		});
	};
	var f2;
	f2 = function(){
		if( window.jQuery ){
			// jQuery(f);
			setTimeout(function(){
				jQuery(f);
			},200);
		} else {
			setTimeout(f2,500);
		}
	};
	f2();
})();