TM Clean UI

7/7/2023, 8:23:11 AM

  1. // ==UserScript==
  2. // @name TM Clean UI
  3. // @namespace https://trophymanager.com
  4. // @match https://trophymanager.com/*
  5. // @grant none
  6. // @version 0.6
  7. // @author lorde_jim
  8. // @description 7/7/2023, 8:23:11 AM
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. 'use strict';
  14.  
  15. const WIN_COLOR = '#44ac45';
  16. const DRAW_COLOR = 'darkorange';
  17. const LOSE_COLOR = '#eb3f30';
  18. const UPCOMING_COLOR = 'grey';
  19. const LAST_MATCHES = 5;
  20. const LAST_HEADER = "Form";
  21. const WIN = 'W';
  22. const DRAW = 'D';
  23. const LOSE = 'L';
  24. const UPCOMING = '?'
  25.  
  26. let first = true;
  27. let startMatchIndex = 0;
  28. let teams = [];
  29.  
  30. [...document.querySelector('#overall_table').querySelectorAll('tr')]
  31. .forEach((row, i) => {
  32. if (!i) return;
  33. row.style.height = '24px';
  34. })
  35.  
  36. function addTableHeader() {
  37. let header = $('#overall_table thead tr');
  38. let streak = document.createElement('TH');
  39. let arrowLeft = document.createElement('IMG');
  40. arrowLeft.src = 'https://trophymanager.com/pics/cf_mini_arrow_left.png';
  41. arrowLeft.style.marginRight = '4px'
  42. arrowLeft.addEventListener('click', () => {
  43. if(startMatchIndex > -1) {
  44. startMatchIndex -= LAST_MATCHES;
  45. // if (startMatchIndex < 0) startMatchIndex = 0;
  46. applyResults(startMatchIndex)
  47. }
  48. })
  49. streak.appendChild(arrowLeft);
  50. let contentEl = document.createElement('SPAN');
  51. contentEl.textContent = LAST_HEADER;
  52. streak.appendChild(contentEl);
  53. let arrowRight = document.createElement('IMG');
  54. arrowRight.src = 'https://trophymanager.com/pics/cf_mini_arrow_right.png';
  55. arrowRight.style.marginLeft = '4px'
  56. arrowRight.addEventListener('click', () => {
  57. if (startMatchIndex < 29) {
  58. startMatchIndex += LAST_MATCHES;
  59. applyResults(startMatchIndex)
  60. }
  61. })
  62. streak.appendChild(arrowRight);
  63. $(streak).addClass('align_center');
  64. $(streak).addClass('header');
  65.  
  66. header.append(streak);
  67. }
  68.  
  69. function generateMatchsHistory() {
  70. let url = $('.content_menu .calendar').attr('href').split(`/`).filter(el => el.length);
  71. const params = {
  72. 'type': url[1],
  73. 'var1': url[2],
  74. 'var2': url.length > (3) ? url[3] : '',
  75. 'var3': url.length > (4) ? url[4] : ''
  76. };
  77. $.post('/ajax/fixtures.ajax.php', params, data => {
  78. if (data != null) {
  79. const keys = Object.keys(data);
  80. let matches = [];
  81. keys.forEach(key => matches = [...matches, ...data[key].matches]);
  82. teams = matches.reduce((carry, item) => {
  83. let hometeam = carry.find(team => team.id === item.hometeam);
  84. let awayteam = carry.find(team => team.id === item.awayteam);
  85.  
  86. if (hometeam) hometeam.matches.push(item)
  87. else carry.push({id: item.hometeam, name: item.hometeam_name, matches: [item], element: null})
  88.  
  89. if (awayteam) awayteam.matches.push(item);
  90. else carry.push({id: item.awayteam, name: item.awayteam_name, matches: [item], element: null})
  91.  
  92. return carry;
  93. }, []);
  94. applyResults();
  95. }
  96. }, 'json');
  97. }
  98.  
  99. function adjustHighlight(row) {
  100. row.children().last().removeClass('highlight_td_right');
  101. }
  102.  
  103. function adjustBorder(cell) {
  104. cell.removeClass('highlight_td_right_std');
  105. }
  106.  
  107. function getTeamResults(team) {
  108. let results = [];
  109. const start = startMatchIndex < 0 ? 0 : startMatchIndex;
  110. team.matches.slice(start, startMatchIndex + LAST_MATCHES).forEach(match => {
  111. let result = {};
  112. let otherTeam = null;
  113. const isHome = match.hometeam === team.id;
  114. if (isHome) {
  115. otherTeam = teams.find(team => team.id === match.awayteam);
  116. } else {
  117. otherTeam = teams.find(team => team.id === match.hometeam);
  118. }
  119. result.element = otherTeam.element;
  120. if (match.result) {
  121. let score = match.result.split('-');
  122. score[0] = parseInt(score[0]);
  123. score[1] = parseInt(score[1]);
  124. result.tooltip = match.hometeam_name + ' ' + match.result + ' ' + match.awayteam_name;
  125. result.matchLink = $(match.match_link).attr('href');
  126. if (score[0] > score[1])
  127. result.result = isHome ? WIN : LOSE;
  128. else if (score[0] < score[1])
  129. result.result = isHome ? LOSE : WIN;
  130. else
  131. result.result = DRAW;
  132. } else {
  133. result.matchLink = $(match.match_link).attr('href');
  134. result.tooltip = match.hometeam_name + ' - ' + match.awayteam_name;
  135. result.result = UPCOMING
  136. }
  137. results.push(result);
  138. })
  139. return results;
  140. }
  141. const nodes = document.querySelector('.column2_a').querySelector('.box_body').childNodes;
  142. document.querySelector('.column2_a').querySelector('.box_body').querySelector('.std').style.margin = '0';
  143. document.querySelector('.column2_a').querySelector('.box_body').querySelector('.std').style.padding = '0';
  144. document.querySelector('.column2_a').querySelector('.box_footer').remove();
  145. document.querySelector('.column2_a').querySelector('.box_body').style.marginBottom = '8px';
  146. nodes[9].remove();
  147. document.querySelector('#overall_table').classList.remove('border_bottom');
  148. [...document.querySelectorAll('#overall_table tbody tr')]
  149. .forEach((row, i) => {
  150. row.addEventListener('mouseover', event => {
  151. event.preventDefault();
  152. });
  153. row.style.height = '32px';
  154.  
  155. const columns = [...row.querySelectorAll('td')];
  156. columns.forEach(column => {
  157. column.classList.remove('border_right', 'highlight_td_left', 'highlight_td_right');
  158. });
  159. columns[1].style.paddingLeft = '8px';
  160. columns[1].querySelector('img').style.marginRight = '4px';
  161. let standingsColumn = columns[0];
  162. standingsColumn.classList.remove('align_right');
  163. standingsColumn.classList.add('align_center');
  164. if(!i) standingsColumn.style.backgroundColor = '#007700';
  165. if(i && i < 4) standingsColumn.style.backgroundColor = 'rgb(19, 90, 19)';
  166. if(i > 9 && i < 14) standingsColumn.style.backgroundColor = 'rgb(111, 19, 19)';
  167. if(i > 13) standingsColumn.style.backgroundColor = "#990000";
  168. let pointsColumn = columns[8];
  169. pointsColumn.classList.remove('align_right', 'border_right');
  170. pointsColumn.classList.add('align_center');
  171. pointsColumn.style.fontWeight = 'bold';
  172. row.classList.remove('promotion');
  173. row.classList.remove('promotion_playoff');
  174. row.classList.remove('relegation_playoff');
  175. row.classList.remove('relegation');
  176. row.style.backgroundColor = i % 2 ? 'rgb(48, 48, 48)' : 'rgb(34, 34, 34)';
  177.  
  178. });
  179. function applyResults(index = null) {
  180. [...document.querySelectorAll('#overall_table tbody td a')]
  181. .forEach(teamEl => {
  182. const id = teamEl.getAttribute('club_link');
  183. if (!id) return;
  184. let team = teams.find(team => team.id === id);
  185. team.element = teamEl.parentElement.parentElement;
  186. });
  187. [...document.querySelectorAll('#overall_table tbody td a')]
  188. .forEach((teamEl, i) => {
  189. const id = teamEl.getAttribute('club_link');
  190. if (!id) return;
  191. let team = teams.find(team => team.id === id);
  192. const lastMatchIndex = team.matches.findIndex(match => !match.result);
  193. startMatchIndex = index !== null ? index : lastMatchIndex - LAST_MATCHES;
  194. if(startMatchIndex < 0) startMatchIndex = 0;
  195. let results = getTeamResults(team);
  196. let streak = null;
  197. if (first) {
  198. let row = teamEl.parentElement.parentElement;
  199.  
  200. adjustBorder($(row).children().last());
  201. if ($(row).children().first().hasClass('highlight_td')) {
  202. adjustHighlight($(row));
  203. }
  204. streak = row.insertCell(-1);
  205. $(streak).addClass('cell_padding');
  206. $(streak).css('display', 'flex');
  207. $(streak).css('justify-content', 'space-between');
  208. $(streak).css('align-items', 'center');
  209. $(streak).css('height', '32px');
  210. $(streak).css('padding', '0 6px');
  211. $(streak).css('font-size', '12px');
  212. $(streak).css('letter-spacing', '2px');
  213. $(streak).css('cursor', 'default');
  214. $(streak).disableSelection();
  215.  
  216. if ($(row).children().first().hasClass('highlight_td')) {
  217. $(streak).addClass('highlight_td');
  218. }
  219. } else {
  220. let row = teamEl.parentElement.parentElement;
  221. streak = row.lastChild;
  222. }
  223. appendSchedule(streak, results);
  224. });
  225. if (first) {
  226. addTableHeader();
  227. }
  228. first = false;
  229. }
  230.  
  231. const appendSchedule = (streak, results) => {
  232. streak.innerHTML = '';
  233. for (const result of results) {
  234. let res = document.createElement('A');
  235. res.style.display = 'block';
  236. res.style.color = 'white';
  237. res.style.borderRadius = '2px';
  238. res.style.width = '16px';
  239. res.style.height = '16px';
  240. res.style.textAlign = 'center';
  241. res.style.paddingLeft = '2px';
  242. res.style.paddingBottom = '2px';
  243. res.style.cursor = 'pointer';
  244. $(res).attr('href', result.matchLink);
  245. $(res).attr('target', '_blank');
  246. $(res).attr('title', result.tooltip);
  247. res.addEventListener('mouseover', () => {
  248. [...result.element.querySelectorAll('td')].forEach(column => column.classList.add('promotion'))
  249. })
  250. res.addEventListener('mouseleave', () => {
  251. [...result.element.querySelectorAll('td')].forEach(column => column.classList.remove('promotion'))
  252. })
  253. switch (result.result) {
  254. case WIN:
  255. $(res).css('background-color', WIN_COLOR);
  256. res.textContent = 'W';
  257. break;
  258. case DRAW:
  259. $(res).css('background-color', DRAW_COLOR);
  260. res.textContent = 'D';
  261. break;
  262. case LOSE:
  263. $(res).css('background-color', LOSE_COLOR);
  264. res.textContent = 'L';
  265. break;
  266. case UPCOMING:
  267. $(res).css('background-color', UPCOMING_COLOR);
  268. res.textContent = '?';
  269. break;
  270. default:
  271. break;
  272. }
  273. streak.appendChild(res);
  274. }
  275. }
  276.  
  277. generateMatchsHistory();
  278.  
  279. function enlargeTable() {
  280. $('div.main_center').css('width', '1100px');
  281. $('.column2_a').css('width', '590px');
  282. }
  283.  
  284. enlargeTable()
  285.  
  286.  
  287. /**
  288. * Show team logos
  289. */
  290. let teamIds = []
  291. function getAllTeamIds() {
  292. $('#overall_table').find('[club_link]').each(function(index, team) {
  293. teamIds.push($(team).attr('club_link'))
  294. })
  295.  
  296. teamIds.map(loadTeam)
  297. }
  298.  
  299. getAllTeamIds()
  300.  
  301. /**
  302. * Load team information
  303. */
  304. function loadTeam(id) {
  305. $.post('/ajax/tooltip.ajax.php', {club_id: id}, data => {
  306. if (data != null) {
  307. const logo = data.club.logo_url
  308. $('#overall_table [club_link="' + id + '"]').parent().prepend('<img src="' + logo + '" width="26px" height="26px" />')
  309. $('#overall_table [club_link="' + id + '"]').parent().html('<div style="display: flex;align-items: center;gap: 4px;">' + $('#overall_table [club_link="' + id + '"]').parent().html() + '</div>')
  310. }
  311. }, 'json');
  312. }
  313. })();

QingJ © 2025

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