Replay Rewrite - First Down Lines On Replay

Adds down and scrimmage lines to GLB replays viewed with the replay rewrite script.

  1. // ==UserScript==
  2. // @name Replay Rewrite - First Down Lines On Replay
  3. // @description Adds down and scrimmage lines to GLB replays viewed with the replay rewrite script.
  4. // @include http://*goallineblitz.com/game/replay.pl?game_id=*&pbp_id=*
  5. // @include http://glb.warriorgeneral.com/game/replay.pl?game_id=*&pbp_id=*
  6. // @copyright 2009, pabst
  7. // @namespace pbr/fdlor
  8. // @license (CC) Attribution Share Alike; http://creativecommons.org/licenses/by-sa/3.0/
  9. // @version 13.12.291
  10. // @require https://greasyfork.org/scripts/1371-libpbr2/code/libpbr2.js?version=3533
  11. // ==/UserScript==
  12.  
  13. /*
  14. *
  15. * pabst did this 09/08/01+
  16. *
  17. *
  18. */
  19.  
  20. var scriptName = "First Down Lines";
  21. var scriptVersion = "13.12.29";
  22. var scriptWebpage = "http://userscripts.org/scripts/show/54522";
  23.  
  24. window.setTimeout(
  25. function() {
  26. try {
  27. init();
  28. }
  29. catch (e) {
  30. console.log(e);
  31. }
  32. }
  33. , 100);
  34.  
  35. function activate(e) {
  36. console.log("activate first down lines");
  37. lock();
  38. removeDownLines();
  39. createDownLines();
  40.  
  41. unlock();
  42. }
  43.  
  44. function removeDownLines() {
  45. var ds = document.getElementById("ds");
  46. if (ds != null) ds.parentNode.removeChild(ds);
  47. var los = document.getElementById("los");
  48. if (los != null) los.parentNode.removeChild(los);
  49. var fdm = document.getElementById("fdm");
  50. if (fdm != null) fdm.parentNode.removeChild(fdm);
  51. }
  52.  
  53. function createDownLines() {
  54. try {
  55. //console.log("createDownLines");
  56. var play_data = unsafeWindow.play_data[0];
  57.  
  58. var fdcolor = "yellow";
  59. var play_container = document.getElementById("replay_area");
  60. var header = document.getElementById("replay_header");
  61. var dir = header.getElementsByTagName("h1")[0];
  62. var dirText = dir.innerHTML;
  63. var ytg = "";
  64. if(dirText.indexOf(" inches ")!=-1) {
  65. ytg = '.3';
  66. }
  67. else {
  68. if(dirText.indexOf(" G on ")!=-1) {
  69. // later
  70. }
  71. else {
  72. var p2 = dirText.indexOf(" & ")+7;
  73. var p1 = dirText.indexOf(" on ");
  74. ytg = dirText.substring(p2,p1);
  75. if (dirText.substring(p2-10,p2-9) == "4") {
  76. fdcolor = "red";
  77. }
  78. }
  79. }
  80. if (play_data != null) {
  81. //line of scrimmage
  82. var greater=0;
  83. for (var i=1; i<play_data.length; i++) {
  84. if (play_data[i].y > play_data[0].y) greater++;
  85. else greater--;
  86. }
  87. var diff = (greater / Math.abs(greater));
  88. if (diff < 0) diff = -4;
  89. else diff = 1;
  90. //console.log("diff="+diff);
  91. var pid = 999;
  92. for (var i=0; i<document.images.length; i++) {
  93. if (document.images[i].src.indexOf("/C.gif") != -1) {
  94. pid = parseInt(document.images[i].parentNode.id.split("_")[2]);
  95. break;
  96. }
  97. }
  98. if (pid == 999) return;
  99. for (var i=0; i<play_data.length; i++) {
  100. if (play_data[i].id == pid) {
  101. pid = i;
  102. break;
  103. }
  104. }
  105. if (play_data[pid] != null) {
  106. var los = parseFloat(play_data[pid].y);
  107. los = los * 3 + 40;
  108. los = los + 1;
  109.  
  110. var div = document.createElement('div');
  111. div.id = 'los';
  112. div.style.top = (los + diff) + 'px';
  113. div.style.position = "absolute";
  114. div.style.width = '520px';
  115. div.style.height = '2px';
  116. div.style.backgroundColor = 'blue';
  117. div.style.zIndex = playerLayerZ-32;
  118. play_container.appendChild(div);
  119. //end los
  120.  
  121. //first down marker
  122. diff = Math.abs(diff)/diff * ytg * 9;
  123. los = parseFloat(play_data[pid].y);
  124. los = los * 3 + 40;
  125. los = los + (Math.abs(diff)/diff)*2;
  126.  
  127. div = document.createElement('div');
  128. div.id = 'fdm';
  129. div.style.top = (los + diff) + 'px';
  130. div.style.position = "absolute";
  131. div.style.width = '520px';
  132. div.style.height = '2px';
  133. div.style.backgroundColor = fdcolor;
  134. div.style.zIndex = playerLayerZ-32;
  135. play_container.appendChild(div);
  136. //end fdm
  137. }
  138. else {
  139. console.log(play_data.length+" -- "+pid+" : play_data[0][pid] == null");
  140. }
  141. }
  142. }
  143. catch (e) {
  144. console.log(e);
  145. }
  146. }