// ==UserScript== // @name TMVN Coefficients Transfer // @namespace https://trophymanager.com // @version 1 // @description Trophymanager: aggregate the amount of money bought and sold players of the highest leagues of the countries. You can configure the number of countries and seasons to aggregate. The larger the number, the slower the performance. This is a gift for Voohan. // @include https://trophymanager.com/international-cup/coefficients/* // @grant none // @downloadURL none // ==/UserScript== (function () { 'use strict'; const APPLICATION_PARAM = { DEFAULT_TOP_COUNT: 10, TOP_COUNT_LOCAL_STORAGE_KEY: "TMVN_COEFFICIENTS_TRANSFER_TOP_COUNT", DEFAULT_SEASON_COUNT: 3, SEASON_COUNT_LOCAL_STORAGE_KEY: "TMVN_COEFFICIENTS_TRANSFER_SEASON_COUNT", } const CONTROL_ID = { INPUT_TOP_COUNT: 'tmvn_coefficients_transfer_script_input_top_count', BUTTON_TOP_COUNT: 'tmvn_coefficients_transfer_script_button_top_count_set', INPUT_SEASON_COUNT: 'tmvn_coefficients_transfer_script_input_season_count', BUTTON_SEASON_COUNT: 'tmvn_coefficients_transfer_script_button_season_count_set', } const APPLICATION_COLOR = { NATIONAL: 'Aqua', SOLD: 'Yellow', } var topCount, seasonCount, currentSeason; topCount = localStorage.getItem(APPLICATION_PARAM.TOP_COUNT_LOCAL_STORAGE_KEY); if (topCount == null || topCount == "") { topCount = APPLICATION_PARAM.DEFAULT_TOP_COUNT; } seasonCount = localStorage.getItem(APPLICATION_PARAM.SEASON_COUNT_LOCAL_STORAGE_KEY); if (seasonCount == null || seasonCount == "") { seasonCount = APPLICATION_PARAM.DEFAULT_SEASON_COUNT; } currentSeason = $('#top_menu a[class="none white small"]')[0].innerText.split(/(\s+)/)[2]; var symbolArr = []; var nationalMap = new Map(); var nationalTrArr = $('div#tab0 table.border_bottom tr'); for (let i = 1; i < nationalTrArr.length; i++) { let tr = nationalTrArr[i]; let symbol = tr.children[1].children[0].href.split('/')[4]; let name = tr.children[1].innerText.trim(); symbolArr.push(symbol); let national = { Name: name, Bought: 0, Sold: 0, } nationalMap.set(symbol, national); } var ajaxCount, ajaxTotal; if (symbolArr.length > 0 && topCount > 0 && seasonCount > 0) { ajaxCount = 0; ajaxTotal = (topCount < symbolArr.length ? topCount : symbolArr.length) * (seasonCount < currentSeason ? seasonCount : currentSeason); for (let i = 0; i < topCount && i < symbolArr.length; i++) { let j = 0; let season = currentSeason; while (j < seasonCount && season > 0) { $.ajax('https://trophymanager.com/history/league/' + symbolArr[i] + '/1/1/transfers/' + season, { type: "GET", dataType: 'html', crossDomain: true, success: function (response) { let bought, sold; let table = $('div.box_body table', response)[2]; let tdArr = $('td', table); bought = tdArr[0].children[0].innerText.replace(/,/g, ''); sold = tdArr[1].children[0].innerText.replace(/,/g, ''); let national = nationalMap.get(symbolArr[i]); national.Bought += Math.round(parseFloat(bought) * 10) / 10; national.Sold += Math.round(parseFloat(sold) * 10) / 10; ajaxCount++; } }); j++; season--; } } } var myInterval = setInterval(append, 1000); function append() { if (!(ajaxTotal > 0 && ajaxCount == ajaxTotal)) { return; } clearInterval(myInterval); present(); try { $('.banner_placeholder.rectangle')[0].parentNode.removeChild($('.banner_placeholder.rectangle')[0]); } catch (err) {} } function present() { let summaryTransfer = "
" + "
" + "

SUMMARY Transfer (M)

" + "
" + "
" + "
" + "
" + "

CONFIG

" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "
" + "" + "" + "Top Count" + "
" + "" + "" + "Season Count" + "
" + "
" + "
" + "
" + "
" + "
"; $(".column3_a").append(summaryTransfer); /*** TOP COUNT ***/ document.getElementById(CONTROL_ID.BUTTON_TOP_COUNT).addEventListener('click', (e) => { setTopCount(); }); $('#' + CONTROL_ID.INPUT_TOP_COUNT).val(topCount); /*********/ /*** SEASON COUNT ***/ document.getElementById(CONTROL_ID.BUTTON_SEASON_COUNT).addEventListener('click', (e) => { setSeasonCount(); }); $('#' + CONTROL_ID.INPUT_SEASON_COUNT).val(seasonCount); /*********/ showSummaryTransfer(); } function showSummaryTransfer() { var content = "" + ""; let rowCount = 0; for (let i = 0; i < topCount && i < symbolArr.length; i++) { let national = nationalMap.get(symbolArr[i]); rowCount++; let classOdd = ""; if ((rowCount % 2) == 1) { classOdd = "class='odd'"; } content += ''; } content += "
#NationalBoughtSoldBalance
' + (i + 1) + '. ' + '' + national.Name + '' + national.Bought.toFixed(1).replace(/\B(?=(\d{3})+(?!\d))/g, ",") + '' + national.Sold.toFixed(1).replace(/\B(?=(\d{3})+(?!\d))/g, ",") + '' + (national.Bought - national.Sold).toFixed(1).replace(/\B(?=(\d{3})+(?!\d))/g, ",") + '
"; $("#summaryTransfer_content").append(content); } function setTopCount() { let topCount = $('#' + CONTROL_ID.INPUT_TOP_COUNT)[0].value; if (topCount == '') { localStorage.removeItem(APPLICATION_PARAM.TOP_COUNT_LOCAL_STORAGE_KEY); } else if (isNaN(topCount) || topCount <= 0) { alert('Top count must be positive integer'); } else { localStorage.setItem(APPLICATION_PARAM.TOP_COUNT_LOCAL_STORAGE_KEY, topCount); alert('Set successful, please refresh'); } } function setSeasonCount() { let seasonCount = $('#' + CONTROL_ID.INPUT_SEASON_COUNT)[0].value; if (seasonCount == '') { localStorage.removeItem(APPLICATION_PARAM.SEASON_COUNT_LOCAL_STORAGE_KEY); } else if (isNaN(seasonCount) || seasonCount <= 0) { alert('Season count must be positive integer'); } else { localStorage.setItem(APPLICATION_PARAM.SEASON_COUNT_LOCAL_STORAGE_KEY, seasonCount); alert('Set successful, please refresh'); } } })();