您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Greasy Fork is available in English.
Trophymanager: show main events of the match
当前为
// ==UserScript== // @name TMVN Match Event // @version 1 // @description Trophymanager: show main events of the match // @namespace https://trophymanager.com // @include https://trophymanager.com/matches/* // ==/UserScript== (function () { 'use strict'; const MENTALITY_MAP = new Map() .set("1", "Very Defensive") .set("2", "Defensive") .set("3", "Slightly Defensive") .set("4", "Normal") .set("5", "Slightly Attacking") .set("6", "Attacking") .set("7", "Very Attacking"); const STYLE_MAP = new Map() .set("1", "Balanced") .set("2", "Direct") .set("3", "Wings") .set("4", "Shortpassing") .set("5", "Long Balls") .set("6", "Through Balls"); const EVENT_TYPE = { GOAL: 'goal', CARD: 'card', MENTALITY: 'mentality', STYLE: 'style', POSITION: 'position', SUBTITION: 'subtition', INJURY: 'injury' } var mainEventHTML = ""; var matchUrl = window.location.href; var reg = /^\d+$/; var matchId; if (matchUrl.charAt(matchUrl.length - 1) === "/") { matchId = matchUrl.substring("https://trophymanager.com/matches/".length, matchUrl.length - 1); } else { matchId = matchUrl.substring("https://trophymanager.com/matches/".length, matchUrl.length); } if (!reg.test(matchId)) { return; } var xhr = new XMLHttpRequest(); var url = 'https://trophymanager.com/ajax/match.ajax.php?id=' + matchId; xhr.open('GET', url, true); xhr.send(); xhr.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { var data = JSON.parse(this.responseText); var report = data.report; if (Object.keys(report).length <= 3) { return; //because don't have datas of match } var homeClubId = data.club.home.id; var awayClubId = data.club.away.id; var homeLineup = data.lineup.home; var awayLineup = data.lineup.away; var homePlayerIds = Object.getOwnPropertyNames(homeLineup); var awayPlayerIds = Object.getOwnPropertyNames(awayLineup); var homePlayer = new Map(), awayPlayer = new Map(); homePlayerIds.forEach((playerId) => { homePlayer.set(playerId, homeLineup[playerId].name); }); awayPlayerIds.forEach((playerId) => { awayPlayer.set(playerId, awayLineup[playerId].name); }); var homeGoal = 0, awayGoal = 0; var eventReport = []; Object.keys(report).forEach(function (key, index) { var minuteArr = report[key]; for (var i = 0; i < minuteArr.length; i++) { var paramArr = minuteArr[i].parameters; if (paramArr) { for (var j = 0; j < paramArr.length; j++) { var paramObj = paramArr[j]; if (paramObj.goal) { if (homePlayer.has(paramObj.goal.player)) { homeGoal++; eventReport.push({ minute: key, type: EVENT_TYPE.GOAL, home: true, content: "[Goal] " + homePlayer.get(paramObj.goal.player) + (paramObj.goal.assist ? " (" + homePlayer.get(paramObj.goal.assist) + ") " : " ") + paramObj.goal.score[0] + " - " + paramObj.goal.score[1] }); } else { awayGoal++; eventReport.push({ minute: key, type: EVENT_TYPE.GOAL, home: false, content: "[Goal] " + awayPlayer.get(paramObj.goal.player) + (paramObj.goal.assist ? " (" + awayPlayer.get(paramObj.goal.assist) + ") " : " ") + paramObj.goal.score[0] + " - " + paramObj.goal.score[1] }); } } else if (paramObj.red) { if (homePlayer.has(paramObj.red)) { eventReport.push({ minute: key, type: EVENT_TYPE.CARD, home: true, content: "[Red card] " + homePlayer.get(paramObj.red) }); } else { eventReport.push({ minute: key, type: EVENT_TYPE.CARD, home: false, content: "[Red card] " + awayPlayer.get(paramObj.red) }); } } else if (paramObj.yellow_red) { if (homePlayer.has(paramObj.yellow_red)) { eventReport.push({ minute: key, type: EVENT_TYPE.CARD, home: true, content: "[Red card] (2 yellow cards) " + homePlayer.get(paramObj.yellow_red) }); } else { eventReport.push({ minute: key, type: EVENT_TYPE.CARD, home: false, content: "[Red card] (2 yellow cards) " + awayPlayer.get(paramObj.yellow_red) }); } } else if (paramObj.mentality_change) { if (paramObj.mentality_change.mentality) { if (paramObj.mentality_change.team == homeClubId) { eventReport.push({ minute: key, type: EVENT_TYPE.MENTALITY, home: true, content: "[Tactics] Mentality change to " + MENTALITY_MAP.get(paramObj.mentality_change.mentality) }); } else { eventReport.push({ minute: key, type: EVENT_TYPE.MENTALITY, home: false, content: "[Tactics] Mentality change to " + MENTALITY_MAP.get(paramObj.mentality_change.mentality) }); } } else if (paramObj.mentality_change.style) { if (paramObj.mentality_change.team == homeClubId) { eventReport.push({ minute: key, type: EVENT_TYPE.STYLE, home: true, content: "[Tactics] Attacking style change to " + STYLE_MAP.get(paramObj.mentality_change.style) }); } else { eventReport.push({ minute: key, type: EVENT_TYPE.STYLE, home: false, content: "[Tactics] Attacking style change to " + STYLE_MAP.get(paramObj.mentality_change.style) }); } } } else if (paramObj.player_change) { if (homePlayer.has(paramObj.player_change.player)) { eventReport.push({ minute: key, type: EVENT_TYPE.POSITION, home: true, content: "[Position] " + homePlayer.get(paramObj.player_change.player) + " change to " + (paramObj.player_change.position !== undefined ? paramObj.player_change.position.toUpperCase() : "") }); } else { eventReport.push({ minute: key, type: EVENT_TYPE.POSITION, home: false, content: "[Position] " + awayPlayer.get(paramObj.player_change.player) + " change to " + (paramObj.player_change.position !== undefined ? paramObj.player_change.position.toUpperCase() : "") }); } } else if (paramObj.sub && paramObj.sub.player_in && paramObj.sub.player_out) { if (homePlayer.has(paramObj.sub.player_in)) { eventReport.push({ minute: key, type: EVENT_TYPE.SUBTITION, home: true, content: "[Subtition] " + homePlayer.get(paramObj.sub.player_in) + " replace " + homePlayer.get(paramObj.sub.player_out) + (paramObj.sub.player_position !== undefined ? " and play " + paramObj.sub.player_position.toUpperCase() : "") }); } else { eventReport.push({ minute: key, type: EVENT_TYPE.SUBTITION, home: false, content: "[Subtition] " + awayPlayer.get(paramObj.sub.player_in) + " replace " + awayPlayer.get(paramObj.sub.player_out) + (paramObj.sub.player_position !== undefined ? " and play " + paramObj.sub.player_position.toUpperCase() : "") }); } } else if (paramObj.injury) { if (homePlayer.has(paramObj.injury)) { eventReport.push({ minute: key, type: EVENT_TYPE.INJURY, home: true, content: "[Injury] " + homePlayer.get(paramObj.injury) }); } else { eventReport.push({ minute: key, type: EVENT_TYPE.INJURY, home: false, content: "[Injury] " + awayPlayer.get(paramObj.injury) }); } } } } } }); if (eventReport.length > 0) { eventReport.forEach((event) => { if (event.home) { let color; switch (event.type) { case EVENT_TYPE.GOAL: color = "style='color:Aqua;'"; break; case EVENT_TYPE.CARD: color = "style='color:Brown;'"; break; case EVENT_TYPE.MENTALITY: color = "style='color:Orange;'"; break; case EVENT_TYPE.STYLE: color = "style='color:Yellow;'"; break; case EVENT_TYPE.POSITION: color = "style='color:GreenYellow;'"; break; case EVENT_TYPE.INJURY: color = "style='color:Brown;'"; break; default: color = ""; } mainEventHTML += "<li align='left' " + color + ">" + event.minute + ". " + event.content + "</li>"; } else { let color; switch (event.type) { case EVENT_TYPE.GOAL: color = "style='color:Aqua;'"; break; case EVENT_TYPE.CARD: color = "style='color:Brown;'"; break; case EVENT_TYPE.MENTALITY: color = "style='color:Orange;'"; break; case EVENT_TYPE.STYLE: color = "style='color:Yellow;'"; break; case EVENT_TYPE.POSITION: color = "style='color:GreenYellow;'"; break; case EVENT_TYPE.INJURY: color = "style='color:Brown;'"; break; default: color = ""; } mainEventHTML += "<li align='right' " + color + ">" + event.content + " ." + event.minute + "</li>"; } }); } } } var myInterval = setInterval(display, 1000); var pause = false; function display() { if (mainEventHTML !== "" && $('.box_body.mv_bottom').length > 0) { if ($('.post_report').length > 0) { let divArea = $('.box_body.mv_bottom div.post_report')[0]; divArea.innerHTML = '<div class="mega_headline tcenter report_section_header dark_bg">Main Event</div><div><ul class="clean underlined large_padding">' + mainEventHTML + '</ul></div>' + divArea.innerHTML; clearInterval(myInterval); } else if (!pause) { let divArea = $('.box_body.mv_bottom')[0]; divArea.innerHTML = '<div class="mega_headline tcenter report_section_header dark_bg">Main Event</div><div><ul class="clean underlined large_padding">' + mainEventHTML + '</ul></div>' + divArea.innerHTML; pause = true; } } } })();