Star players and match result quickly

You can immediately find out the result of the league match in the viewing mode of the match, as well as the starting lineups in the stars.

  1. // ==UserScript==
  2. // @name Star players and match result quickly
  3. // @version 3.7
  4. // @author Spieler17
  5. // @description You can immediately find out the result of the league match in the viewing mode of the match, as well as the starting lineups in the stars.
  6. // @include https://trophymanager.com/matches/*
  7. // @namespace https://greasyfork.org/users/32455
  8. // @grant function
  9. // ==/UserScript==
  10.  
  11. var funShowStars;
  12. function isOKForShow(){
  13. var loading =document.getElementsByClassName("loading")[0];
  14. var shown=document.getElementById("mystarbox");
  15. if(loading!=null)
  16. return false;
  17. if(shown!=null)
  18. return false;
  19. return true;
  20. }
  21.  
  22. function countStars(str) {
  23. var num1=str.lastIndexOf("_")+1;
  24. var num2=str.lastIndexOf("\"");
  25. return parseInt(str.substring(num1,num2));
  26. }
  27.  
  28. function getStars(starnum) {
  29. var num= Math.round(starnum*100/55);
  30. if(num<10)return "<img src=\"/pics/half_star.png\"><img src=\"/pics/dark_star.png\"><img src=\"/pics/dark_star.png\"><img src=\"/pics/dark_star.png\"><img src=\"/pics/dark_star.png\"> (";
  31. if(num<20)return "<img src=\"/pics/star.png\"><img src=\"/pics/dark_star.png\"><img src=\"/pics/dark_star.png\"><img src=\"/pics/dark_star.png\"><img src=\"/pics/dark_star.png\"> (";
  32. if(num<30)return "<img src=\"/pics/star.png\"><img src=\"/pics/half_star.png\"><img src=\"/pics/dark_star.png\"><img src=\"/pics/dark_star.png\"><img src=\"/pics/dark_star.png\"> (";
  33. if(num<40)return "<img src=\"/pics/star.png\"><img src=\"/pics/star.png\"><img src=\"/pics/dark_star.png\"><img src=\"/pics/dark_star.png\"><img src=\"/pics/dark_star.png\"> (";
  34. if(num<50)return "<img src=\"/pics/star.png\"><img src=\"/pics/star.png\"><img src=\"/pics/half_star.png\"><img src=\"/pics/dark_star.png\"><img src=\"/pics/dark_star.png\"> (";
  35. if(num<61)return "<img src=\"/pics/star.png\"><img src=\"/pics/star.png\"><img src=\"/pics/star.png\"><img src=\"/pics/dark_star.png\"><img src=\"/pics/dark_star.png\"> (";
  36. if(num<72)return "<img src=\"/pics/star.png\"><img src=\"/pics/star.png\"><img src=\"/pics/star.png\"><img src=\"/pics/half_star.png\"><img src=\"/pics/dark_star.png\"> (";
  37. if(num<84)return "<img src=\"/pics/star.png\"><img src=\"/pics/star.png\"><img src=\"/pics/star.png\"><img src=\"/pics/star.png\"><img src=\"/pics/dark_star.png\"> (";
  38. if(num<93.5)return "<img src=\"/pics/star.png\"><img src=\"/pics/star.png\"><img src=\"/pics/star.png\"><img src=\"/pics/star.png\"><img src=\"/pics/half_star.png\"> (";
  39. return "<img src=\"/pics/star.png\"><img src=\"/pics/star.png\"><img src=\"/pics/star.png\"><img src=\"/pics/star.png\"><img src=\"/pics/star.png\"> (";
  40. }
  41.  
  42. function ShowStars()
  43. {
  44. if(isOKForShow()==true)
  45. {
  46. var divs=document.getElementsByClassName("player_field")[0].getElementsByTagName("div");
  47. var i = 0;
  48. var home=0;
  49. var away=0;
  50. for(;i<=10;i++)
  51. home+=countStars(divs[i*2].innerHTML);
  52. for(;i<=21;i++)
  53. away+=countStars(divs[i*2].innerHTML);
  54. home=home/2;
  55. home=home.toFixed(1);
  56. away=away/2;
  57. away=away.toFixed(1);
  58. var newdiv=document.createElement("div");
  59. newdiv.innerHTML="<br><div id=\"mystarbox\" class=\"home color\" style=\"background-color:rgb(127,127,127)\"><b style=\"color: gold;\">"+getStars(home)+home+"/55)</b></div><div class=\"away color\" style=\"background-color:rgb(10,5,76)\"><b style=\"color: gold;\">"+getStars(away)+away+"/55)</b></div>";
  60. document.getElementsByClassName("nameplate")[0].appendChild(newdiv);
  61. }
  62. }
  63.  
  64. if (location.href.indexOf("matches") != -1)
  65. {
  66. funShowStars=setInterval(ShowStars,700);
  67. var welcome = document.createElement("div");
  68. welcome.className = "final_score";
  69. welcome.innerHTML="<center><a href=\"javascript:getResult()\">Match result </a></center>";
  70. document.getElementsByClassName("abs output stats text_center")[0].appendChild(welcome);
  71. var MatchId = location.href.split(".com/")[1].split("/")[1].split("#")[0].split("?")[0];
  72. var title = document.getElementsByTagName("head")[0];
  73. var myscript = document.createElement("script");
  74. myscript.type="text/javascript";
  75. var str= "function getResult(){\n";
  76. str+="$.ajax({\n";
  77. str+="type: \'GET\',\n";
  78. str+="url: \'https://trophymanager.com/ajax/match.ajax.php\',\n";
  79. str+="data: { id: "+MatchId+"},\n";
  80. str+="dataType: 'json',\n";
  81. str+="success: function(data){ \n";
  82. str+="var ObjectReport =data.report;\n";
  83. str+="if (ObjectReport==null){\n";
  84. str+="$(\'.final_score\')[0].innerHTML=\"<p>Match result</p>\";}\n";
  85. str+="else{var size=Object.keys(ObjectReport).length;\n";
  86. str+="var keys=Object.keys(ObjectReport)[size-1];\n";
  87. str+="var lastString=data.report[keys][0].chance.text;\n";
  88. str+="var tableBefore= lastString.toString().split(\' \');\n";
  89. str+="for (var i = 0; i < tableBefore.length; i++) { \n";
  90. str+="var index = tableBefore[i].indexOf(\'-\');\n";
  91. str+="if (index > -1) { lastIndex=i;}}\n";
  92. str+="$(\'.final_score\')[0].innerHTML=\"<p style=\'font-family:arial;font-size:14px;\'>Match result <b>\"+tableBefore[lastIndex]+\"</b></p>\";\n";
  93. str+="}}});}\n";
  94. myscript.innerHTML=str;
  95. title.appendChild(myscript);
  96. }