Advertisement
Guest User

Untitled

a guest
Jul 30th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. var ratingToInt = function( str ) {
  2. // numstr = ' 18.6k '
  3. str = str.trim(); // "18.6k"
  4.  
  5. var number = parseFloat(str); // 18.6
  6. var letter = str.replace(/[^kmb]/g, '');//"k"
  7.  
  8. switch( letter ) {
  9. case 'k':
  10. number = number * 1000;
  11. break;
  12. case 'm':
  13. number = number * 1000000;
  14. break;
  15. }
  16.  
  17. return parseInt(number);
  18. }
  19.  
  20. var ratingsGetValues = function( $element ) {
  21. var $items = $element.children('li');
  22.  
  23. if ( $items.length < 3 ) return false;
  24.  
  25. var amounts = {
  26. 'up': ratingToInt( $items.eq(0).text() ),
  27. 'down': ratingToInt( $items.eq(1).text() ),
  28. 'play': ratingToInt( $items.eq(2).text() )
  29. };
  30.  
  31. amounts.rating = (amounts.up - amounts.down) / amounts.up;
  32.  
  33. return amounts;
  34. }
  35.  
  36. var updateList = function() {
  37. var $table = jQuery('#search-results-list');
  38. var $rows = $table.find('tr.mission-result-text');
  39.  
  40. $rows.each(function() {
  41. var $row = jQuery(this);
  42. var $ratings = $row.find('ul.ratings');
  43.  
  44. if ( $ratings.find('li.percent').length > 0 ) return;
  45.  
  46. var votes = ratingsGetValues( $ratings );
  47.  
  48. if ( !votes ) {
  49. $rows.css('opacity', '0.5');
  50. return;
  51. }
  52.  
  53. var percent = Math.round(votes.rating * 100);
  54.  
  55. var $percent_li = jQuery('<li class="percent"><i class="gtavicon-icon_star"></i> ' +percent+ '%</li>');
  56.  
  57. $ratings.append( $percent_li );
  58.  
  59. $ratings.css('margin-right', 0);
  60. $ratings.find('li').css({
  61. 'margin-left': '5px',
  62. 'padding-left': '5px'
  63. });
  64.  
  65. var color = '#ffffff';
  66. if ( percent > 90 ) color = '#ffffff';
  67. else if ( percent > 80 ) color = '#7EF654';
  68. else if ( percent > 70 ) color = '#7EF654';
  69. else if ( percent > 50 ) color = '#D6E647';
  70. else if ( percent > 40 ) color = '#DEBC41';
  71. else if ( percent > 25 ) color = '#D6833B';
  72. else if ( percent > 10 ) color = '#cc631B';
  73. else color = '#aa0000';
  74.  
  75. $percent_li.css({
  76. 'color': color,
  77. 'padding-right': '10px'
  78. });
  79. });
  80. };
  81.  
  82. var queueUpdateList = function() {
  83. updateList();
  84. setTimeout( updateList, 1000 );
  85. setTimeout( updateList, 3000 );
  86. setTimeout( updateList, 5000 );
  87. setTimeout( updateList, 10000 );
  88. setTimeout( updateList, 20000 );
  89. setTimeout( updateList, 30000 );
  90. setTimeout( updateList, 40000 );
  91. };
  92.  
  93. jQuery('.search-previous, search-next').on('click', queueUpdateList );
  94. jQuery('#searchFrm').on('submit', queueUpdateList );
  95.  
  96. updateList();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement