BvS Lookup Linkifier

Inserts village lookup link on ninja lookup page.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name           BvS Lookup Linkifier
// @namespace      BvS
// @version        1.2
// @history        1.2 New domain - animecubedgaming.com - Channel28
// @history        1.1 Now https compatible (Updated by Channel28)
// @include        http*://*animecubed.com/billy/bvs/*
// @include        http*://*animecubedgaming.com/billy/bvs/*
// @description    Inserts village lookup link on ninja lookup page.
// @grant          none
// ==/UserScript==

var reVillage = /^(\w[\w\d\s]+) Village$/;

function ecansolLink(name)
{
	var link = document.createElement("a");
	link.href = "http://bvs.ecansol.com/?page=panalyservillage&village=" + escape(name);
	link.setAttribute("style", "font-weight: bold; color: inherit;");
	link.textContent = name + " Village";
	return link;
}

function vlookupLink(name)
{
	var link = document.createElement("a");
	link.href = "vlookup.html?village=" + escape(name);
	link.textContent = name + " Village";
	return link;
}

function villageNameNonKaiju()
{
	var textSnap = document.evaluate("//table/tbody/tr/td/text()", document, null,
			XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
	var txtnode;
	for (var i = 0; txtnode = textSnap.snapshotItem(i); i++)
		if (reVillage.test(txtnode.textContent))
			return {name: RegExp.lastParen, node: txtnode, kaiju: false};
	return null;
}

function villageNameKaiju()
{
	var textSnap = document.evaluate("//table/tbody/tr/td/center/i/i/b/text()", document, null,
			XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
	var txtnode;
	for (var i = 0; txtnode = textSnap.snapshotItem(i); i++)
		if (reVillage.test(txtnode.textContent))
			return {name: RegExp.lastParen, node: txtnode, kaiju: true};
	return null;
}

if (/bvs.lookup\b/.test(location.href)) {
	var village = villageNameNonKaiju() ||  villageNameKaiju();
	if (!village)
		return;

	var link = vlookupLink(village.name);
	if (village.kaiju)
		link.setAttribute("style", "color: white");
	else
		link.setAttribute("style", "color: black");
	village.node.parentNode.replaceChild(link, village.node);

	var link2 = ecansolLink(village.name);
	link2.textContent = "[?]";
	if (link.nextSibling)
		link.parentNode.insertBefore(link2, link.nextSibling);
	else
		link.parentNode.appendChild(link2);
} else if (/bvs.vlookup\b/.test(location.href) || /bvs.village\b/.test(location.href)) {
	var nodes = document.evaluate("//table//td//b", document, null,
		XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);

	for (var i = 0; i < nodes.snapshotLength; i++) {
		var node = nodes.snapshotItem(i);
		var txt = node.textContent;
		if (reVillage.test(txt)) {
			var name = RegExp.lastParen;
			var link = ecansolLink(name);
			node.parentNode.replaceChild(link, node);
			break;
		}
	}
}