Nexus Clash Improved Pet Status (B4)

Adds color to pet status pane based on remaining AP

当前为 2020-04-15 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

(function(){
	'use strict';

	// constants
	var LOW_MP = 20;

	var i = 0;

	// get pets table
	var queryEls = document.querySelectorAll('b'),
		petTable = null;

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

		if (e.innerHTML == 'ACTIVE PETS') {
			petTable = e.parentNode.parentNode.parentNode;
			break;
		}
	}

	// no pets; bail
	if (petTable === null) return;

	// add Decay column header
	var petHeader = document.createElement('td');

	petHeader.innerText = 'Decay';
	petTable.querySelector('tr:nth-child(2)').appendChild(petHeader);

	// loop through pets and handle any status events
	var now = new Date(),
		lastTick = new Date(now - Math.round(now % (60 * 15 * 1000))),
		petRows = petTable.querySelectorAll('tr:nth-child(n+3)');

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

		// not a pet row ("Set all pets..."); skip
		if (cols.length !== 3) continue;

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

		// AP check

		if (p.ap <= p.mp /* when AP is less than or equal to MP, pet will expire if it uses all of its attacks */
			|| p.mp < LOW_MP /* low MP is a red flag */)
		{
			el.style = 'color:white;background-color:red';
		}
		else if (p.ap <= p.mp * 2) {
				// when AP is less than or equal to double pet MP, pet will not be able to travel far and still attack */
			el.style = 'background-color:yellow';
		}

		// show decay time
		var decay = document.createElement('td'),
			decayTime = new Date(lastTick),
			decayTimeStr = null;

		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);
		el.appendChild(decay);
	}
}());