Greasy Fork

Greasy Fork is available in English.

TMVN League ALI

Trophymanager: calculate ALI (Achievement League Index) and count the championships of teams. So you can easy find rich achievements teams in the countries.

当前为 2020-12-07 提交的版本,查看 最新版本

// ==UserScript==
// @name         TMVN League ALI
// @namespace    https://trophymanager.com
// @version      1
// @description  Trophymanager: calculate ALI (Achievement League Index) and count the championships of teams. So you can easy find rich achievements teams in the countries.
// @match        https://trophymanager.com/league/*
// @grant        none
// ==/UserScript==

(function () {
	'use strict';

	const ALI_MAP = new Map()
		.set("1.1", 5508).set("1.2", 3564).set("1.3", 2355)
		.set("2.1", 510).set("2.2", 330).set("2.3", 218)
		.set("3.1", 68).set("3.2", 44).set("3.3", 29)
		.set("4.1", 14).set("4.2", 9).set("4.3", 6)
		.set("5.1", 5).set("5.2", 3).set("5.3", 2)
		.set("6.1", 4).set("6.2", 2).set("6.3", 1);

	var clubDatas = new Map();
	var clubMap = new Map();
	$('#overall_table td').each(function () {
		let clubId = $(this).children('a').attr('club_link');
		if (clubId) {
			let clubName = $(this).children('a')[0].innerHTML;
			clubMap.set(clubId, clubName);
		}
	});

	clubMap.forEach((value, key) => {
		$.ajax('https://trophymanager.com/history/club/league/' + key, {
			type: "GET",
			dataType: 'html',
			crossDomain: true,
			success: function (response) {
				let trArr = $('.zebra.hover.sortable tr', response);
				var ali = 0;
				var champion = "";
				var seasonCount = 0;
				var championMap = new Map();
				for (var i = 1; i < trArr.length; i++) {
					var rank = trArr[i].lastElementChild.innerText;
					if (rank !== "") {
						seasonCount++;
						var division = trArr[i].children[1].innerText.substring(0, 1);
						if (rank == 1) {
							if (championMap.has(division)) {
								var championCount = championMap.get(division);
								championCount++;
								championMap.set(division, championCount);
							} else {
								championMap.set(division, 1);
							}
						}

						if (rank <= 3 && division <= 3) {
							ali += ALI_MAP.get(division + "." + rank);
						}
					}
				}

				if (championMap.size > 0) {
					var championDivision = [...championMap.keys()].sort();
					championDivision.forEach((div) => {
						champion += (div + "." + championMap.get(div) + " ");
					});
				}

				clubDatas.set(key, {
					"ALI": ali,
					"Champion": champion,
					"SeasonCount": seasonCount
				});
			},
			error: function (e) {}
		});
	});

	var myInterval = setInterval(append, 1000);

	function append() {
		if (clubDatas.size < 18) {
			return;
		}
		clearInterval(myInterval);

		/*APPEND ALI TABLE*/
		let ali =
			"<div class=\"box\">" +
			"<div class=\"box_head\">" +
			"<h2 class=\"std\">Achievement League Index</h2>" +
			"</div>" +
			"<div class=\"box_body\">" +
			"<div class=\"box_shadow\"></div>" +
			"<div id=\"ali_content\" class=\"content_menu\"></div>" +
			"</div>" +
			"<div class=\"box_footer\">" +
			"<div></div>" +
			"</div>" +
			"</div>";
		$(".column3_a").append(ali);

		let ali_content = "<table>" +
			"<tr><th>Club</th><th align='right'>ALI</th><th align='right'>Champion</th></tr>";

		let rowCount = 0;
		clubMap.forEach((value, key) => {
			rowCount++;
			let classOdd = "";
			if ((rowCount % 2) == 1) {
				classOdd = "class='odd'";
			}
			if (clubDatas.has(key)) {
				let clubData = clubDatas.get(key);
				value = '<span style="color:Orange;">' + clubData.SeasonCount + '.</span>' + value;
				ali_content += "<tr " + classOdd + "><td><span onclick = \"window.open(\'https:\/\/trophymanager.com\/history\/club\/league\/" + key + "\')\">" + value + "</span></td><td align='right'>" +
				clubData.ALI.toFixed(0).replace(/\B(?=(\d{3})+(?!\d))/g, ",") +
				"</td><td align='right'><span style='color:Orange;'>" +
				clubData.Champion +
				"</span></td></tr>";
			} else {
				ali_content += "<tr " + classOdd + "><td><span onclick = \"window.open(\'https:\/\/trophymanager.com\/history\/club\/league\/" + key + "\')\">" + value + "</span></td><td></td><td></td></tr>";
			}
		});

		ali_content += "</table>";

		$("#ali_content").append(ali_content);
	}
})();