TMVN Squad BP WA XP

Trophymanager: display bank price, wage and routine of players

当前为 2020-11-02 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name TMVN Squad BP WA XP
  3. // @version 4
  4. // @description Trophymanager: display bank price, wage and routine of players
  5. // @namespace https://trophymanager.com
  6. // @include https://trophymanager.com/club/*/squad/*
  7. // @include https://trophymanager.com/club/*/squad/*
  8. // @include https://trophymanager.com/club/%20/squad/
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. function collect() {
  13. var ret = {};
  14. var len = arguments.length;
  15. for (var i = 0; i < len; i++) {
  16. for (var p in arguments[i]) {
  17. if (arguments[i].hasOwnProperty(p)) {
  18. ret[p] = arguments[i][p];
  19. }
  20. }
  21. }
  22. return ret;
  23. }
  24.  
  25. var new_player_array = [];
  26. var team_b_id = "";
  27. var team_main_id = $('.box_sub_header a')[1].getAttribute('club_link'); //for find exactly b-team
  28.  
  29. $.ajaxSetup({
  30. async: false
  31. });
  32.  
  33. $.post("/ajax/players_get_select.ajax.php", {
  34. "type": "change",
  35. "club_id": SUBPAGE
  36. }, function (data) {
  37.  
  38. data = JSON.parse(data);
  39. new_player_array = data.post;
  40.  
  41. });
  42.  
  43. function objectLength(obj) {
  44. var result = 0;
  45. for (var prop in obj) {
  46. if (obj.hasOwnProperty(prop)) {
  47. result++;
  48. }
  49. }
  50. return result;
  51. }
  52.  
  53. $("#player_table tr:eq(0)")[0].childNodes[5].innerHTML = 'Recommend';
  54. $("#player_table tr:eq(0)").append('<th align="right">BP</th><th align="right">WA</th><th align="right">XP</th>');
  55. var count = 0;
  56. var countU21 = 0;
  57. var totalBankPrice = 0;
  58. var totalBankPriceU21 = 0;
  59. var totalWage = 0;
  60. var totalWageU21 = 0;
  61. var totalASI = 0;
  62. var totalASIU21 = 0;
  63. var totalXP = 0;
  64. var totalXPU21 = 0;
  65.  
  66. var national = $('.box_sub_header a')[2].getAttribute('href').substring(16, 18);
  67.  
  68. $("#player_table tr > .text_fade > div").not(".text_fade_overlay").find("a[player_link]").each(function () {
  69.  
  70. player_link = $(this).attr("player_link");
  71. if (new_player_array[player_link] == null && team_b_id === "") {
  72. //console.log("finding team b id");
  73. $.post("https://trophymanager.com/ajax/players_get_info.ajax.php", {
  74. "player_id": player_link,
  75. "type": "history",
  76. "show_non_pro_graphs": false
  77. }, function (data) {
  78. data = JSON.parse(data);
  79. try {
  80. let i = 0;
  81. do {
  82. team_b_id = data.table.nat[i].klub_id;
  83. i++;
  84. } while (team_b_id == "" || team_b_id == team_main_id);
  85. } catch (err) {
  86. team_b_id = "";
  87. }
  88. });
  89.  
  90. if (team_b_id !== "") {
  91. $.post("/ajax/players_get_select.ajax.php", {
  92. "type": "change",
  93. "club_id": team_b_id
  94. }, function (data) {
  95. data = JSON.parse(data);
  96. new_player_array = collect(new_player_array, data.post);
  97. });
  98. }
  99. }
  100.  
  101. current_player_info = new_player_array[player_link];
  102. if (current_player_info == null) {
  103. return;
  104. }
  105.  
  106. parent_select = $(this).parent().parent().parent();
  107. parent_select.find("td:eq(2)").append("." + Number(current_player_info.month));
  108.  
  109. let pow = Math.pow;
  110. let bp = 0;
  111. if (current_player_info.fp === "GK") {
  112. bp = (current_player_info.asi * 500 * pow((300 / (Number(current_player_info.age) * 12 + Number(current_player_info.month))), 2.5)) * 0.75;
  113. } else {
  114. bp = (current_player_info.asi * 500 * pow((300 / (Number(current_player_info.age) * 12 + Number(current_player_info.month))), 2.5));
  115. }
  116.  
  117. if (current_player_info.country !== national) {
  118. parent_select.append('<td align="right" style="color:Blue;">' + (bp / 1000000).toFixed(1) + '</td>');
  119. } else {
  120. parent_select.append('<td align="right">' + (bp / 1000000).toFixed(1) + '</td>');
  121. }
  122. parent_select.append('<td align="right" style="color:Orange;">' + Math.round(current_player_info.wage / 1000) + '</td>');
  123. parent_select.append('<td align="right">' + current_player_info.rutine + '</td>');
  124.  
  125. if (Number(current_player_info.age) > 21) {
  126. count++;
  127. } else {
  128. countU21++;
  129. }
  130. if (Number(current_player_info.age) > 21) {
  131. totalBankPrice += bp;
  132. } else {
  133. totalBankPriceU21 += bp;
  134. }
  135. if (Number(current_player_info.age) > 21) {
  136. totalWage += Number(current_player_info.wage);
  137. } else {
  138. totalWageU21 += Number(current_player_info.wage);
  139. }
  140. if (Number(current_player_info.age) > 21) {
  141. totalASI += current_player_info.asi;
  142. } else {
  143. totalASIU21 += current_player_info.asi;
  144. }
  145. if (Number(current_player_info.age) > 21) {
  146. totalXP += Number(current_player_info.rutine);
  147. } else {
  148. totalXPU21 += Number(current_player_info.rutine);
  149. }
  150. });
  151.  
  152. var clubId = $('.box_sub_header a')[1].getAttribute('club_link');
  153. if (clubId) {
  154. localStorage.setItem(clubId + "_SQUAD_VALUE", JSON.stringify({
  155. "Time": new Date(),
  156. "BP": (totalBankPrice + totalBankPriceU21),
  157. "Wage": (totalWage + totalWageU21),
  158. "Count": (count + countU21)
  159. }));
  160. localStorage.setItem(clubId + "_U21_SQUAD_VALUE", JSON.stringify({
  161. "Time": new Date(),
  162. "BP": (totalBankPriceU21),
  163. "Wage": (totalWageU21),
  164. "Count": (countU21)
  165. }));
  166. localStorage.setItem(clubId + "_O21_SQUAD_VALUE", JSON.stringify({
  167. "Time": new Date(),
  168. "BP": (totalBankPrice),
  169. "Wage": (totalWage),
  170. "Count": (count)
  171. }));
  172. }
  173.  
  174. $('div.column3_a')[0].childNodes[3].childNodes[3].childNodes[2].childNodes[1].innerHTML +=
  175. '<br>' +
  176. 'Total Bank Price: <span style="color:Orange;">' + totalBankPrice.toFixed(0).replace(/\B(?=(\d{3})+(?!\d))/g, ",") + '</span><br>' +
  177. 'Total Wage: <span style="color:Orange;">' + totalWage.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + '</span><br>' +
  178. 'Total ASI: <span style="color:Orange;">' + totalASI.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + '</span><br>' +
  179. 'Total XP: <span style="color:Orange;">' + totalXP.toFixed(1) + '</span><br>' +
  180. '<br>' +
  181. 'Average Bank Price: <span style="color:Orange;">' + (totalBankPrice / (count > 0 ? count : 1)).toFixed(0).replace(/\B(?=(\d{3})+(?!\d))/g, ",") + '</span><br>' +
  182. 'Average Wage: <span style="color:Orange;">' + Math.round(totalWage / (count > 0 ? count : 1)).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + '</span><br>' +
  183. 'Average ASI: <span style="color:Orange;">' + (totalASI / (count > 0 ? count : 1)).toFixed(0).replace(/\B(?=(\d{3})+(?!\d))/g, ",") + '</span><br>' +
  184. 'Average XP: <span style="color:Orange;">' + (totalXP / (count > 0 ? count : 1)).toFixed(1) + '</span><br>';
  185.  
  186. $('div.column3_a')[0].childNodes[3].childNodes[3].childNodes[6].childNodes[1].innerHTML +=
  187. '<br>' +
  188. 'Total Bank Price: <span style="color:Orange;">' + totalBankPriceU21.toFixed(0).replace(/\B(?=(\d{3})+(?!\d))/g, ",") + '</span><br>' +
  189. 'Total Wage: <span style="color:Orange;">' + totalWageU21.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + '</span><br>' +
  190. 'Total ASI: <span style="color:Orange;">' + totalASIU21.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + '</span><br>' +
  191. 'Total XP: <span style="color:Orange;">' + totalXPU21.toFixed(1) + '</span><br>' +
  192. '<br>' +
  193. 'Average Bank Price: <span style="color:Orange;">' + (totalBankPriceU21 / (countU21 > 0 ? countU21 : 1)).toFixed(0).replace(/\B(?=(\d{3})+(?!\d))/g, ",") + '</span><br>' +
  194. 'Average Wage: <span style="color:Orange;">' + Math.round(totalWageU21 / (countU21 > 0 ? countU21 : 1)).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + '</span><br>' +
  195. 'Average ASI: <span style="color:Orange;">' + (totalASIU21 / (countU21 > 0 ? countU21 : 1)).toFixed(0).replace(/\B(?=(\d{3})+(?!\d))/g, ",") + '</span><br>' +
  196. 'Average XP: <span style="color:Orange;">' + (totalXPU21 / (countU21 > 0 ? countU21 : 1)).toFixed(1) + '</span><br>';
  197.  
  198. $.ajaxSetup({
  199. async: true
  200. });