Skip to content

Instantly share code, notes, and snippets.

@snapcase snapcase/badranks.user.js
Last active Oct 17, 2015

Embed
What would you like to do?
Highlight 'bad' ranks on the Horizon Surf Servers
// ==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
You can’t perform that action at this time.