Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         HotSLogs Extra Data
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.1
  5. // @description  Adds extra columns to HotSLogs data tables
  6. // @author       Jacques Marcotte
  7. // @match        https://www.hotslogs.com/*
  8. // @grant        none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12.     window.addRoS = function() {
  13.         var tables = $('table.rgMasterTable').filter(function(i, table) {
  14.             var found_games_played = false;
  15.             var found_win_percent = false;
  16.             var found_ros = false;
  17.             var header_cells = $(table).find('th');
  18.             header_cells.each(function(i, cell) {
  19.                 var text = $(cell).text().trim();
  20.                 if (text.substr(0,12) == 'Games Played') {
  21.                     found_games_played = true;
  22.                 }
  23.                 if (text == 'Win Percent') {
  24.                     found_win_percent = true;
  25.                 }
  26.                 if (text == 'RoS Win %') {
  27.                     found_ros = true;
  28.                 }
  29.             });
  30.             return found_games_played && found_win_percent && !found_ros;
  31.         });
  32.  
  33.         tables.each(function(i,table) {
  34.             var header_row = $(table).find('thead > tr');
  35.             header_row.append('<th scope="col" class="rgHeader">RoS Win %</th>');
  36.  
  37.             var header_cells = $(table).find('th');
  38.             var games_played_index = null;
  39.             var win_percent_index = null;
  40.             header_cells.each(function(i, cell) {
  41.                 var text = $(cell).text().trim();
  42.                 if (text.substr(0,12) == 'Games Played') {
  43.                     games_played_index = i;
  44.                 }
  45.                 if (text == 'Win Percent') {
  46.                     win_percent_index = i;
  47.                 }
  48.             });
  49.  
  50.             var rows = $(table).find('tr.rgRow,tr.rgAltRow');
  51.             rows.each(function(i,row) {
  52.                 var cells = $(row).find('td');
  53.                 var games_played = parseInt(cells.eq(games_played_index).text(),10);
  54.                 var win_percent = parseFloat(cells.eq(win_percent_index).text(),10);
  55.                 var RoS = (win_percent * games_played + 1 ) / (games_played + 2);
  56.                 var new_cell = document.createElement('td');
  57.                 new_cell.innerHTML = RoS.toFixed(2) + ' %';
  58.                 row.append(new_cell);
  59.             });
  60.         });
  61.     }
  62.  
  63.     // Add a button to the page
  64.     ros_cell = document.createElement('div');
  65.     ros_cell.id = 'ros_cell';
  66.     ros_cell.style = "position:fixed; bottom: 20px; left: 20px; font-size: 14px; cursor: pointer; font-weight: bold";
  67.     ros_cell.innerHTML = "Add<BR>RoS";
  68.     document.body.appendChild(ros_cell);
  69.     $(ros_cell).click(window.addRoS);
  70. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement