Greasy Fork is available in English.

GLB Offered Contract Sort

sdfsdf

  1. // ==UserScript==
  2. // @name GLB Offered Contract Sort
  3. // @namespace pbr
  4. // @include http://goallineblitz.com/game/team_offers.pl?team_id=*
  5. // @copyright 2008, pabst
  6. // @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
  7. // @version 09.04.01
  8. // @description sdfsdf
  9. // ==/UserScript==
  10.  
  11. /*
  12. *
  13. * written by pabst 12/26/08+
  14. *
  15. */
  16.  
  17. var removeConfirmation = false;
  18.  
  19. window.setTimeout(
  20. function() {
  21. sort_main();
  22. },
  23. 1000
  24. );
  25.  
  26. function sort_main() {
  27. var remove = document.getElementsByClassName("offer");
  28. var contracts = new Array();
  29. for (var i=remove.length-1; i>-1; i--) {
  30. contracts[i] = remove[i].parentNode.removeChild(remove[i]);
  31. }
  32. var positions = new Array();
  33. var levels = new Array();
  34. for (var i=0; i<contracts.length; i++) {
  35. var lev = contracts[i].getElementsByTagName("b")[0].innerHTML.split(" ")[1];
  36. var pos = contracts[i].getElementsByTagName("b")[0].innerHTML.split(" ")[2];
  37. positions[i] = pos;
  38. levels[i] = lev;
  39. }
  40.  
  41. sortTriplet(levels, positions, contracts);
  42. var p = ["QB","HB","FB","TE","WR","C","G","OT","DT","DE","LB","CB","SS","FS","K","P"];
  43. for (var i=0; i<p.length; i++) {
  44. showPosition(p[i],contracts, positions, levels);
  45. }
  46. getRosterPage();
  47. }
  48.  
  49. function showPosition(pos, contracts, positions, levels) {
  50. var div = document.createElement("div");
  51. div.setAttribute("class","nonalternating_color pbr_positions");
  52. div.setAttribute("style","margin: 5px; clear: both;")
  53. div.innerHTML = pos;
  54. var div2 = document.createElement("div");
  55. div2.setAttribute("class","offers");
  56. var offerblock = document.getElementById("sent_offers");
  57. for (var i=0; i<positions.length; i++) {
  58. if (positions[i] == pos) {
  59. div2.appendChild(contracts[i]);
  60. }
  61. }
  62.  
  63. offerblock.appendChild(div);
  64. offerblock.appendChild(div2);
  65. }
  66.  
  67. function sortTriplet(arr1, arr2, arr3) {
  68. for (var i=0; i<arr1.length-1; i++) {
  69. for (var j=i; j<arr1.length; j++) {
  70. if (parseFloat(arr1[i]) < parseFloat(arr1[j])) {
  71. var temp = arr1[i];
  72. arr1[i] = arr1[j];
  73. arr1[j] = temp;
  74. temp = arr2[i];
  75. arr2[i] = arr2[j];
  76. arr2[j] = temp;
  77.  
  78. temp = arr3[i];
  79. arr3[i] = arr3[j];
  80. arr3[j] = temp;
  81. }
  82. }
  83. }
  84. }
  85.  
  86. function getRosterPage() {
  87. var addr = window.location.href.toString().replace("team_offers","roster");
  88. GM_xmlhttpRequest({
  89. method: 'GET',
  90. url: addr,
  91. headers: {
  92. 'User-agent': 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9) Gecko/2008052912 Firefox/3.0 Greasemonkey',
  93. 'Accept': 'text/xml'
  94. },
  95. onload: function(page) {
  96. showSignedPlayers(page.responseText);
  97. }
  98. });
  99. }
  100.  
  101. function showSignedPlayers(page) {
  102. var div = document.createElement("div");
  103. div.setAttribute("style","visibility: hidden");
  104. div.innerHTML = page;
  105. document.getElementById("footer").appendChild(div);
  106. // console.log(page);
  107. var pos = document.getElementsByClassName("position");
  108. var lvl = document.getElementsByClassName("player_level");
  109. var headings = document.getElementsByClassName("pbr_positions")
  110. for (var i=0; i<headings.length; i++) {
  111. var signed = getPositionString(headings[i].innerHTML,pos,lvl);
  112. headings[i].innerHTML += ": " + signed.length + " players signed";
  113. headings[i].innerHTML += " ("+signed.sort(sortFunc)+")";
  114. }
  115. div.parentNode.removeChild(div);
  116. }
  117.  
  118. function sortFunc(a, b) {
  119. return a < b;
  120. }
  121.  
  122. function getPositionString(pos, positions, levels) {
  123. var output = [];
  124. for (var i=0; i<positions.length; i++) {
  125. var ind = positions[i].innerHTML.indexOf("<");
  126. if (ind != -1) {
  127. positions[i].innerHTML = positions[i].innerHTML.slice(0,ind);
  128. }
  129. //console.log(pos + " |||| "+positions[i].innerHTML);
  130. if (pos == positions[i].innerHTML) {
  131. output.push(parseInt(levels[i].innerHTML));
  132. }
  133. }
  134. //console.log(pos+" -- "+output);
  135. return output;
  136. }
  137.  
  138. unsafeWindow.deleteOffer = function(id) {
  139. var teamId = window.location.href.toString();
  140. teamId = teamId.slice(teamId.indexOf("=")+1);
  141. if (removeConfirmation == false) {
  142. if (confirm("Really delete this offer?")) {
  143. unsafeWindow.redirectTo('/game/team_offers.pl?team_id=' + teamId + '&delete_offer=' + id);
  144. }
  145. }
  146. else {
  147. var iframe = document.createElement("frame");
  148. iframe.setAttribute("id","iframe_"+id);
  149. iframe.setAttribute("style","visibility: hidden;");
  150. iframe.setAttribute("src",'/game/team_offers.pl?team_id=' + teamId + '&delete_offer=' + id);
  151. document.getElementById("footer").appendChild(iframe);
  152.  
  153. var links = document.links;
  154. for (var i=0; i<links.length; i++) {
  155. var onclick = links[i].getAttribute("onclick");
  156. if (onclick == "deleteOffer('"+id+"')") {
  157. links[i].innerHTML = "Deleting ...";
  158. break;
  159. }
  160. }
  161. deletionDelay(id);
  162. }
  163. }
  164.  
  165. function deletionDelay(id) {
  166. var done = false;
  167.  
  168. var iframe = document.getElementById("iframe_"+id);
  169. if (iframe != null) {
  170. try {
  171. var footer = iframe.contentDocument.getElementById("footer");
  172. if (footer != null) {
  173. done = true;
  174. }
  175. }
  176. catch (e) {
  177. done = true;
  178. }
  179. }
  180. if (done == false) {
  181. setTimeout(function() {
  182. deletionDelay(id);
  183. }, 1000);
  184. }
  185. else {
  186. if (iframe == null) console.log("why is iframe null?");
  187. iframe.parentNode.removeChild(iframe);
  188.  
  189. var links = document.links;
  190. for (var i=0; i<links.length; i++) {
  191. var onclick = links[i].getAttribute("onclick");
  192. if (onclick == "deleteOffer('"+id+"')") {
  193. var container = links[i].parentNode.parentNode;
  194. container.parentNode.removeChild(container);
  195. break;
  196. }
  197. }
  198. }
  199. }