TMVN Squad BP WA XP

Modify from ASI in Squad Overview script

当前为 2020-10-24 提交的版本,查看 最新版本

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