TM Compare Others' Players

TrophyManager: Allow managers to compare two other clubs' players

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         TM Compare Others' Players
// @namespace    https://trophymanager.com
// @version      1.0
// @description  TrophyManager: Allow managers to compare two other clubs' players
// @author       UNITE eM (Club ID: 551050)
// @match        https://trophymanager.com/players/*
// @exclude      https://trophymanager.com/players/
// @exclude      https://trophymanager.com/players/compare/*
// @grant        none
// @license      MIT
// ==/UserScript==
 
(function() {
    'use strict';
 
    var playerId = player_id;
    var compareId = -1;
    var isDifferent = false;
 
    var existingEntry = JSON.parse(localStorage.getItem('comparePlayer'));
    if (existingEntry != null) {
        compareId = existingEntry.id;
        if (compareId != playerId) isDifferent = true;
    }
 
    var buttonImage = (playerId == compareId) ? "/pics/mini_green_check.png" : "/pics/icons/pen.gif";
    var buttonText = (playerId == compareId) ? "Added" : "Add to Compare";
    var addCompare =
        "<br><span id=\"addCompare_button\" class=\"button\" style=\"width:170px;\">" +
        "<span class=\"button_border\" style=\"width:168px; padding: 0;\"><img src=\"" + buttonImage + "\">&nbsp;" + buttonText + "</span>" +
        "</span>";
    $("div.column3_a > div:nth-child(2) > div.box_body > div:nth-child(4)").append(addCompare);
 
    if (isDifferent) {
        var compareUrl = "https://trophymanager.com/players/compare/" + playerId + "/" + compareId + "/";
        var compareCountry = existingEntry.country;
        var compareName = existingEntry.name;
        var doCompare =
            "<br><a href=\"" + compareUrl + "\"><span id=\"doCompare_button\" class=\"button\" style=\"width:170px;\">" +
            "<span class=\"button_border\" style=\"width:168px; padding: 0;\">Compare to<br><ib class=\"flag-img-" + compareCountry + " \"></ib>&nbsp;" + compareName + "</span></span>" +
            "</a>";
        $("div.column3_a > div:nth-child(2) > div.box_body > div:nth-child(4)").append(doCompare);
    }
 
    document.getElementById('addCompare_button').addEventListener('click', (e) => {
        addPlayerInfo(playerId);
        if (isDifferent) document.getElementById("doCompare_button").style.display = 'none';
    });
 
    function addPlayerInfo(playerId) {
        var elem = document.getElementById("addCompare_button");
        elem.innerHTML = "<span class=\"button_border\" style=\"width:168px; padding: 0;\"><img src=\"/pics/mini_green_check.png\">&nbsp;Added</span>";
 
        var playerName = player_name;
        if (playerName.length > 18) playerName = playerName.substring(0, 17) + "...";
 
        var playerCountry = player_country;
 
        var entry = {
            id: playerId,
            name: playerName,
            country: playerCountry
        }
        localStorage.setItem('comparePlayer', JSON.stringify(entry));
    }
 
})();