Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var ratingToInt = function( str ) {
- // numstr = ' 18.6k '
- str = str.trim(); // "18.6k"
- var number = parseFloat(str); // 18.6
- var letter = str.replace(/[^kmb]/g, '');//"k"
- switch( letter ) {
- case 'k':
- number = number * 1000;
- break;
- case 'm':
- number = number * 1000000;
- break;
- }
- return parseInt(number);
- }
- var ratingsGetValues = function( $element ) {
- var $items = $element.children('li');
- if ( $items.length < 3 ) return false;
- var amounts = {
- 'up': ratingToInt( $items.eq(0).text() ),
- 'down': ratingToInt( $items.eq(1).text() ),
- 'play': ratingToInt( $items.eq(2).text() )
- };
- amounts.rating = (amounts.up - amounts.down) / amounts.up;
- return amounts;
- }
- var updateList = function() {
- var $table = jQuery('#search-results-list');
- var $rows = $table.find('tr.mission-result-text');
- $rows.each(function() {
- var $row = jQuery(this);
- var $ratings = $row.find('ul.ratings');
- if ( $ratings.find('li.percent').length > 0 ) return;
- var votes = ratingsGetValues( $ratings );
- if ( !votes ) {
- $rows.css('opacity', '0.5');
- return;
- }
- var percent = Math.round(votes.rating * 100);
- var $percent_li = jQuery('<li class="percent"><i class="gtavicon-icon_star"></i> ' +percent+ '%</li>');
- $ratings.append( $percent_li );
- $ratings.css('margin-right', 0);
- $ratings.find('li').css({
- 'margin-left': '5px',
- 'padding-left': '5px'
- });
- var color = '#ffffff';
- if ( percent > 90 ) color = '#ffffff';
- else if ( percent > 80 ) color = '#7EF654';
- else if ( percent > 70 ) color = '#7EF654';
- else if ( percent > 50 ) color = '#D6E647';
- else if ( percent > 40 ) color = '#DEBC41';
- else if ( percent > 25 ) color = '#D6833B';
- else if ( percent > 10 ) color = '#cc631B';
- else color = '#aa0000';
- $percent_li.css({
- 'color': color,
- 'padding-right': '10px'
- });
- });
- };
- var queueUpdateList = function() {
- updateList();
- setTimeout( updateList, 1000 );
- setTimeout( updateList, 3000 );
- setTimeout( updateList, 5000 );
- setTimeout( updateList, 10000 );
- setTimeout( updateList, 20000 );
- setTimeout( updateList, 30000 );
- setTimeout( updateList, 40000 );
- };
- jQuery('.search-previous, search-next').on('click', queueUpdateList );
- jQuery('#searchFrm').on('submit', queueUpdateList );
- updateList();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement