Last active
October 17, 2015 17:35
-
-
Save snapcase/4b8188cb653658ad2326 to your computer and use it in GitHub Desktop.
Highlight 'bad' ranks on the Horizon Surf Servers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Bad Ranks | |
// @namespace http://snapcase.net | |
// @description Highlight bad ranks on the Horizon Surf Servers | |
// @include https://www.horizonservers.net/stats/* | |
// @version 1.7 | |
// @grant none | |
// @require http://www.kryogenix.org/code/browser/sorttable/sorttable.js | |
// ==/UserScript== | |
// text won't fit in divs | |
$('.details').css({fontSize: '1.15em'}); | |
// counters | |
var details = { | |
badranks: { name: 'Bad Ranks', count: 0, color: 'f4f' }, | |
completions: { name: 'Completions', count: 0 } | |
} | |
// sorttable support | |
$('table').addClass('sortable'); | |
// table header | |
$('th.comp').after('<th style="width: 12%" class="badrank">Bad Rank</th>'); | |
// each row | |
$('tbody tr').each(function() { | |
// add td | |
$(this).append('<td style="color: #f4f" class="badrank"></td>'); | |
details.completions.count += parseInt($(this).find('.comp').text()); | |
// determine tier and hide bonus levels | |
var tier = $(this).find('.tier').text(); | |
if (tier == "Bonus") { | |
$(this).hide(); | |
return; | |
} | |
// determine rank and set custom attribute | |
var rank_elem = $(this).find('.rank'); | |
var arr = rank_elem.text().split('/'); | |
var rank = arr[0], total = arr[1]; | |
rank_elem.attr('sorttable_customkey', rank); | |
// check mark bad ranks and set custom attribute | |
if (rank > (total / 2)) { | |
details.badranks.count++; | |
$(this).find('.badrank').text('✓').attr('sorttable_customkey', tier); | |
} | |
}) | |
// generate details | |
function add_to_details(detail) { | |
var color = (detail.hasOwnProperty('color')) ? detail.color : 'ccc'; | |
var name = detail.name | |
var count = detail.count | |
$('.col-xs-5').append("<div class='row'>\n"+ | |
"<div class='col-xs-12'>\n"+ | |
"<div class='type'>"+name+":</div>\n"+ | |
"<div class='data' style='color: #"+color+"'>"+count+"</div>\n"+ | |
"</div>\n</div>"); | |
} | |
// add details | |
for (key in details) { | |
add_to_details(details[key]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment