NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name bash.im color quotes // @namespace bash.im // @include http://bash.im/* // @version 1 // @grant none // @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js // ==/UserScript== window.addEventListener('load', function() { // to conver date with offset UTC function convertDate(dateString, offsetDiff){ var reggie = /(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2})/; var dateArray = reggie.exec(dateString); var newDate = new Date( (+dateArray[1]), (+dateArray[2])-1, // Careful, month starts at 0! (+dateArray[3]), (+dateArray[4]) - offsetDiff, (+dateArray[5]) ); return newDate; } quote = []; // global variable var todayDate = new Date(); // offset difference var offset = Math.abs(todayDate.getTimezoneOffset())/60; var offsetDiff = 3 - offset; $(".quote").each(function(index) { // rating of quote var quoteRating = $(this).find(".rating").text(); // date of quote var dateString = $(this).find('.date').text(); // skip empty quotes if(!dateString){ quote[index] = 0; return; } // get converted date with offset difference var quoteDate = convertDate(dateString, offsetDiff); // difference between todaydate and quote date var diffMs = (todayDate - quoteDate); var difSec = Math.floor(diffMs / 1000); // diff in seconds var difMin = Math.floor(difSec / 60); // diff in minutes // calculate new rating var newRating; if(isNumeric(quoteRating)){ newRating = Math.floor(quoteRating / difSec * 100000); } else { newRating = 0; } quote[index] = newRating; //---------------------debug--------------------- var datetext = $(this).find('.date').text(); $(this).find('.date').text(datetext + ' (' + difSec + ' sec)'); $(this).find('.date').css("color", "#000"); //------------------------------------------------- }); // get max rating number var maxRating = Math.max.apply(Math, quote); // convert to 100% for (index = 0; index < quote.length; ++index) { quote[index] = Math.floor(quote[index] / maxRating * 100); } // draw $(".quote").each(function(index) { //$(this).find('.date').text(quote[index]); if(quote[index] == 0){ $(this).css("background-color", "#C0C0C0"); }else if(quote[index] <= 10){ $(this).css("background-color", "#B22222"); }else if(quote[index] <= 20){ $(this).css("background-color", "#FF6633"); }else if(quote[index] <= 40){ $(this).css("background-color", "#FF9933"); }else if(quote[index] <= 60){ $(this).css("background-color", "#FFFF66"); }else if(quote[index] <= 80){ $(this).css("background-color", "#ADFF2F"); }else if(quote[index] <= 100){ $(this).css("background-color", "#00FF00"); }else{ $(this).css("background-color", "#C0C0C0"); } //--------------------debug--------------------- var ratingtext = $(this).find(".rating").text(); $(this).find(".rating").text(ratingtext + ' (' + quote[index] + '%)'); $(this).find(".rating").css("width", "auto"); //-------------------------------------------- }); }, false);