Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name CF Rating Table
- // @namespace http://codeforces.com/
- // @version 0.1
- // @description try to take over the world!
- // @author PikMike
- // @match http://codeforces.com/group/*/customrating/*
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- function comp(a, b) {
- if (a[0] < b[0]) {
- return -1;
- }
- if (a[0] > b[0]) {
- return 1;
- }
- return 0;
- }
- function calcRating(state){
- var cnt = 0;
- var sum = 0.0;
- for (var i = 4; i < state.children.length; i++){
- var text = state.children[i].innerHTML;
- if (text.indexOf('/') == -1){
- if (text.indexOf('-') != -1)
- continue;
- cnt += 1;
- sum += parseFloat(text.replace(',', '.'));
- }
- else{
- text = text.split('/');
- if (text[0].indexOf('-') != -1)
- continue;
- cnt += 1;
- sum += parseFloat(text[0].replace(',', '.'));
- text = state.children[i].children[0].innerHTML;
- sum += parseFloat(text.replace(',', '.'));
- }
- }
- state.children[2].innerHTML = cnt.toString();
- state.children[3].innerHTML = (cnt === 0 ? 0.0 : sum / cnt).toFixed(2).toString();
- return (cnt === 0 ? 0.0 : sum / cnt);
- }
- var panel = document.getElementsByClassName("datatable")[0];
- var panel2 = panel.children[panel.children.length - 1];
- var tableFull = panel2.children[panel2.children.length - 1];
- var table = tableFull.children[tableFull.children.length - 1];
- var ar = [];
- for (var i = 0; i < table.children.length; i++)
- ar.push([calcRating(table.children[i]), i]);
- ar.sort(comp);
- var newTable = document.createElement("tbody");
- for (var i = ar.length - 1; i >= 0; i--){
- var tmp = table.children[ar[i][1]].cloneNode(true);
- tmp.children[0].innerHTML = (ar.length - i).toString();
- newTable.appendChild(tmp);
- }
- tableFull.removeChild(table);
- tableFull.appendChild(newTable);
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement