Greasy Fork镜像 支持简体中文。

MatchResult_GoalScorers

View match result in advance (under 50 minutes before the match start)

  1. // ==UserScript==
  2. // @name MatchResult_GoalScorers
  3. // @namespace https://gf.qytechs.cn/users/562206
  4. // @version 0.0.6
  5. // @description View match result in advance (under 50 minutes before the match start)
  6. // @author Jhonatan Bianchi
  7. // @include http://trophymanager.com/matches/*
  8. // @include https://trophymanager.com/matches/*
  9. // ==/UserScript==
  10.  
  11.  
  12. function insertBefore(el, referenceNode) {
  13. referenceNode.parentNode.insertBefore(el, referenceNode);
  14. }
  15. function insertAfter(el, referenceNode) {
  16. referenceNode.parentNode.insertBefore(el, referenceNode.nextSibling);
  17. }
  18.  
  19. Object.filter = (obj, predicate) =>
  20. Object.keys(obj)
  21. .filter(key => predicate(obj[key]))
  22. .reduce((res, key) => (res[key] = obj[key], res), {});
  23.  
  24. function getEventImage(match, event) {
  25. let src = '';
  26.  
  27. if (getEventIs(event, 'goal')) {
  28. src = 'https://trophymanager.com/pics/icons/ball.gif';
  29. }
  30.  
  31. if (getEventIs(event, 'yellow')) {
  32. src = 'https://trophymanager.com/pics/icons/yellow_card.gif';
  33. }
  34.  
  35. if (getEventIs(event, 'red')) {
  36. src = 'https://trophymanager.com/pics/icons/red_card.gif';
  37. }
  38.  
  39. if (getEventIs(event, 'injury')) {
  40. src = 'https://trophymanager.com/pics/icons/injury.gif';
  41. }
  42.  
  43. const playerId = getPlayerIdFromEvent(event);
  44.  
  45. if (isPlayerFromHomeTeam(match, playerId)) {
  46. return '<img src="' + src + '" style="margin-left: 15px"/>';
  47. } else {
  48. return '<img src="' + src + '" style="margin-right: 15px"/>'
  49. }
  50. }
  51.  
  52. function getEventIs(event, eventNameToCheck) {
  53. return event[0].parameters.filter(e => e[eventNameToCheck]).length;
  54. }
  55.  
  56. function getGoalDetailsFromGoalEvent(goalEvent) {
  57. return goalEvent[0].parameters.filter(e => e.goal)[0].goal;
  58. }
  59.  
  60. function getMatchCurrentScoreAfterGoalEvent(goalEvent) {
  61. const goal = getGoalDetailsFromGoalEvent(goalEvent);
  62.  
  63. if (goal) {
  64. return {
  65. homeGoals: goal.score[0],
  66. awayGoals: goal.score[1],
  67. }
  68. }
  69. }
  70.  
  71. function isPlayerFromHomeTeam(match, playerId) {
  72. return Object.keys(match.lineup.home).includes(playerId);
  73. }
  74.  
  75. function getPlayerName(match, playerId) {
  76. return isPlayerFromHomeTeam(match, playerId) ? match.lineup.home[playerId].name : match.lineup.away[playerId].name;
  77. }
  78.  
  79. function eventIsGoalCardInjury(event) {
  80. return event.parameters && event.parameters.filter(event => event.goal || event.yellow || event.red || event.injury).length;
  81. }
  82.  
  83. function getWantedEvents(match) {
  84. return Object.filter(match.report, (event) => {
  85. return event.filter(e => {
  86. return eventIsGoalCardInjury(e);
  87. }).length;
  88. })
  89. }
  90.  
  91. function getGoalsEvents(match) {
  92. return Object.filter(match.report, (event) => {
  93. return event.filter(e => {
  94. return e.parameters && e.parameters.filter(e => e.goal).length;
  95. }).length;
  96. })
  97. }
  98.  
  99. function getMatchResult(match) {
  100. const goalsEvents = getGoalsEvents(match);
  101.  
  102. if (Object.keys(goalsEvents).length === 0) {
  103. return {
  104. homeGoals: 0,
  105. awayGoals: 0
  106. };
  107. }
  108.  
  109. const { [Object.keys(goalsEvents).pop()]: lastGoal } = goalsEvents;
  110.  
  111. return getMatchCurrentScoreAfterGoalEvent(lastGoal);
  112. }
  113.  
  114. function getHomeTeamName(match) {
  115. return match.club.home.club_name;
  116. }
  117.  
  118. function getAwayTeamName(match) {
  119. return match.club.away.club_name;
  120. }
  121.  
  122. function getPlayerIdFromEvent(event) {
  123. if (getEventIs(event, 'goal')) {
  124. return event[0].parameters.filter(e => e.goal)[0].goal.player;
  125. }
  126.  
  127. if (getEventIs(event, 'yellow')) {
  128. return event[0].parameters.filter(e => e.yellow)[0].yellow;
  129. }
  130.  
  131. if (getEventIs(event, 'red')) {
  132. return event[0].parameters.filter(e => e.red)[0].red;
  133. }
  134.  
  135. if (getEventIs(event, 'injury')) {
  136. return event[0].parameters.filter(e => e.injury)[0].injury;
  137. }
  138. }
  139.  
  140. function getFinalResultHtml(match) {
  141. const matchResult = getMatchResult(match);
  142.  
  143. return '<div style="width:100%;margin-top:10px;padding:10px;padding-bottom:5px;background-color:#000000;font-size:16px;font-weight:bold;">' +
  144. '<div style="display:inline-block;width:46%;margin:0px;padding:0px;text-align:right;">' + getHomeTeamName(match) + '</div>' +
  145. '<div style="display:inline-block;width:8%;margin:0px;padding:0px;text-align:center;color:#fff">' + matchResult.homeGoals + ' - ' + matchResult.awayGoals + '</div>'+
  146. '<div style="display:inline-block;width:46%;margin:0px;padding:0px;text-align:left;">' + getAwayTeamName(match) + '</div>' +
  147. '</div>';
  148. }
  149.  
  150. function getGoalHtml(match, goalEvent, minute) {
  151. const goal = getGoalDetailsFromGoalEvent(goalEvent);
  152. const currentMatchResult = getMatchCurrentScoreAfterGoalEvent(goalEvent);
  153.  
  154. if (isPlayerFromHomeTeam(match, goal.player)) {
  155. return '<div style="width:100%;padding:0px;padding-bottom:2px;background-color:#000000;font-size:13px;">' +
  156. '<div style="display:inline-block;width:47%;margin:0px;padding:0px;text-align:right">[' + minute + '] ' + getPlayerName(match, goal.player) + getEventImage(match, goalEvent) +'</div>' +
  157. '<div style="display:inline-block;width:8%;margin:0px;padding:0px;text-align:center">' + currentMatchResult.homeGoals + ' - ' + currentMatchResult.awayGoals + '</div>' +
  158. '</div>';
  159. } else {
  160. return '<div style="width:100%;padding:0px;padding-bottom:2px;background-color:#000000;font-size:13px;">' +
  161. '<div style="display:inline-block;width:47%;margin:0px;padding:0px;text-align:right">&nbsp;</div>' +
  162. '<div style="display:inline-block;width:8%;margin:0px;padding:0px;text-align:center"">' + currentMatchResult.homeGoals + ' - ' + currentMatchResult.awayGoals + '</div>' +
  163. '<div style="display:inline-block;width:45%;margin:0px;padding:0px;text-align:left">' + getEventImage(match, goalEvent) + getPlayerName(match, goal.player) + ' [' + minute + ']</div>' +
  164. '</div>';
  165. }
  166. }
  167.  
  168. function getNonGoalHtml(match, event, minute) {
  169. const playerId = getPlayerIdFromEvent(event);
  170.  
  171. if (isPlayerFromHomeTeam(match, playerId)) {
  172. return '<div style="width:100%;padding:0px;padding-bottom:2px;background-color:#000000;font-size:13px;">' +
  173. '<div style="display:inline-block;width:47%;margin:0px;padding:0px;text-align:right">[' + minute + '] ' + getPlayerName(match, playerId) + getEventImage(match, event) + '</div>' +
  174. '<div style="display:inline-block;width:8%;margin:0px;padding:0px;text-align:center"></div>' +
  175. '</div>';
  176. } else {
  177. return '<div style="width:100%;padding:0px;padding-bottom:2px;background-color:#000000;font-size:13px;">' +
  178. '<div style="display:inline-block;width:47%;margin:0px;padding:0px;text-align:right">&nbsp;</div>' +
  179. '<div style="display:inline-block;width:8%;margin:0px;padding:0px;text-align:center""></div>' +
  180. '<div style="display:inline-block;width:45%;margin:0px;padding:0px;text-align:left">' + getEventImage(match, event) + getPlayerName(match, playerId) + ' [' + minute + ']</div>' +
  181. '</div>';
  182. }
  183. }
  184.  
  185. function getEventHtml(match, event, minute) {
  186. if (getEventIs(event, 'goal')) {
  187. return getGoalHtml(match, event, minute);
  188. }
  189.  
  190. return getNonGoalHtml(match, event, minute);
  191. }
  192.  
  193. function showMatchEvents(match) {
  194. const mainCentersDivs = document.getElementsByClassName('main_center');
  195. if (mainCentersDivs) {
  196. const matchEventsDiv = document.createElement('div');
  197. matchEventsDiv.className = 'main_center';
  198. matchEventsDiv.innerHTML = getFinalResultHtml(match);
  199.  
  200. const matchEvents = getWantedEvents(match);
  201. for (const [minute, event] of Object.entries(matchEvents)) {
  202. matchEventsDiv.innerHTML = matchEventsDiv.innerHTML + getEventHtml(match, event, minute);
  203. }
  204.  
  205. insertBefore(matchEventsDiv, mainCentersDivs[mainCentersDivs.length - 1])
  206. }
  207.  
  208. }
  209.  
  210. var matchID = location.href.match(/([^\/]*)\/*$/)[1];
  211. var url = 'https://trophymanager.com/ajax/match.ajax.php?id=' + matchID;
  212. var xhr = new XMLHttpRequest();
  213. xhr.open('GET', url, true);
  214. xhr.send();
  215. xhr.onreadystatechange = function() {
  216. if (this.readyState === 4 && this.status === 200) {
  217. var match = JSON.parse(this.responseText);
  218. showMatchEvents(match);
  219. }
  220. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址