My Match Analyzer-New

none

  1. // ==UserScript==
  2. // @name My Match Analyzer-New
  3. // @namespace *trophymanager.com/matches*
  4. // @include *trophymanager.com/matches*
  5. // @version 3
  6. // @grant none
  7. // @description none
  8. // ==/UserScript==
  9.  
  10. function installFunc(source) {
  11. /*
  12. // Check for function input.
  13. if ('function' == typeof source) {
  14. // Execute this function with no arguments, by adding parentheses.
  15. // One set around the function, required for valid syntax, and a
  16. // second empty set calls the surrounded function.
  17. source = '(' + source + ')();'
  18. }
  19. */
  20. // Create a script node holding this source code.
  21. var script = document.createElement('script');
  22. script.setAttribute("type", "application/javascript");
  23. script.textContent = source;
  24.  
  25. // Insert the script node into the page, so it will run
  26. document.body.appendChild(script);
  27. }
  28.  
  29. /*
  30. Taken from http://www.tomhoppe.com/index.php/2008/03/dynamically-adding-css-through-javascript/
  31. */
  32. function addCss(cssCode) {
  33. var styleElement = document.createElement("style");
  34. styleElement.type = "text/css";
  35. if (styleElement.styleSheet) {
  36. styleElement.styleSheet.cssText = cssCode;
  37. } else {
  38. styleElement.appendChild(document.createTextNode(cssCode));
  39. }
  40. document.getElementsByTagName("head")[0].appendChild(styleElement);
  41. }
  42.  
  43. function loadJS(filename)
  44. {
  45. var fileref=document.createElement('script');
  46. fileref.setAttribute("type","text/javascript");
  47. fileref.setAttribute("src", filename);
  48. document.getElementsByTagName("head")[0].appendChild(fileref);
  49. }
  50.  
  51. function clickAnalyze()
  52. {
  53. //get match id
  54. var mid = document.URL.split(".com/")[1].split("/")[1].split("#")[0].split("?")[0];
  55. container = document.getElementById("mma_data");
  56. container.value = JSON.stringify(match_data);
  57. midc = document.getElementById("mma_mid");
  58. midc.value = JSON.stringify(match_id);
  59. mids = document.getElementById("mma_season");
  60. mids.value = JSON.stringify($("a[title]").first().html().split(' ')[1])
  61.  
  62. if (!end_of_game)
  63. alert("Wait for match to end")
  64. else
  65. {
  66. myform = document.getElementById("mma_form");
  67. myform.action = "http://trophyhelptool.com/mma/report.php";
  68. myform.submit();
  69. }
  70. }
  71.  
  72. function clickSave()
  73. {
  74. //get match id
  75. var mid = document.URL.split(".com/")[1].split("/")[1].split("#")[0].split("?")[0];
  76. container = document.getElementById("mma_data");
  77. container.value = JSON.stringify(match_data);
  78. midc = document.getElementById("mma_mid");
  79. midc.value = JSON.stringify(match_id);
  80. mids = document.getElementById("mma_season");
  81. mids.value = JSON.stringify($("a[title]").first().html().split(' ')[1])
  82.  
  83. if (!end_of_game)
  84. alert("Wait for match to end")
  85. else
  86. {
  87. myform = document.getElementById("mma_form");
  88. myform.action = "http://trophyhelptool.com/mma/savereport.php";
  89. myform.submit();
  90. }
  91. }
  92.  
  93. window.addEventListener('load', function (e)
  94. {
  95. installFunc( clickAnalyze );
  96. installFunc( clickSave );
  97. installFunc( addCss );
  98. installFunc( loadJS );
  99. var fileref=document.createElement('script');
  100. fileref.setAttribute("type","text/javascript");
  101. fileref.setAttribute("src", "http://trophyhelptool.com/mma/json2.js");
  102. document.getElementsByTagName("head")[0].appendChild(fileref);
  103. loadJS("http://trophyhelptool.com/mma/json2.js");
  104. addCss(".mma_big { height: 30px; width: 400px; background: url(http://trophyhelptool.herobo.com/mma/scr_back.png); position: fixed; bottom: 0px; left: 10px; z-index: 10;}");
  105. addCss(".mma_analyze { left: 200px; top: 5px; height: 20px; position: relative; width: 60px; float: left; background: url(http://trophyhelptool.herobo.com/mma/analyze.png); }");
  106. addCss(".mma_analyze:hover { background: url(http://trophyhelptool.com/mma/analyze_hover.png); cursor: pointer; }");
  107. addCss(".mma_saverep { left: 220px; top: 5px; height: 20px; position: relative; width: 100px; float: left; background: url(http://trophyhelptool.herobo.com/mma/saverep.png); }");
  108. addCss(".mma_saverep:hover { background: url(http://trophyhelptool.herobo.com/mma/saverep_hover.png); cursor: pointer; }");
  109.  
  110. thisform = document.createElement("form");
  111. thisform.method = "post";
  112. thisform.setAttribute("id", "mma_form");
  113. thisform.setAttribute("target", "_blank");
  114. formdata = document.createElement("input");
  115. formdata.setAttribute("id", "mma_data");
  116. formdata.setAttribute("type", "hidden");
  117. formdata.setAttribute("name", "data");
  118. thisform.appendChild(formdata);
  119. formmid = document.createElement("input");
  120. formmid.setAttribute("id", "mma_mid");
  121. formmid.setAttribute("type", "hidden");
  122. formmid.setAttribute("name", "mid");
  123. thisform.appendChild(formmid);
  124. formseason = document.createElement("input");
  125. formseason.setAttribute("id", "mma_season");
  126. formseason.setAttribute("type", "hidden");
  127. formseason.setAttribute("name", "season");
  128. thisform.appendChild(formseason)
  129. document.body.appendChild(thisform);
  130.  
  131. div = document.createElement("div");
  132. div.setAttribute("class", "mma_big");
  133. div.innerHTML = '<div class="mma_analyze" onclick="clickAnalyze();"></div><div class="mma_saverep" onclick="clickSave();"></div>';
  134. document.body.appendChild(div);
  135. }, false);