joyreactor.cc (reactor.cc) Comment Colorizer

Colorizes comments by rating

  1. // ==UserScript==
  2. // @name joyreactor.cc (reactor.cc) Comment Colorizer
  3. // @description Colorizes comments by rating
  4. // @author Sanya_Zol (Alexander Zolotarev)
  5. // @license Public domain
  6. // @icon http://reactor.cc/favicon.ico
  7. // @homepageURL https://greasyfork.org/en/scripts/518-joyreactor-cc-comment-colorizer
  8. // @namespace Sanya_Zol
  9. // @version 0.2.0
  10. // @include http://joyreactor.cc/*
  11. // @include https://joyreactor.cc/*
  12. // @include http://reactor.cc/*
  13. // @include https://reactor.cc/*
  14. // @include http://*.reactor.cc/*
  15. // @include https://*.reactor.cc/*
  16. // @run-at document-end
  17. // @grant none
  18. // ==/UserScript==
  19.  
  20. // old homepage: http://userscripts.org/scripts/show/485580
  21.  
  22. (function(){
  23. var f = function($){
  24. // 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) );};
  25. var ZolCalcColor_max = 255/Math.log(300);
  26. var ZolCalcColor = function(r){
  27. r=Math.round(r*10);
  28. // var sub = (255-Math.min( Math.round( Math.log(Math.abs(r)+1)*ZolCalcColor_max ), 255 )+256).toString(16).substr(1);
  29. var sub = (255-Math.min( Math.round( Math.log(Math.abs(r)+1)*ZolCalcColor_max ), 255 ) );
  30. // return '#'+( (r>0)?(sub+'ff'+sub):('ff'+sub+sub) );
  31. return ( (r>0)?(sub+',255,'+sub):('255,'+sub+','+sub) );
  32. };
  33. var ZolGradient = function(a,gr){
  34. a.css({background:'linear-gradient(to right, rgba('+gr+',0) 0%,rgba('+gr+',0) 1%,rgba('+gr+',1) 80%,rgba('+gr+',1) 100%)',borderRadius:'5px'});
  35. };
  36. var RX = /^\s*(-?\d+\.\d+)\s*$/;
  37. var processFunc = function(){
  38. // $(this).find('div.vote-plus').css({borderRadius:'20px',border:'2px rgb(0,255,0) solid',height:'12px',marginTop:'-5px'});
  39. // $(this).find('div.vote-minus').css({borderRadius:'20px',border:'2px rgb(255,0,0) solid',height:'12px',marginTop:'-5px'});
  40. $(this).find('span.comment_rating').css({"float":'right',fontWeight:'bold',color:'#000'});
  41. $(this).find('div.txt').each(function(){
  42. if( !$(this).data('zol_colorized') ){
  43. $(this).data('zol_colorized',true);
  44. var cr = $(this).find('span.comment_rating > span');
  45. var r = RX.exec( cr.text() );
  46. if( !r ){return;}
  47. r=parseFloat(r[1]);
  48. if(isNaN(r)){return;}
  49. ZolGradient($(this),ZolCalcColor(r));
  50. // $(this).find('div.vote-plus').css({outline:'2px #000 solid',background:'#0F0',fontSize:'16px'}).html('+');
  51. // $(this).find('div.vote-minus').css({outline:'2px #000 solid',background:'#F00',fontSize:'16px'}).html('-');
  52. }
  53. });
  54. };
  55. $(document).on('DOMUpdate','.post_comment_list',function(e){
  56. processFunc.call(e.target);
  57. });
  58. // $('div.comment_list_post').each(processFunc);
  59. $('.post_comment_list').each(processFunc);
  60. };
  61. var f2;
  62. f2 = function(){
  63. if( window.jQuery ){
  64. // jQuery(f);
  65. setTimeout(function(){
  66. jQuery(f);
  67. },200);
  68. } else {
  69. setTimeout(f2,500);
  70. }
  71. };
  72. f2();
  73. })();