// ==UserScript== // @name TMVN Cup HOF // @namespace https://trophymanager.com // @version 2 // @description Trophymanager: hall of fame of tournament // @match https://trophymanager.com/history/cup/* // @grant none // @downloadURL none // ==/UserScript== (function () { 'use strict'; var clubChampionMap = new Map(); var clubRunnerUpMap = new Map(); var clubSortMap = new Map(); var clubMap = new Map(); var currentSeason = $('#top_menu a[class="none white small"]')[0].innerText.split(/(\s+)/)[2]; var country = location.href.split('/')[5]; var scanCount = 0; for (var i = currentSeason - 1; i > 0; i--) { $.ajax('https://trophymanager.com/history/cup/' + country + '/' + i, { type: "GET", dataType: 'html', crossDomain: true, success: function (response) { let final = $('.match_list.border_bottom li', response)[0]; if (final) { let aArr = final.querySelectorAll('a'); let leftClubId = aArr[0].getAttribute('club_link'); let leftClubName = aArr[0].innerText; let rightClubId = aArr[2].getAttribute('club_link'); let rightClubName = aArr[2].innerText; if (!clubMap.has(leftClubId)) { clubMap.set(leftClubId, leftClubName); } if (!clubMap.has(rightClubId)) { clubMap.set(rightClubId, rightClubName); } let score = aArr[1].innerText.split('-'); if (score[0] > score[1]) { increaseValueOfMap(clubChampionMap, leftClubId); increaseValueOfMap(clubRunnerUpMap, rightClubId); } else { increaseValueOfMap(clubRunnerUpMap, leftClubId); increaseValueOfMap(clubChampionMap, rightClubId); } } scanCount++; }, error: function (e) {} }); } var myInterval = setInterval(append, 1000); function append() { if (scanCount < currentSeason - 1) { return; } clearInterval(myInterval); for (let[key, value]of clubMap) { let champion = clubChampionMap.get(key) == undefined ? 0 : clubChampionMap.get(key); let runnerUp = clubRunnerUpMap.get(key) == undefined ? 0 : clubRunnerUpMap.get(key); if (champion * 1000 + runnerUp > 0) { clubSortMap.set(key, champion * 1000 + runnerUp); } } clubSortMap[Symbol.iterator] = function * () { yield * [...this.entries()].sort((a, b) => b[1] - a[1]); } /*APPEND HALL OF FAME TABLE*/ let hof = "
" + "
" + "
" + "

HALL OF FAME

" + "
" + "
" + "
" + "
" + "
" + "
" + "
" + "
" + "
" + "
"; if ($('#bteam_reminder').length == 1) { $(".main_center")[3].innerHTML += hof; } else { $(".main_center")[2].innerHTML += hof; } let hof_content = "" + ""; let rowCount = 0; for (let[key, value]of clubSortMap) { rowCount++; let classOdd = ""; if ((rowCount % 2) == 1) { classOdd = "class='odd'"; } let clubName = clubMap.get(key); let championCount = clubChampionMap.get(key); let runnerUpCount = clubRunnerUpMap.get(key); hof_content += "" + "" + "" + "" + "" + ""; } hof_content += "
#ClubChampion2
" + rowCount + "" + clubName + "" + (championCount != undefined ? championCount : "") + "" + (runnerUpCount != undefined ? runnerUpCount : "") + "
"; $("#hof_content").append(hof_content); $('.column3')[0].parentNode.removeChild($('.column3')[0]); } function increaseValueOfMap(map, key) { if (map.has(key)) { let count = map.get(key); count++; map.set(key, count); } else { map.set(key, 1); } } })();