// ==UserScript==
// @name KG_JSParser_only_xpress
// @version 1.0.3
// @namespace klavogonki
// @author NIN, kazimur
// @description Скрипт-парсер для Клавогонок
// @include http*://klavogonki.ru/jsparser*
// @grant none
// ==/UserScript==
(function() {
let kgjs_pers_messages = {};
let kgjs_inter_results = [];
let kgjs_total_results = [];
let parse_zip = false;
if (!(location.href.match(/^https?:\/\/klavogonki\.ru\/jsparser.*$/))) return;
console.log("load jsparser_only");
document.title = document.title.replace("Ошибка", "JSParser");
const default_rules = (function() {
let rule_avg_speed = {};
rule_avg_speed.command = "avg_speed";
rule_avg_speed.chat = false;
rule_avg_speed.columns = (table) => {
for (let _id of Object.keys(table)) {
table[_id]["points"] = table[_id]["avg_speed"];
}
let columns=[];
columns.push({"title":"№","data": (x) => x["sort_position"]});
columns.push({"title":"Ник","data": (x) => table.list_get_last_not_none(x["name"]),"add_class":"kgjs-left-align"});
columns.push({"title":"Результат","data": (x) => x["points"].toFixed(2)})
for (const f of table.valid_game_numbers) {
columns.push({"title":f.n.toString()+"\n"+f.gametype.title,"data": (x,_i=f.i) => x["speed"][_i],"game":f.i});
}
return columns;
};
let rule_avg_errors = {};
rule_avg_errors.command = "avg_error_percent";
rule_avg_errors.chat = false;
rule_avg_errors.sort_func = (x) => -x[1]["avg_error_percent"];
rule_avg_errors.columns = (table) => {
for (let _id of Object.keys(table)) {
table[_id]["points"] = table[_id]["avg_error_percent"];
}
let columns=[];
columns.push({"title":"№","data": (x) => x["sort_position"]});
columns.push({"title":"Ник","data": (x) => table.list_get_last_not_none(x["name"]),"add_class":"kgjs-left-align"});
columns.push({"title":"Результат","data": (x) => x["points"].toFixed(2)})
for (const f of table.valid_game_numbers) {
columns.push({"title":f.n.toString()+"\n"+f.gametype.title,"data": (x,_i=f.i) => x["error_percent"][_i],"game":f.i});
}
return columns;
};
// Xpress
function points_for_place(place) {
points = {};
points[1] = 60;
points[2] = 54;
points[3] = 48;
points[4] = 43;
points[5] = 40;
points[6] = 38;
points[7] = 36;
points[8] = 34;
points[9] = 32;
points[10] = 31;
points[11] = 30;
points[12] = 29;
points[13] = 28;
points[14] = 27;
points[15] = 26;
points[16] = 25;
points[17] = 24;
points[18] = 23;
points[19] = 22;
points[20] = 21;
points[21] = 20;
points[22] = 19;
points[23] = 18;
points[24] = 17;
points[25] = 16;
points[26] = 15;
points[27] = 14;
points[28] = 13;
points[29] = 12;
points[30] = 11;
points[31] = 10;
points[32] = 9;
points[33] = 8;
points[34] = 7;
points[35] = 6;
points[36] = 5;
points[37] = 4;
points[38] = 3;
points[39] = 2;
points[40] = 1;
place = parseInt(place);
if ((place<=40) && (place>0))
return points[place];
else
return 0;
}
function rewards_for_place(place) {
let rewards = {};
rewards[1] = 2500;
rewards[2] = 2000;
rewards[3] = 1500;
rewards[4] = 1000;
rewards[5] = 800;
rewards[6] = 600;
place = parseInt(place);
if ((place<=6) && (place>0))
return rewards[place];
else
return 0;
}
let rule_xpress1 = {};
rule_xpress1.command = "xpress1";
rule_xpress1.chat = false;
rule_xpress1.columns = (table) => {
let games_short = [];
let games_usual = [];
for (const f of table.valid_game_numbers) {
if (f.gametype.class == "voc-14878")
games_short.push(f);
if (f.gametype.class == "voc-5539")
games_usual.push(f);
}
for (let _i of table.items(table)) {
let _id = _i[0];
let _value = _i[1];
let sum_points = 0;
let speed = [];
for (let gg of games_short.concat(games_usual)) {
let g = gg.i;
let _place = table[_id]["place"][g];
sum_points += points_for_place(_place);
}
table[_id]["points"] = sum_points;
sum_points = 0;
speed = games_short.map(x => x.i).map(x => table[_id]["speed"][x]);
let avg_speed = table.calc_avg_of_array(speed, 0);
table[_id]["avg_speed_short"] = avg_speed;
sum_points = games_short.map(x => x.i).map(x => points_for_place(table[_id]["place"][x])).reduce((a, b) => a + b, 0);
table[_id]["points_short"] = sum_points;
sum_points = 0;
speed = games_usual.map(x => x.i).map(x => table[_id]["speed"][x]);
avg_speed = table.calc_avg_of_array(speed, 0);
table[_id]["avg_speed_usual"] = avg_speed;
sum_points = games_usual.map(x => x.i).map(x => points_for_place(table[_id]["place"][x])).reduce((a, b) => a + b, 0);
table[_id]["points_usual"] = sum_points;
if (table[_id]["points"] == 0)
delete table[_id];
}
let custom_header = "";
custom_header += ' ';
custom_header += 'Stage 1: sprint