ElimLastTick

description

当前为 2021-09-19 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         ElimLastTick
// @namespace    namespace
// @version      0.1
// @description  description
// @author       tos
// @match       *.torn.com/*
// @grant        GM_addStyle
// ==/UserScript==

GM_addStyle(`
#lastTick th {
  font-weight: bold;
}
#lastTick td {
  padding: 0em 1em;
}
`)

const team_names = {
  "Cereal Killers": 'cereal-killers',
  "Chicken Nuggets": 'chicken-nuggets',
  "Dongs": 'dongs',
  "G.O.A.T": 'goat',
  "Illuminati": 'illuminati',
  "Keyboard Warriors": 'keyboard-warriors',
  "Lettuce Win!": 'lettuce-win',
  "Pandemic": 'pandemic',
  "Sea Men": 'sea-men',
  "Short Bus": 'short-bus',
  "Snowflakes": 'snowflakes',
  "Victorious Secret": 'victorious-secret'
}

const eliminated_teams = ["Victorious Secret", "Pandemic", "Snowflakes", "Cereal Killers", "Chicken Nuggets", "Sea Men", "Lettuce Win!"]

const tableHTML = (td, col_labels) => `
<table>
  <tr><th>Teams</th>${col_labels.map(l => `<th>${l[1]}</th>`).join('')}</tr>
  <tr>
    <td></td>
    ${Object.entries(td).map( ([team, scores]) => `<tr>
      <td><i class="elimination-team-logo ${team_names[team]}"></i><i class="elimination-team-name ${team_names[team]}"></i></td>
      ${scores.map(s => `<td>${s}</td>`).join('')}
    </tr>`).join('')}
  </tr>
</table>
`

$( document ).ajaxComplete(function(event, jqXHR, ajaxObj) {
  if(ajaxObj.url.includes('competition.php') && ajaxObj.data?.includes('step=statisticDataset')) {
    const chart_data = JSON.parse(jqXHR.responseText)
    const tab = document.querySelector('LI.ui-tabs-active A').getAttribute('data-single-title')
    if (chart_data && tab) {
      fillTable(chart_data, tab)
    }
  }
})

function last_tick_tables (d) {
  return {
    labels: d.labels.slice(-10),
    ticket: Object.fromEntries(d.tickets.map(team => [team.label, team.data.slice(-10)])),
    life: Object.fromEntries(d.lives.map(team => [team.label, team.data.slice(-10)])),
    win: Object.fromEntries(d.wins.map(team => [team.label, team.data.slice(-10)])),
    lose: Object.fromEntries(d.losses.map(team => [team.label, team.data.slice(-10)]))
  }
}

async function fillTable(d, tab) {
  let lastTickDIV = document.querySelector('#lastTick')
  if (!lastTickDIV) {
    document.querySelector('.statistic-lives-history').insertAdjacentHTML('beforebegin', `<div id="lastTick"></div><hr class="page-head-delimiter m-bottom10">`)
    lastTickDIV = document.querySelector('#lastTick')
  }
  let tables = last_tick_tables(d.statistic)
  Object.keys(tables[tab]).forEach(k => {
    if (eliminated_teams.includes(k)) delete tables[tab][k]
  })
  //console.log(tab, tables)
  lastTickDIV.innerHTML = tableHTML(tables[tab], tables.labels)
}