Nexus Clash Improved Pet Status (B4)

Adds color to pet status pane based on remaining AP and displays GMT time of AP decay

目前為 2020-03-25 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name Nexus Clash Improved Pet Status (B4)
// @description Adds color to pet status pane based on remaining AP and displays GMT time of AP decay
// @namespace https://roadha.us
// @author haliphax
// @version 1.1
// @include https://www.nexusclash.com/modules.php?name=Game*
// @include https://nexusclash.com/modules.php?name=Game*
// ==/UserScript==

//------ constants ------

var AP_LOW = 60,  // threshold for "low" AP (yellow)
  AP_VERY_LOW = 30;  // threshold for "very low" AP (red)

//------ process ------

var petRows = [],
    pets = [],
    queryEls = document.querySelectorAll('b'),
    now = new Date();
    lastTick = new Date(now - Math.round(now % (60 * 15 * 1000))),
    petTable = null,
    petHeader = null;

// get pets table
for (var i = 0; i < queryEls.length; i++) {
  var e = queryEls[i];

  if (e.innerHTML == 'ACTIVE PETS') {
    petTable = e.parentNode.parentNode.parentNode;
    petRows = petTable.querySelectorAll('tr:nth-child(n+3)');
    break;
  }
}

// no pets; bail
if (petRows.length === 0)
  return;

// add Decay table header
petHeader = document.createElement('td');
petHeader.innerText = 'Decay';
petTable.querySelector('tr:nth-child(2)').appendChild(petHeader);

// build pets object array
for (var i = 0; i < petRows.length; i++) {
  var el = petRows[i],
      cols = Array.prototype.slice.call(el.querySelectorAll('td:nth-child(n+3)'), 0, 3);

  if (cols.length !== 3)
    continue;

  var p = {
    el: el,
    ap: Math.round(cols[0].innerText),
    mp: Math.round(cols[1].innerText),
    hp: Math.round(cols[2].innerText) 
  };

  pets.push(p);
}

// loop through pets and handle any status events
for (var i = 0; i < pets.length; i++) {
  var p = pets[i],
    decay = document.createElement('td'),
    decayTime = new Date(lastTick),
    decayTimeStr = null;

  // AP check
  if (p.ap <= AP_VERY_LOW)
    p.el.style = 'color:white;background-color:red';
  else if (p.ap <= AP_LOW)
    p.el.style = 'background-color:yellow';

  // show decay time
  decayTime.setMinutes(decayTime.getMinutes() + (p.ap * 15));
  decayTimeStr = decayTime.toUTCString();
  decay.innerText = /(\d+:\d+):\d/.exec(decayTimeStr)[1];
  decay.setAttribute('title', '0 AP at ' + decayTimeStr);
  p.el.appendChild(decay);
}