From 74c700972e34409588faf95be01fab51244a946c Mon Sep 17 00:00:00 2001 From: kauefelipe Date: Thu, 2 Jul 2020 02:27:44 +0000 Subject: [PATCH 1/5] MaxTools (Module to show last match U20/U21/Senior) --- Info.plist | 2 + content/background.html | 4 +- content/foxtrick.properties | 19 +++ content/information-aggregation/maxtools.js | 146 ++++++++++++++++++++ content/preferences.html | 6 +- defaults/preferences/foxtrick.js | 2 + manifest.json | 4 +- modules | 1 + 8 files changed, 177 insertions(+), 7 deletions(-) create mode 100644 content/information-aggregation/maxtools.js diff --git a/Info.plist b/Info.plist index a6ec166ed2..12f0d30127 100644 --- a/Info.plist +++ b/Info.plist @@ -156,6 +156,7 @@ a good reason to. They are for version bumps in Makefile. content/information-aggregation/htms-points.js content/information-aggregation/last-login.js content/information-aggregation/match-weather.js + content/information-aggregation/maxtools.js content/information-aggregation/my-monitor.js content/information-aggregation/nt-peek.js content/information-aggregation/player-birthday.js @@ -299,6 +300,7 @@ a good reason to. They are for version bumps in Makefile. www.fantamondi.it pastebin.com api.openweathermap.org + ht-mt.org Include Secure Pages diff --git a/content/background.html b/content/background.html index 4cc10b4d55..b7a61c3b01 100644 --- a/content/background.html +++ b/content/background.html @@ -1,4 +1,4 @@ - + @@ -104,6 +104,7 @@ + @@ -217,7 +218,6 @@ - diff --git a/content/foxtrick.properties b/content/foxtrick.properties index 42a5ca1057..b267ae4027 100644 --- a/content/foxtrick.properties +++ b/content/foxtrick.properties @@ -2090,3 +2090,22 @@ CopyLeagueStatsAd.maxstats=maximum statistics CopyLeagueStatsAd.avgstats=average statistics CopyFinancesAd.copy=Copy economy report to cliboard CopyFinancesAd.copied=The economy report has been copied to the clipboard. + +# MaxTools +module.Maxtools.desc=Show last match U20/U21/Senior +module.Maxtools.RomanNumberEdition.desc=Use Roman numerals in the championship edition + +MaxTools.match=Match %1 of %2 +MaxTools.edition=Edition +MaxTools.lastMatch=Last match + +# %1 = MaxTools.title +# %2 = type, e.g. U20, U21, Senior +# %3 = scheduler, e.g. New or Old +# %4 = MaxTools.edition +# %5 = WC number, e.g. XIV +# %6 = phase, e.g. CC +# %7 = MaxTools.match +MaxTools.templateWithoutTable=%1: %2(%3) - %4 %5 - %6 - %7 +MaxTools.eligibilityTitle=U20/U21/Senior Eligibility (MaxTools) +MaxTools.eligibilityText=This player will be able to play: diff --git a/content/information-aggregation/maxtools.js b/content/information-aggregation/maxtools.js new file mode 100644 index 0000000000..f9b7db0681 --- /dev/null +++ b/content/information-aggregation/maxtools.js @@ -0,0 +1,146 @@ +/** + * maxtools.js + * Shows which would be the last official u20/u21 match of a certain player. + * @author: KaueFelipeBR, MaxDareDevil + */ + +'use strict'; + +/* eslint-disable no-magic-numbers */ + +Foxtrick.modules.Maxtools = { + MODULE_CATEGORY: Foxtrick.moduleCategories.INFORMATION_AGGREGATION, + PAGES: [ + 'youthPlayerDetails', 'playerDetails', + 'allPlayers', 'youthPlayers', + 'transferSearchResult', + ], + OPTIONS: ['RomanNumberEdition'], + + /** @param {document} doc */ + // eslint-disable-next-line complexity + run: function (doc) { + const module = this; + + var isYouthPlayerDetailsPage = Foxtrick.isPage(doc, 'youthPlayerDetails'); + var isSeniorPlayerDetailsPage = Foxtrick.isPage(doc, 'playerDetails'); + var isPlayersPage = Foxtrick.isPage(doc, 'allPlayers'); + var isYouthPlayersPage = Foxtrick.isPage(doc, 'youthPlayers'); + var isTransferResultsPage = Foxtrick.isPage(doc, 'transferSearchResult'); + + ////var isYouthEnabled = Foxtrick.Prefs.isModuleOptionEnabled(module, 'YouthPlayers'); + ////var isSeniorsEnabled = Foxtrick.Prefs.isModuleOptionEnabled(module, 'SeniorPlayers'); + ////var isPlayersEnabled = Foxtrick.Prefs.isModuleOptionEnabled(module, 'AllPlayers'); + ////var isTransferEnabled = Foxtrick.Prefs.isModuleOptionEnabled(module, 'TransfersResults'); + + + //// If the option isn't enabled for this page, don't show. + //if (isYouthPlayerDetailsPage && !isYouthEnabled) + // return; + //if (isSeniorPlayerDetailsPage && !isSeniorsEnabled) + // return; + //if (isPlayersPage && !isPlayersEnabled) + // return; + //if (isTransferResultsPage && !isTransferEnabled) + // return; + + if (isYouthPlayerDetailsPage || isSeniorPlayerDetailsPage) { + module.runPlayer(doc); + } + + + //else if (isPlayersPage || isYouthPlayersPage) + // module.runPlayerList(doc); + //else if (isTransferResultsPage) + // module.runTransferList(doc); + }, + + /** + * @typedef MaxToolPerfectAge + * @prop {string} type + * @prop {string} scheduler + * @prop {number} edition + * @prop {string} phase + * @prop {number} match + * @prop {number} last_phase_match + * @prop {number} training_weeks + */ + + /** + * @param {string} text + * @return {Array} + */ + buildMaxToolPerfectAge: function (text) { + const module = this; + + /** @type {Array} */ + var champsList = JSON.parse(text); + return champsList; + }, + + /** @param {document} doc */ + runPlayer: function (doc) { + const module = this; + + const TITLE_STR = Foxtrick.L10n.getString('MaxTools.eligibilityTitle'); + const EDITION_STR = Foxtrick.L10n.getString('MaxTools.edition'); + const MATCH_STR = Foxtrick.L10n.getString('MaxTools.match'); + const TMPL_STR = Foxtrick.L10n.getString('MaxTools.templateWithoutTable'); + const LAST_MATCH_STR = Foxtrick.L10n.getString('MaxTools.lastMatch'); + + var isRomanNumberEditionEnabled = Foxtrick.Prefs.isModuleOptionEnabled(module, 'RomanNumberEdition'); + + if (Foxtrick.Pages.Player.wasFired(doc)) + return; + + let age = Foxtrick.Pages.Player.getAge(doc); + + const HTMT_PATH = 'https://ht-mt.org'; + var url = `${HTMT_PATH}/maxtools-api/perfect-age/${age.years}/${age.days}`; + + console.log("vou chamar " + url); + Foxtrick.load(url).then(function (r) { + var text = /** @type {string} */ (r); + console.log(text); + let champsList = module.buildMaxToolPerfectAge(text); + console.log(champsList); + + let entryPoint = + doc.querySelector('#mainBody > .mainBox') || + doc.querySelector('#mainBody > .playerInfo'); + + let wrapper = Foxtrick.createFeaturedElement(doc, module, 'div'); + Foxtrick.addClass(wrapper, 'mainBox'); + let titleElement = doc.createElement('h2'); + titleElement.textContent = TITLE_STR; + wrapper.appendChild(titleElement); + + + champsList.forEach(function (championship) { + if (Object.keys(championship).length !== 0) { + let editionNum = isRomanNumberEditionEnabled ? Foxtrick.decToRoman(championship.edition) : championship.edition; + + let lastMatch = MATCH_STR.replace(/%1/, championship.match.toString()); + lastMatch = lastMatch.replace(/%2/, championship.last_phase_match.toString()); + + let contentChamp = TMPL_STR; + contentChamp = contentChamp.replace(/%1/, LAST_MATCH_STR); + contentChamp = contentChamp.replace(/%2/, championship.type); + contentChamp = contentChamp.replace(/%3/, championship.scheduler); + contentChamp = contentChamp.replace(/%4/, EDITION_STR); + contentChamp = contentChamp.replace(/%5/, editionNum); + contentChamp = contentChamp.replace(/%6/, championship.phase); + contentChamp = contentChamp.replace(/%7/, lastMatch); + + let textElement = doc.createElement('div'); + textElement.textContent = contentChamp; + wrapper.appendChild(textElement); + } + }); + + entryPoint.parentNode.insertBefore(wrapper, entryPoint.nextSibling); + }, (er) => { + console.log(er); + }).catch(Foxtrick.catch(module)); + }, +}; diff --git a/content/preferences.html b/content/preferences.html index 36326f7c5d..3f0e6450a1 100644 --- a/content/preferences.html +++ b/content/preferences.html @@ -1,4 +1,4 @@ - + @@ -62,7 +62,6 @@ - @@ -71,7 +70,6 @@ - @@ -112,6 +110,7 @@ + @@ -225,7 +224,6 @@ - diff --git a/defaults/preferences/foxtrick.js b/defaults/preferences/foxtrick.js index 03e977edb6..205cace8ef 100644 --- a/defaults/preferences/foxtrick.js +++ b/defaults/preferences/foxtrick.js @@ -292,6 +292,8 @@ pref("extensions.foxtrick.prefs.module.MatchReportFormat.ShowEventIcons.enabled" pref("extensions.foxtrick.prefs.module.LiveMatchReportFormat.enabled", true); pref("extensions.foxtrick.prefs.module.MatchWeather.enabled", true); pref("extensions.foxtrick.prefs.module.MatchWeather.Irl.enabled", true); +pref("extensions.foxtrick.prefs.module.Maxtools.enabled", true); +pref("extensions.foxtrick.prefs.module.Maxtools.RomanNumberEdition.enabled", true); pref("extensions.foxtrick.prefs.module.MoveLinks.enabled", false); pref("extensions.foxtrick.prefs.module.MoveManagerOnline.enabled", false); pref("extensions.foxtrick.prefs.module.MovePlayerSelectbox.enabled", false); diff --git a/manifest.json b/manifest.json index 5ffc1a714b..ea5156fea6 100644 --- a/manifest.json +++ b/manifest.json @@ -141,6 +141,7 @@ "content/information-aggregation/htms-points.js", "content/information-aggregation/last-login.js", "content/information-aggregation/match-weather.js", + "content/information-aggregation/maxtools.js", "content/information-aggregation/my-monitor.js", "content/information-aggregation/nt-peek.js", "content/information-aggregation/player-birthday.js", @@ -287,7 +288,8 @@ "*://chpp.hattrick.org/*", "*://*.foxtrick.org/*", "http://www.fantamondi.it/*", - "http://pastebin.com/api/*" + "http://pastebin.com/api/*", + "https://ht-mt.org/*" ], "optional_permissions": [ "https://*.hattrick-youthclub.org/*", diff --git a/modules b/modules index 3cb3e51967..de43c96cc7 100644 --- a/modules +++ b/modules @@ -37,6 +37,7 @@ information-aggregation/history-stats.js information-aggregation/htms-points.js information-aggregation/last-login.js information-aggregation/match-weather.js +information-aggregation/maxtools.js information-aggregation/my-monitor.js information-aggregation/nt-peek.js information-aggregation/player-birthday.js From 08d1cf9169022b70e51e1d0c1334dda370067c55 Mon Sep 17 00:00:00 2001 From: kauefelipe Date: Thu, 30 Jul 2020 04:15:48 +0000 Subject: [PATCH 2/5] MaxTools (Module to show last match U20/U21/Senior) --- content/foxtrick.properties | 13 ++ content/information-aggregation/maxtools.js | 195 ++++++++++++++++---- defaults/preferences/foxtrick.js | 4 + 3 files changed, 179 insertions(+), 33 deletions(-) diff --git a/content/foxtrick.properties b/content/foxtrick.properties index b267ae4027..75e1c44d09 100644 --- a/content/foxtrick.properties +++ b/content/foxtrick.properties @@ -2094,7 +2094,13 @@ CopyFinancesAd.copied=The economy report has been copied to the clipboard. # MaxTools module.Maxtools.desc=Show last match U20/U21/Senior module.Maxtools.RomanNumberEdition.desc=Use Roman numerals in the championship edition +module.Maxtools.YouthPlayers.desc=Show last match U20/U21/Senior in the Youth Player Details page. +module.Maxtools.SeniorPlayers.desc=Show last match U20/U21/Senior in the Senior Player Details page. +module.Maxtools.AllPlayers.desc=Show last match U20/U21/Senior in the Senior/Youth/NT Players page. +module.Maxtools.TransfersResults.desc=Show last match U20/U21/Senior in the Transfers Search Results page. +MaxTools=MaxTools: +MaxTools.MoreDetails=(more details) MaxTools.match=Match %1 of %2 MaxTools.edition=Edition MaxTools.lastMatch=Last match @@ -2109,3 +2115,10 @@ MaxTools.lastMatch=Last match MaxTools.templateWithoutTable=%1: %2(%3) - %4 %5 - %6 - %7 MaxTools.eligibilityTitle=U20/U21/Senior Eligibility (MaxTools) MaxTools.eligibilityText=This player will be able to play: + +# %1 = type, e.g. U20, U21, Senior +# %2 = phase, e.g. CC +# %3 = WC number, e.g. XIV +# %4 = MaxTools.match +U21 - WC RI XXXIII - 6/10 +MaxTools.templateShortWithoutTable=%1 - %2 %3 - %4 diff --git a/content/information-aggregation/maxtools.js b/content/information-aggregation/maxtools.js index f9b7db0681..1c35f0a04b 100644 --- a/content/information-aggregation/maxtools.js +++ b/content/information-aggregation/maxtools.js @@ -14,8 +14,10 @@ Foxtrick.modules.Maxtools = { 'youthPlayerDetails', 'playerDetails', 'allPlayers', 'youthPlayers', 'transferSearchResult', - ], - OPTIONS: ['RomanNumberEdition'], + ], + OPTIONS: ['RomanNumberEdition', 'YouthPlayers', 'SeniorPlayers', 'AllPlayers'], + + /** @param {document} doc */ // eslint-disable-next-line complexity @@ -28,31 +30,29 @@ Foxtrick.modules.Maxtools = { var isYouthPlayersPage = Foxtrick.isPage(doc, 'youthPlayers'); var isTransferResultsPage = Foxtrick.isPage(doc, 'transferSearchResult'); - ////var isYouthEnabled = Foxtrick.Prefs.isModuleOptionEnabled(module, 'YouthPlayers'); - ////var isSeniorsEnabled = Foxtrick.Prefs.isModuleOptionEnabled(module, 'SeniorPlayers'); - ////var isPlayersEnabled = Foxtrick.Prefs.isModuleOptionEnabled(module, 'AllPlayers'); - ////var isTransferEnabled = Foxtrick.Prefs.isModuleOptionEnabled(module, 'TransfersResults'); - - - //// If the option isn't enabled for this page, don't show. - //if (isYouthPlayerDetailsPage && !isYouthEnabled) - // return; - //if (isSeniorPlayerDetailsPage && !isSeniorsEnabled) - // return; - //if (isPlayersPage && !isPlayersEnabled) - // return; - //if (isTransferResultsPage && !isTransferEnabled) - // return; + var isYouthEnabled = Foxtrick.Prefs.isModuleOptionEnabled(module, 'YouthPlayers'); + var isSeniorsEnabled = Foxtrick.Prefs.isModuleOptionEnabled(module, 'SeniorPlayers'); + var isPlayersEnabled = Foxtrick.Prefs.isModuleOptionEnabled(module, 'AllPlayers'); + var isTransferEnabled = Foxtrick.Prefs.isModuleOptionEnabled(module, 'TransfersResults'); + + + // If the option isn't enabled for this page, don't show. + if (isYouthPlayerDetailsPage && !isYouthEnabled) + return; + if (isSeniorPlayerDetailsPage && !isSeniorsEnabled) + return; + if (isPlayersPage && !isPlayersEnabled) + return; + if (isTransferResultsPage && !isTransferEnabled) + return; if (isYouthPlayerDetailsPage || isSeniorPlayerDetailsPage) { module.runPlayer(doc); } - - - //else if (isPlayersPage || isYouthPlayersPage) - // module.runPlayerList(doc); - //else if (isTransferResultsPage) - // module.runTransferList(doc); + else if (isPlayersPage || isYouthPlayersPage) + module.runPlayerList(doc); + else if (isTransferResultsPage) + module.runTransferList(doc); }, /** @@ -71,9 +71,6 @@ Foxtrick.modules.Maxtools = { * @return {Array} */ buildMaxToolPerfectAge: function (text) { - const module = this; - - /** @type {Array} */ var champsList = JSON.parse(text); return champsList; }, @@ -88,22 +85,43 @@ Foxtrick.modules.Maxtools = { const TMPL_STR = Foxtrick.L10n.getString('MaxTools.templateWithoutTable'); const LAST_MATCH_STR = Foxtrick.L10n.getString('MaxTools.lastMatch'); - var isRomanNumberEditionEnabled = Foxtrick.Prefs.isModuleOptionEnabled(module, 'RomanNumberEdition'); + var isRomanNumberEditionEnabled = Foxtrick.Prefs.isModuleOptionEnabled(module, 'RomanNumberEdition'); + + /** + * @param {number} years + * @param {number} days + * @return {HTMLAnchorElement} + */ + var getLink = function (years, days) { + //console.log('chegou aqui'); + let lang = Foxtrick.Prefs.getString('htLanguage'); + //let prefix = 'http://www.fantamondi.it/HTMS/index.php' + + // `?page=htmspoints&lang=${lang}&action=calc`; + let prefix = 'https://ht-mt.org/nt/perfect-age'; + let skillQuery = `?lang=${lang}&years=${years}&days=${days}`; + + let link = doc.createElement('a'); + link.textContent = Foxtrick.L10n.getString('MaxTools.MoreDetails'); + link.href = prefix + skillQuery; + link.target = '_blank'; + link.rel = 'noopener'; + return link; + } if (Foxtrick.Pages.Player.wasFired(doc)) return; - let age = Foxtrick.Pages.Player.getAge(doc); + let age = Foxtrick.Pages.Player.getAge(doc); const HTMT_PATH = 'https://ht-mt.org'; var url = `${HTMT_PATH}/maxtools-api/perfect-age/${age.years}/${age.days}`; - console.log("vou chamar " + url); + //console.log("vou chamar " + url); Foxtrick.load(url).then(function (r) { var text = /** @type {string} */ (r); - console.log(text); + //console.log(text); let champsList = module.buildMaxToolPerfectAge(text); - console.log(champsList); + //console.log(champsList); let entryPoint = doc.querySelector('#mainBody > .mainBox') || @@ -113,8 +131,10 @@ Foxtrick.modules.Maxtools = { Foxtrick.addClass(wrapper, 'mainBox'); let titleElement = doc.createElement('h2'); titleElement.textContent = TITLE_STR; - wrapper.appendChild(titleElement); + //titleElement.appendChild(getLink(age.years, age.days)); + + wrapper.appendChild(titleElement); champsList.forEach(function (championship) { if (Object.keys(championship).length !== 0) { @@ -128,7 +148,7 @@ Foxtrick.modules.Maxtools = { contentChamp = contentChamp.replace(/%2/, championship.type); contentChamp = contentChamp.replace(/%3/, championship.scheduler); contentChamp = contentChamp.replace(/%4/, EDITION_STR); - contentChamp = contentChamp.replace(/%5/, editionNum); + contentChamp = contentChamp.replace(/%5/, editionNum.toString()); contentChamp = contentChamp.replace(/%6/, championship.phase); contentChamp = contentChamp.replace(/%7/, lastMatch); @@ -138,9 +158,118 @@ Foxtrick.modules.Maxtools = { } }); + let textElement = doc.createElement('div'); + textElement.appendChild(getLink(age.years, age.days)); + wrapper.appendChild(textElement); + entryPoint.parentNode.insertBefore(wrapper, entryPoint.nextSibling); }, (er) => { console.log(er); }).catch(Foxtrick.catch(module)); }, + + /** @param {document} doc */ + runPlayerList: function (doc) { + const module = this; + + const TITLE_STR = Foxtrick.L10n.getString('MaxTools.eligibilityTitle'); + const EDITION_STR = Foxtrick.L10n.getString('MaxTools.edition'); + const MATCH_STR = Foxtrick.L10n.getString('MaxTools.match'); + const TMPL_STR_SHORT = Foxtrick.L10n.getString('MaxTools.templateShortWithoutTable'); + const LAST_MATCH_STR = Foxtrick.L10n.getString('MaxTools.lastMatch'); + + var isRomanNumberEditionEnabled = Foxtrick.Prefs.isModuleOptionEnabled(module, 'RomanNumberEdition'); + + /** + * @param {number} years + * @param {number} days + * @return {HTMLAnchorElement} + */ + var getLink = function (years, days) { + //console.log('chegou aqui'); + let lang = Foxtrick.Prefs.getString('htLanguage'); + //let prefix = 'http://www.fantamondi.it/HTMS/index.php' + + // `?page=htmspoints&lang=${lang}&action=calc`; + let prefix = 'https://ht-mt.org/nt/perfect-age'; + let skillQuery = `?lang=${lang}&years=${years}&days=${days}`; + + let link = doc.createElement('a'); + link.textContent = Foxtrick.L10n.getString('MaxTools'); + link.href = prefix + skillQuery; + link.target = '_blank'; + link.rel = 'noopener'; + return link; + } + + let players = Foxtrick.modules.Core.getPlayerList(); + for (let player of players) { + + const HTMT_PATH = 'https://ht-mt.org'; + var url = `${HTMT_PATH}/maxtools-api/perfect-age/${player.age.years}/${player.age.days}`; + + Foxtrick.load(url).then(function (r) { + var text = /** @type {string} */ (r); + let champsList = module.buildMaxToolPerfectAge(text); + + let container = Foxtrick.createFeaturedElement(doc, module, 'p'); + Foxtrick.addClass(container, 'ft-u20lastmatch'); + container.appendChild(getLink(player.age.years, player.age.days)); + container.appendChild(doc.createTextNode(' ')); + + + champsList.forEach(function (championship) { + if (Object.keys(championship).length !== 0) { + let editionNum = isRomanNumberEditionEnabled ? Foxtrick.decToRoman(championship.edition) : championship.edition; + + //let lastMatch = championship.match.toString() + "/" + championship.last_phase_match.toString(); + let lastMatch = MATCH_STR.replace(/%1/, championship.match.toString()); + lastMatch = lastMatch.replace(/%2/, championship.last_phase_match.toString()); + + let contentChamp = TMPL_STR_SHORT; + contentChamp = contentChamp.replace(/%1/, championship.type); + contentChamp = contentChamp.replace(/%2/, championship.phase); + contentChamp = contentChamp.replace(/%3/, editionNum.toString()); + contentChamp = contentChamp.replace(/%4/, lastMatch); + + let champDiv = doc.createElement('div'); + champDiv.textContent = contentChamp; + container.appendChild(champDiv); + } + }); + + let entry = player.playerNode.querySelector('table') || player.playerNode.lastChild; + while (entry.parentElement && entry.parentElement.matches('.flex')) + entry = entry.parentElement; + + Foxtrick.insertAfter(container, entry); + }, (er) => { + console.log(er); + }).catch(Foxtrick.catch(module)); + //if (player.age.years > 20) + // continue; + + //let { worldCupNumber, lastMatch, matchNumber, dateWhen21 } = + // module.calculate(doc, player.age); + + //let wcNum = Foxtrick.decToRoman(worldCupNumber); + + //let text = TMPL_STR; + //text = text.replace(/%1/, TITLE_STR); + //text = text.replace(/%2/, WC_STR); + //text = text.replace(/%3/, wcNum); + //text = text.replace(/%4/, lastMatch); + + //let container = Foxtrick.createFeaturedElement(doc, module, 'p'); + //Foxtrick.addClass(container, 'ft-u20lastmatch'); + //container.textContent = text; + //container.dataset.value = String(dateWhen21.getTime()); + //container.dataset.valueString = `${wcNum}:${matchNumber}`; + + //let entry = player.playerNode.querySelector('table') || player.playerNode.lastChild; + //while (entry.parentElement && entry.parentElement.matches('.flex')) + // entry = entry.parentElement; + + //Foxtrick.insertAfter(container, entry); + } + }, }; diff --git a/defaults/preferences/foxtrick.js b/defaults/preferences/foxtrick.js index 205cace8ef..fdf5313df6 100644 --- a/defaults/preferences/foxtrick.js +++ b/defaults/preferences/foxtrick.js @@ -294,6 +294,10 @@ pref("extensions.foxtrick.prefs.module.MatchWeather.enabled", true); pref("extensions.foxtrick.prefs.module.MatchWeather.Irl.enabled", true); pref("extensions.foxtrick.prefs.module.Maxtools.enabled", true); pref("extensions.foxtrick.prefs.module.Maxtools.RomanNumberEdition.enabled", true); +pref("extensions.foxtrick.prefs.module.Maxtools.YouthPlayers.enabled", true); +pref("extensions.foxtrick.prefs.module.Maxtools.SeniorPlayers.enabled", true); +pref("extensions.foxtrick.prefs.module.Maxtools.AllPlayers.enabled", true); +pref("extensions.foxtrick.prefs.module.Maxtools.TransfersResults.enabled", true); pref("extensions.foxtrick.prefs.module.MoveLinks.enabled", false); pref("extensions.foxtrick.prefs.module.MoveManagerOnline.enabled", false); pref("extensions.foxtrick.prefs.module.MovePlayerSelectbox.enabled", false); From 2bc5370660bbd55d4e5a3c80d8d00e3a9daba876 Mon Sep 17 00:00:00 2001 From: kauefelipe Date: Fri, 31 Jul 2020 02:54:39 +0000 Subject: [PATCH 3/5] MaxTools (Module to show last match U20/U21/Senior) --- content/foxtrick.properties | 19 ++++++++-------- content/information-aggregation/maxtools.js | 24 ++++++++++++--------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/content/foxtrick.properties b/content/foxtrick.properties index 75e1c44d09..22d79bcf07 100644 --- a/content/foxtrick.properties +++ b/content/foxtrick.properties @@ -2105,20 +2105,21 @@ MaxTools.match=Match %1 of %2 MaxTools.edition=Edition MaxTools.lastMatch=Last match -# %1 = MaxTools.title +# %1 = MaxTools.lastMatch # %2 = type, e.g. U20, U21, Senior # %3 = scheduler, e.g. New or Old # %4 = MaxTools.edition # %5 = WC number, e.g. XIV # %6 = phase, e.g. CC # %7 = MaxTools.match -MaxTools.templateWithoutTable=%1: %2(%3) - %4 %5 - %6 - %7 -MaxTools.eligibilityTitle=U20/U21/Senior Eligibility (MaxTools) +MaxTools.templateWithoutTable=%1: %2 (%3) - %4 %5 - %6 - %7 +MaxTools.eligibilityTitle=MaxTools +MaxTools.eligibilitySubtitle=NT Eligibility MaxTools.eligibilityText=This player will be able to play: -# %1 = type, e.g. U20, U21, Senior -# %2 = phase, e.g. CC -# %3 = WC number, e.g. XIV -# %4 = MaxTools.match -U21 - WC RI XXXIII - 6/10 -MaxTools.templateShortWithoutTable=%1 - %2 %3 - %4 +# %1 = MaxTools.lastMatch +# %2 = type, e.g. U20, U21, Senior +# %3 = phase, e.g. CC +# %4 = WC number, e.g. XIV +# %5 = MaxTools.match +MaxTools.templateShortWithoutTable=%1: %2 - %3 %4 - %5 \ No newline at end of file diff --git a/content/information-aggregation/maxtools.js b/content/information-aggregation/maxtools.js index 1c35f0a04b..2be4ac8bc3 100644 --- a/content/information-aggregation/maxtools.js +++ b/content/information-aggregation/maxtools.js @@ -80,6 +80,7 @@ Foxtrick.modules.Maxtools = { const module = this; const TITLE_STR = Foxtrick.L10n.getString('MaxTools.eligibilityTitle'); + const SUBTITLE_STR = Foxtrick.L10n.getString('MaxTools.eligibilitySubtitle'); const EDITION_STR = Foxtrick.L10n.getString('MaxTools.edition'); const MATCH_STR = Foxtrick.L10n.getString('MaxTools.match'); const TMPL_STR = Foxtrick.L10n.getString('MaxTools.templateWithoutTable'); @@ -129,13 +130,15 @@ Foxtrick.modules.Maxtools = { let wrapper = Foxtrick.createFeaturedElement(doc, module, 'div'); Foxtrick.addClass(wrapper, 'mainBox'); + let titleElement = doc.createElement('h2'); titleElement.textContent = TITLE_STR; - - //titleElement.appendChild(getLink(age.years, age.days)); - wrapper.appendChild(titleElement); + let subtitleElement = doc.createElement('h3'); + subtitleElement.textContent = SUBTITLE_STR; + wrapper.appendChild(subtitleElement); + champsList.forEach(function (championship) { if (Object.keys(championship).length !== 0) { let editionNum = isRomanNumberEditionEnabled ? Foxtrick.decToRoman(championship.edition) : championship.edition; @@ -221,15 +224,16 @@ Foxtrick.modules.Maxtools = { if (Object.keys(championship).length !== 0) { let editionNum = isRomanNumberEditionEnabled ? Foxtrick.decToRoman(championship.edition) : championship.edition; - //let lastMatch = championship.match.toString() + "/" + championship.last_phase_match.toString(); - let lastMatch = MATCH_STR.replace(/%1/, championship.match.toString()); - lastMatch = lastMatch.replace(/%2/, championship.last_phase_match.toString()); + let lastMatch = championship.match.toString() + "/" + championship.last_phase_match.toString(); + //let lastMatch = MATCH_STR.replace(/%1/, championship.match.toString()); + //lastMatch = lastMatch.replace(/%2/, championship.last_phase_match.toString()); let contentChamp = TMPL_STR_SHORT; - contentChamp = contentChamp.replace(/%1/, championship.type); - contentChamp = contentChamp.replace(/%2/, championship.phase); - contentChamp = contentChamp.replace(/%3/, editionNum.toString()); - contentChamp = contentChamp.replace(/%4/, lastMatch); + contentChamp = contentChamp.replace(/%1/, LAST_MATCH_STR); + contentChamp = contentChamp.replace(/%2/, championship.type); + contentChamp = contentChamp.replace(/%3/, championship.phase); + contentChamp = contentChamp.replace(/%4/, editionNum.toString()); + contentChamp = contentChamp.replace(/%5/, lastMatch); let champDiv = doc.createElement('div'); champDiv.textContent = contentChamp; From 56dcc7d024146d82e361b0982be1e278a6e1dd37 Mon Sep 17 00:00:00 2001 From: kauefelipe Date: Wed, 16 Sep 2020 00:59:03 +0000 Subject: [PATCH 4/5] MaxTools (Module to show last match U20/U21/Senior) --- content/information-aggregation/maxtools.js | 37 --------------------- 1 file changed, 37 deletions(-) diff --git a/content/information-aggregation/maxtools.js b/content/information-aggregation/maxtools.js index 2be4ac8bc3..6850830d85 100644 --- a/content/information-aggregation/maxtools.js +++ b/content/information-aggregation/maxtools.js @@ -117,12 +117,9 @@ Foxtrick.modules.Maxtools = { const HTMT_PATH = 'https://ht-mt.org'; var url = `${HTMT_PATH}/maxtools-api/perfect-age/${age.years}/${age.days}`; - //console.log("vou chamar " + url); Foxtrick.load(url).then(function (r) { var text = /** @type {string} */ (r); - //console.log(text); let champsList = module.buildMaxToolPerfectAge(text); - //console.log(champsList); let entryPoint = doc.querySelector('#mainBody > .mainBox') || @@ -175,9 +172,6 @@ Foxtrick.modules.Maxtools = { runPlayerList: function (doc) { const module = this; - const TITLE_STR = Foxtrick.L10n.getString('MaxTools.eligibilityTitle'); - const EDITION_STR = Foxtrick.L10n.getString('MaxTools.edition'); - const MATCH_STR = Foxtrick.L10n.getString('MaxTools.match'); const TMPL_STR_SHORT = Foxtrick.L10n.getString('MaxTools.templateShortWithoutTable'); const LAST_MATCH_STR = Foxtrick.L10n.getString('MaxTools.lastMatch'); @@ -189,10 +183,7 @@ Foxtrick.modules.Maxtools = { * @return {HTMLAnchorElement} */ var getLink = function (years, days) { - //console.log('chegou aqui'); let lang = Foxtrick.Prefs.getString('htLanguage'); - //let prefix = 'http://www.fantamondi.it/HTMS/index.php' + - // `?page=htmspoints&lang=${lang}&action=calc`; let prefix = 'https://ht-mt.org/nt/perfect-age'; let skillQuery = `?lang=${lang}&years=${years}&days=${days}`; @@ -219,14 +210,11 @@ Foxtrick.modules.Maxtools = { container.appendChild(getLink(player.age.years, player.age.days)); container.appendChild(doc.createTextNode(' ')); - champsList.forEach(function (championship) { if (Object.keys(championship).length !== 0) { let editionNum = isRomanNumberEditionEnabled ? Foxtrick.decToRoman(championship.edition) : championship.edition; let lastMatch = championship.match.toString() + "/" + championship.last_phase_match.toString(); - //let lastMatch = MATCH_STR.replace(/%1/, championship.match.toString()); - //lastMatch = lastMatch.replace(/%2/, championship.last_phase_match.toString()); let contentChamp = TMPL_STR_SHORT; contentChamp = contentChamp.replace(/%1/, LAST_MATCH_STR); @@ -249,31 +237,6 @@ Foxtrick.modules.Maxtools = { }, (er) => { console.log(er); }).catch(Foxtrick.catch(module)); - //if (player.age.years > 20) - // continue; - - //let { worldCupNumber, lastMatch, matchNumber, dateWhen21 } = - // module.calculate(doc, player.age); - - //let wcNum = Foxtrick.decToRoman(worldCupNumber); - - //let text = TMPL_STR; - //text = text.replace(/%1/, TITLE_STR); - //text = text.replace(/%2/, WC_STR); - //text = text.replace(/%3/, wcNum); - //text = text.replace(/%4/, lastMatch); - - //let container = Foxtrick.createFeaturedElement(doc, module, 'p'); - //Foxtrick.addClass(container, 'ft-u20lastmatch'); - //container.textContent = text; - //container.dataset.value = String(dateWhen21.getTime()); - //container.dataset.valueString = `${wcNum}:${matchNumber}`; - - //let entry = player.playerNode.querySelector('table') || player.playerNode.lastChild; - //while (entry.parentElement && entry.parentElement.matches('.flex')) - // entry = entry.parentElement; - - //Foxtrick.insertAfter(container, entry); } }, }; From d3d66fa39641d4221024894081a22d088f919be5 Mon Sep 17 00:00:00 2001 From: kauefelipe Date: Mon, 30 Nov 2020 03:12:46 +0000 Subject: [PATCH 5/5] fixing pull request issues --- content/foxtrick.properties | 12 +- content/information-aggregation/maxtools.js | 190 ++++++++++---------- 2 files changed, 97 insertions(+), 105 deletions(-) diff --git a/content/foxtrick.properties b/content/foxtrick.properties index 5a3cbedcd9..0f7f0e7527 100644 --- a/content/foxtrick.properties +++ b/content/foxtrick.properties @@ -2092,11 +2092,11 @@ CopyFinancesAd.copied=The economy report has been copied to the clipboard. # MaxTools module.Maxtools.desc=Show last match U20/U21/Senior -module.Maxtools.RomanNumberEdition.desc=Use Roman numerals in the championship edition -module.Maxtools.YouthPlayers.desc=Show last match U20/U21/Senior in the Youth Player Details page. -module.Maxtools.SeniorPlayers.desc=Show last match U20/U21/Senior in the Senior Player Details page. -module.Maxtools.AllPlayers.desc=Show last match U20/U21/Senior in the Senior/Youth/NT Players page. -module.Maxtools.TransfersResults.desc=Show last match U20/U21/Senior in the Transfers Search Results page. +module.Maxtools.RomanNumberEdition.desc=Use Roman numerals for the championship edition +module.Maxtools.YouthPlayers.desc=Show last match U20/U21/Senior on the Youth Player Details page. +module.Maxtools.SeniorPlayers.desc=Show last match U20/U21/Senior on the Senior Player Details page. +module.Maxtools.AllPlayers.desc=Show last match U20/U21/Senior on the Senior/Youth/NT Players page. +module.Maxtools.TransfersResults.desc=Show last match U20/U21/Senior on the Transfers Search Results page. MaxTools=MaxTools: MaxTools.MoreDetails=(more details) @@ -2121,4 +2121,4 @@ MaxTools.eligibilityText=This player will be able to play: # %3 = phase, e.g. CC # %4 = WC number, e.g. XIV # %5 = MaxTools.match -MaxTools.templateShortWithoutTable=%1: %2 - %3 %4 - %5 \ No newline at end of file +MaxTools.templateShortWithoutTable=%1: %2 - %3 %4 - %5 diff --git a/content/information-aggregation/maxtools.js b/content/information-aggregation/maxtools.js index 6850830d85..094a34b4cc 100644 --- a/content/information-aggregation/maxtools.js +++ b/content/information-aggregation/maxtools.js @@ -28,12 +28,10 @@ Foxtrick.modules.Maxtools = { var isSeniorPlayerDetailsPage = Foxtrick.isPage(doc, 'playerDetails'); var isPlayersPage = Foxtrick.isPage(doc, 'allPlayers'); var isYouthPlayersPage = Foxtrick.isPage(doc, 'youthPlayers'); - var isTransferResultsPage = Foxtrick.isPage(doc, 'transferSearchResult'); var isYouthEnabled = Foxtrick.Prefs.isModuleOptionEnabled(module, 'YouthPlayers'); var isSeniorsEnabled = Foxtrick.Prefs.isModuleOptionEnabled(module, 'SeniorPlayers'); var isPlayersEnabled = Foxtrick.Prefs.isModuleOptionEnabled(module, 'AllPlayers'); - var isTransferEnabled = Foxtrick.Prefs.isModuleOptionEnabled(module, 'TransfersResults'); // If the option isn't enabled for this page, don't show. @@ -43,16 +41,12 @@ Foxtrick.modules.Maxtools = { return; if (isPlayersPage && !isPlayersEnabled) return; - if (isTransferResultsPage && !isTransferEnabled) - return; if (isYouthPlayerDetailsPage || isSeniorPlayerDetailsPage) { module.runPlayer(doc); } else if (isPlayersPage || isYouthPlayersPage) module.runPlayerList(doc); - else if (isTransferResultsPage) - module.runTransferList(doc); }, /** @@ -75,39 +69,31 @@ Foxtrick.modules.Maxtools = { return champsList; }, + /** + * @param {number} years + * @param {number} days + * @param {document} doc + * @return {HTMLAnchorElement} + */ + getLink: function (years, days, doc) { + let lang = Foxtrick.Prefs.getString('htLanguage'); + let HTMT_PATH = 'https://ht-mt.org/nt/perfect-age'; + let skillQuery = `?lang=${lang}&years=${years}&days=${days}`; + + let link = doc.createElement('a'); + link.textContent = Foxtrick.L10n.getString('MaxTools.MoreDetails'); + link.href = HTMT_PATH + skillQuery; + link.target = '_blank'; + link.rel = 'noopener'; + return link; + }, + /** @param {document} doc */ runPlayer: function (doc) { const module = this; const TITLE_STR = Foxtrick.L10n.getString('MaxTools.eligibilityTitle'); - const SUBTITLE_STR = Foxtrick.L10n.getString('MaxTools.eligibilitySubtitle'); - const EDITION_STR = Foxtrick.L10n.getString('MaxTools.edition'); - const MATCH_STR = Foxtrick.L10n.getString('MaxTools.match'); - const TMPL_STR = Foxtrick.L10n.getString('MaxTools.templateWithoutTable'); - const LAST_MATCH_STR = Foxtrick.L10n.getString('MaxTools.lastMatch'); - - var isRomanNumberEditionEnabled = Foxtrick.Prefs.isModuleOptionEnabled(module, 'RomanNumberEdition'); - - /** - * @param {number} years - * @param {number} days - * @return {HTMLAnchorElement} - */ - var getLink = function (years, days) { - //console.log('chegou aqui'); - let lang = Foxtrick.Prefs.getString('htLanguage'); - //let prefix = 'http://www.fantamondi.it/HTMS/index.php' + - // `?page=htmspoints&lang=${lang}&action=calc`; - let prefix = 'https://ht-mt.org/nt/perfect-age'; - let skillQuery = `?lang=${lang}&years=${years}&days=${days}`; - - let link = doc.createElement('a'); - link.textContent = Foxtrick.L10n.getString('MaxTools.MoreDetails'); - link.href = prefix + skillQuery; - link.target = '_blank'; - link.rel = 'noopener'; - return link; - } + const SUBTITLE_STR = Foxtrick.L10n.getString('MaxTools.eligibilitySubtitle'); if (Foxtrick.Pages.Player.wasFired(doc)) return; @@ -136,30 +122,10 @@ Foxtrick.modules.Maxtools = { subtitleElement.textContent = SUBTITLE_STR; wrapper.appendChild(subtitleElement); - champsList.forEach(function (championship) { - if (Object.keys(championship).length !== 0) { - let editionNum = isRomanNumberEditionEnabled ? Foxtrick.decToRoman(championship.edition) : championship.edition; - - let lastMatch = MATCH_STR.replace(/%1/, championship.match.toString()); - lastMatch = lastMatch.replace(/%2/, championship.last_phase_match.toString()); - - let contentChamp = TMPL_STR; - contentChamp = contentChamp.replace(/%1/, LAST_MATCH_STR); - contentChamp = contentChamp.replace(/%2/, championship.type); - contentChamp = contentChamp.replace(/%3/, championship.scheduler); - contentChamp = contentChamp.replace(/%4/, EDITION_STR); - contentChamp = contentChamp.replace(/%5/, editionNum.toString()); - contentChamp = contentChamp.replace(/%6/, championship.phase); - contentChamp = contentChamp.replace(/%7/, lastMatch); - - let textElement = doc.createElement('div'); - textElement.textContent = contentChamp; - wrapper.appendChild(textElement); - } - }); + module.appendChampsDetail(champsList, doc, wrapper, true); let textElement = doc.createElement('div'); - textElement.appendChild(getLink(age.years, age.days)); + textElement.appendChild(module.getLink(age.years, age.days, doc)); wrapper.appendChild(textElement); entryPoint.parentNode.insertBefore(wrapper, entryPoint.nextSibling); @@ -172,29 +138,6 @@ Foxtrick.modules.Maxtools = { runPlayerList: function (doc) { const module = this; - const TMPL_STR_SHORT = Foxtrick.L10n.getString('MaxTools.templateShortWithoutTable'); - const LAST_MATCH_STR = Foxtrick.L10n.getString('MaxTools.lastMatch'); - - var isRomanNumberEditionEnabled = Foxtrick.Prefs.isModuleOptionEnabled(module, 'RomanNumberEdition'); - - /** - * @param {number} years - * @param {number} days - * @return {HTMLAnchorElement} - */ - var getLink = function (years, days) { - let lang = Foxtrick.Prefs.getString('htLanguage'); - let prefix = 'https://ht-mt.org/nt/perfect-age'; - let skillQuery = `?lang=${lang}&years=${years}&days=${days}`; - - let link = doc.createElement('a'); - link.textContent = Foxtrick.L10n.getString('MaxTools'); - link.href = prefix + skillQuery; - link.target = '_blank'; - link.rel = 'noopener'; - return link; - } - let players = Foxtrick.modules.Core.getPlayerList(); for (let player of players) { @@ -207,36 +150,85 @@ Foxtrick.modules.Maxtools = { let container = Foxtrick.createFeaturedElement(doc, module, 'p'); Foxtrick.addClass(container, 'ft-u20lastmatch'); - container.appendChild(getLink(player.age.years, player.age.days)); + container.appendChild(module.getLink(player.age.years, player.age.days, doc)); container.appendChild(doc.createTextNode(' ')); - champsList.forEach(function (championship) { - if (Object.keys(championship).length !== 0) { - let editionNum = isRomanNumberEditionEnabled ? Foxtrick.decToRoman(championship.edition) : championship.edition; - - let lastMatch = championship.match.toString() + "/" + championship.last_phase_match.toString(); - - let contentChamp = TMPL_STR_SHORT; - contentChamp = contentChamp.replace(/%1/, LAST_MATCH_STR); - contentChamp = contentChamp.replace(/%2/, championship.type); - contentChamp = contentChamp.replace(/%3/, championship.phase); - contentChamp = contentChamp.replace(/%4/, editionNum.toString()); - contentChamp = contentChamp.replace(/%5/, lastMatch); - - let champDiv = doc.createElement('div'); - champDiv.textContent = contentChamp; - container.appendChild(champDiv); - } - }); + + module.appendChampsDetail(champsList, doc, container, false); let entry = player.playerNode.querySelector('table') || player.playerNode.lastChild; while (entry.parentElement && entry.parentElement.matches('.flex')) entry = entry.parentElement; - Foxtrick.insertAfter(container, entry); + Foxtrick.insertAfter(container, entry); }, (er) => { console.log(er); }).catch(Foxtrick.catch(module)); } }, + + /** + * @param {Array} champsList + * @param {document} doc + * @param {boolean} extendedDescription + * @param {HTMLParagraphElement} container + */ + appendChampsDetail: function (champsList, doc, container, extendedDescription) { + const module = this; + + var isRomanNumberEditionEnabled = Foxtrick.Prefs.isModuleOptionEnabled(module, 'RomanNumberEdition'); + + champsList.forEach(function (championship) { + if (Object.keys(championship).length !== 0) { + let editionNum = isRomanNumberEditionEnabled ? Foxtrick.decToRoman(championship.edition) : championship.edition; + + let tmplStr = module.buildTmplStr(championship, editionNum, extendedDescription); + + let champDiv = doc.createElement('div'); + champDiv.textContent = tmplStr; + container.appendChild(champDiv); + } + }); + }, + + /** + * @param {MaxToolPerfectAge} championship + * @param {string|number} editionNum + * @param {boolean} extendedDescription + * @returns {string} + */ + buildTmplStr: function (championship, editionNum, extendedDescription) { + const MATCH_STR = Foxtrick.L10n.getString('MaxTools.match'); + const TMPL_STR = Foxtrick.L10n.getString('MaxTools.templateWithoutTable'); + + var textFormat = extendedDescription ? MATCH_STR : "%1/%2"; + + let strMatch = textFormat.replace(/%1/, championship.match.toString()); + strMatch = strMatch.replace(/%2/, championship.last_phase_match.toString()); + + const TMPL_STR_SHORT = Foxtrick.L10n.getString('MaxTools.templateShortWithoutTable'); + const LAST_MATCH_STR = Foxtrick.L10n.getString('MaxTools.lastMatch'); + let contentChamp = extendedDescription ? TMPL_STR : TMPL_STR_SHORT; + + contentChamp = contentChamp.replace(/%1/, LAST_MATCH_STR); + contentChamp = contentChamp.replace(/%2/, championship.type); + + if (extendedDescription) { + const EDITION_STR = Foxtrick.L10n.getString('MaxTools.edition'); + + contentChamp = contentChamp.replace(/%3/, championship.scheduler); + contentChamp = contentChamp.replace(/%4/, EDITION_STR); + contentChamp = contentChamp.replace(/%5/, editionNum.toString()); + contentChamp = contentChamp.replace(/%6/, championship.phase); + contentChamp = contentChamp.replace(/%7/, strMatch); + } else { + contentChamp = contentChamp.replace(/%3/, championship.phase); + contentChamp = contentChamp.replace(/%4/, editionNum.toString()); + contentChamp = contentChamp.replace(/%5/, strMatch); + } + + + return contentChamp; + } }; +