Match stats and actions 51 minutes before match

Get match stats and actions 51 minutes before match

  1. // ==UserScript==
  2. // @name Match stats and actions 51 minutes before match
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Get match stats and actions 51 minutes before match
  6. // @author Shomi
  7. // @match https://trophymanager.com/matches/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=trophymanager.com
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12. const defaultStats = {
  13. goals: 0,
  14. shoots: {
  15. total: 0,
  16. onTarget: 0
  17. },
  18. setPieces: 0,
  19. penalties: 0,
  20. cards: {
  21. yellow: 0,
  22. red: 0
  23. },
  24. possession: 50
  25. }
  26. const getMatch = matchId => {
  27. $.get(`/ajax/match.ajax.php?id=${matchId}`, function (responseText) {
  28. let data = JSON.parse(responseText);
  29. const {report, club, lineup} = data;
  30. let homeTeam = JSON.parse(JSON.stringify({...defaultStats, id: club.home.id}));
  31. let awayTeam = JSON.parse(JSON.stringify({...defaultStats, id: club.away.id}));
  32. let actions = [];
  33. Object.keys(report)
  34. .reduce((chances, chance) => {
  35. report[chance].forEach(c => c.minute = chance)
  36. chances.push(...report[chance])
  37. return chances
  38. }, [])
  39. .forEach(chance => {
  40. (chance.parameters || []).forEach(parameter => {
  41. if (parameter.goal) {
  42. if (chance.club === homeTeam.id) {
  43. homeTeam.goals++;
  44. const player = lineup.home[parameter.goal.player];
  45. actions.push({name: 'Goal', player: player.name, minute: chance.minute})
  46. } else {
  47. awayTeam.goals++;
  48. const player = lineup.away[parameter.goal.player];
  49. actions.push({name: 'Goal', player: player.name, minute: chance.minute})
  50. }
  51. }
  52. if (parameter.shot) {
  53. if (chance.club === homeTeam.id) {
  54. homeTeam.shoots.total++;
  55. if (parameter.shot.target === 'on') homeTeam.shoots.onTarget++
  56. } else {
  57. awayTeam.shoots.total++;
  58. if (parameter.shot.target === 'on') awayTeam.shoots.onTarget++
  59. }
  60. }
  61. if (parameter.set_piece) {
  62. if (chance.club === homeTeam.id) homeTeam.setPieces++;
  63. else awayTeam.setPieces++;
  64. }
  65. if (parameter.penalty) {
  66. if (chance.club === homeTeam.id) homeTeam.penalties++;
  67. else awayTeam.penalties++;
  68. }
  69. if (parameter.yellow) {
  70. if (chance.club === homeTeam.id) {
  71. awayTeam.cards.yellow++;
  72. const player = lineup.away[parameter.yellow];
  73. actions.push({name: 'Yellow card', player: player.name, minute: chance.minute})
  74. } else {
  75. homeTeam.cards.yellow++;
  76. const player = lineup.home[parameter.yellow];
  77. actions.push({name: 'Yellow card', player: player.name, minute: chance.minute})
  78. }
  79. }
  80. if (parameter.red) {
  81. if (chance.club === homeTeam.id) {
  82. awayTeam.cards.red++;
  83. const player = lineup.away[parameter.red];
  84. actions.push({name: 'Red card', player: player.name, minute: chance.minute})
  85. } else {
  86. homeTeam.cards.red++;
  87. const player = lineup.home[parameter.red];
  88. actions.push({name: 'Red card', player: player.name, minute: chance.minute})
  89. }
  90. }
  91. if (parameter.yellow_red) {
  92. if (chance.club === homeTeam.id) {
  93. awayTeam.cards.yellow++;
  94. awayTeam.cards.red++;
  95. const player = lineup.away[parameter.red];
  96. actions.push({name: 'Red card', player: player.name, minute: chance.minute})
  97. } else {
  98. homeTeam.cards.yellow++;
  99. homeTeam.cards.red++;
  100. const player = lineup.home[parameter.red];
  101. actions.push({name: 'Red card', player: player.name, minute: chance.minute})
  102. }
  103. }
  104. })
  105. })
  106. setTimeout(() => {
  107. let html2 = `<table style="width: 400px;background-color: black;text-align: center;">
  108. <tr>
  109. <th>${club.home.club_name}</th>
  110. <th></th>
  111. <th>${club.away.club_name}</th>
  112. </tr>
  113. <tr>
  114. <td>${homeTeam.goals}</td>
  115. <td>Goals</td>
  116. <td>${awayTeam.goals}</td>
  117. </tr>
  118. <tr>
  119. <td>${homeTeam.shoots.total}</td>
  120. <td>Shots</td>
  121. <td>${awayTeam.shoots.total}</td>
  122. </tr>
  123. <tr>
  124. <td>${homeTeam.shoots.onTarget}</td>
  125. <td>Shots On Target</td>
  126. <td>${awayTeam.shoots.onTarget}</td>
  127. </tr>
  128. <tr>
  129. <td>${homeTeam.setPieces}</td>
  130. <td>Set Pieces</td>
  131. <td>${awayTeam.setPieces}</td>
  132. </tr>
  133. <tr>
  134. <td>${homeTeam.penalties}</td>
  135. <td>Penalties</td>
  136. <td>${awayTeam.penalties}</td>
  137. </tr>
  138. <tr>
  139. <td>${homeTeam.cards.yellow}</td>
  140. <td>Yellow Cards</td>
  141. <td>${awayTeam.cards.yellow}</td>
  142. </tr>
  143. <tr>
  144. <td>${homeTeam.cards.red}</td>
  145. <td>Red Cards</td>
  146. <td>${awayTeam.cards.red}</td>
  147. </tr>
  148. <tr>
  149. <td></td>
  150. <td>Actions</td>
  151. <td></td>
  152. </tr>`;
  153. actions.forEach(action => {
  154. html2 += `<tr style="color: ${action.name === 'Goal' ? 'green' : action.name === 'Red card' ? 'red' : 'yellow'}">
  155. <td>${action.minute}'</td>
  156. <td>${action.player}</td>
  157. <td>${action.name}</td>
  158. </tr>`
  159. })
  160. html2 += '</table>'
  161. $('body').prepend(html2);
  162. }, 5000)
  163. })
  164. }
  165.  
  166. (function () {
  167. 'use strict';
  168. const matchId = window.location.pathname.replace('/matches/', '').replace('/', '');
  169. getMatch(matchId);
  170. // https://trophymanager.com/ajax/match.ajax.php?id=158830722&_=1653070834118
  171. // Your code here...
  172.  
  173. })();