// ==UserScript== // @name Match stats and actions 51 minutes before match // @namespace http://tampermonkey.net/ // @version 0.1 // @description Get match stats and actions 51 minutes before match // @author Shomi // @match https://trophymanager.com/matches/* // @icon https://www.google.com/s2/favicons?sz=64&domain=trophymanager.com // @grant none // @license MIT // @downloadURL none // ==/UserScript== const defaultStats = { goals: 0, shoots: { total: 0, onTarget: 0 }, setPieces: 0, penalties: 0, cards: { yellow: 0, red: 0 }, possession: 50 } const getMatch = matchId => { $.get(`/ajax/match.ajax.php?id=${matchId}`, function (responseText) { let data = JSON.parse(responseText); const {report, club, lineup} = data; let homeTeam = JSON.parse(JSON.stringify({...defaultStats, id: club.home.id})); let awayTeam = JSON.parse(JSON.stringify({...defaultStats, id: club.away.id})); let actions = []; Object.keys(report) .reduce((chances, chance) => { report[chance].forEach(c => c.minute = chance) chances.push(...report[chance]) return chances }, []) .forEach(chance => { (chance.parameters || []).forEach(parameter => { if (parameter.goal) { if (chance.club === homeTeam.id) { homeTeam.goals++; const player = lineup.home[parameter.goal.player]; actions.push({name: 'Goal', player: player.name, minute: chance.minute}) } else { awayTeam.goals++; const player = lineup.away[parameter.goal.player]; actions.push({name: 'Goal', player: player.name, minute: chance.minute}) } } if (parameter.shot) { if (chance.club === homeTeam.id) { homeTeam.shoots.total++; if (parameter.shot.target === 'on') homeTeam.shoots.onTarget++ } else { awayTeam.shoots.total++; if (parameter.shot.target === 'on') awayTeam.shoots.onTarget++ } } if (parameter.set_piece) { if (chance.club === homeTeam.id) homeTeam.setPieces++; else awayTeam.setPieces++; } if (parameter.penalty) { if (chance.club === homeTeam.id) homeTeam.penalties++; else awayTeam.penalties++; } if (parameter.yellow) { if (chance.club === homeTeam.id) { awayTeam.cards.yellow++; const player = lineup.away[parameter.yellow]; actions.push({name: 'Yellow card', player: player.name, minute: chance.minute}) } else { homeTeam.cards.yellow++; const player = lineup.home[parameter.yellow]; actions.push({name: 'Yellow card', player: player.name, minute: chance.minute}) } } if (parameter.red) { if (chance.club === homeTeam.id) { awayTeam.cards.red++; const player = lineup.away[parameter.red]; actions.push({name: 'Red card', player: player.name, minute: chance.minute}) } else { homeTeam.cards.red++; const player = lineup.home[parameter.red]; actions.push({name: 'Red card', player: player.name, minute: chance.minute}) } } if (parameter.yellow_red) { if (chance.club === homeTeam.id) { awayTeam.cards.yellow++; awayTeam.cards.red++; const player = lineup.away[parameter.red]; actions.push({name: 'Red card', player: player.name, minute: chance.minute}) } else { homeTeam.cards.yellow++; homeTeam.cards.red++; const player = lineup.home[parameter.red]; actions.push({name: 'Red card', player: player.name, minute: chance.minute}) } } }) }) setTimeout(() => { let html2 = ``; actions.forEach(action => { html2 += `` }) html2 += '
${club.home.club_name} ${club.away.club_name}
${homeTeam.goals} Goals ${awayTeam.goals}
${homeTeam.shoots.total} Shots ${awayTeam.shoots.total}
${homeTeam.shoots.onTarget} Shots On Target ${awayTeam.shoots.onTarget}
${homeTeam.setPieces} Set Pieces ${awayTeam.setPieces}
${homeTeam.penalties} Penalties ${awayTeam.penalties}
${homeTeam.cards.yellow} Yellow Cards ${awayTeam.cards.yellow}
${homeTeam.cards.red} Red Cards ${awayTeam.cards.red}
Actions
${action.minute}' ${action.player} ${action.name}
' $('body').prepend(html2); }, 5000) }) } (function () { 'use strict'; const matchId = window.location.pathname.replace('/matches/', '').replace('/', ''); getMatch(matchId); // https://trophymanager.com/ajax/match.ajax.php?id=158830722&_=1653070834118 // Your code here... })();