Greasy Fork is available in English.

pbr Game Scout

modification of tciss(?)'s game scout script for GoalLineBlitz.com

Dieses Skript sollte nicht direkt installiert werden. Es handelt sich hier um eine Bibliothek für andere Skripte, welche über folgenden Befehl in den Metadaten eines Skriptes eingebunden wird // @require https://update.greatest.deepsurf.us/scripts/1348/3550/pbr%20Game%20Scout.js

  1. // ==UserScript==
  2. // @name pbr Game Scout
  3. // @description modification of tciss(?)'s game scout script for GoalLineBlitz.com
  4. // @namespace pbr
  5. // @include http://goallineblitz.com/game/game.pl?game_id=*&mode=pbp
  6. // @include http://goallineblitz.com/game/game.pl?game_id=*&mode=pbp&quarter=*
  7. // @include http://goallineblitz.com/game/team.pl?*
  8. // @include http://goallineblitz.com/game/player_game_log.pl?*
  9. // @include http://glb.warriorgeneral.com/game/game.pl?game_id=*&mode=pbp
  10. // @include http://glb.warriorgeneral.com/game/game.pl?game_id=*&mode=pbp&quarter=*
  11. // @include http://glb.warriorgeneral.com/game/team.pl?*
  12. // @include http://glb.warriorgeneral.com/game/player_game_log.pl?*
  13. // @require https://greatest.deepsurf.us/scripts/1371-libpbr2/code/libpbr2.js?version=3533
  14. // @require https://greatest.deepsurf.us/scripts/1372-pbr-game-scout-uilib/code/pbr%20Game%20Scout%20uilib.js?version=3540
  15. // @require https://greatest.deepsurf.us/scripts/1373-pbr-game-scout-statslib/code/pbr%20Game%20Scout%20statslib.js?version=3538
  16. // @copyright 2008, pabst
  17. // @license (CC) Attribution Share Alike; http://creativecommons.org/licenses/by-sa/3.0/
  18. // @version 13.12.29
  19. // ==/UserScript==
  20.  
  21. /*
  22. *
  23. * based on code by tciss from www.goallineblitz.com
  24. * pabst modified it 6/22/08+
  25. *
  26. */
  27.  
  28. // you can modify the following variables
  29. var showEverything = false; //this will SERIOUSLY slow down loading multiple games
  30. var longPass = 15;
  31. var mediumPass = 7.5;
  32. var shortPass = 0;
  33. // you can modify the previous variables
  34.  
  35. var storageStats = [];
  36. var forceTeam = null;
  37.  
  38. window.setTimeout(
  39. function() {
  40. runTeamScout();
  41. },
  42. 1500
  43. );
  44.  
  45. function runTeamScout() {
  46. console.log("start");
  47.  
  48. var scoutTable;
  49. try {
  50. scoutTable = getEmptyTables();
  51. }
  52. catch (err) {
  53. console.log("normal for replay rewrite : "+err);
  54. return;
  55. }
  56. scoutTable.addEventListener("game loaded",fillScoutTable,true);
  57. scoutTable.addEventListener("table sort",sortTable,true);
  58.  
  59. var location = document.getElementById("pbp");
  60. if (location != null) {
  61. var div = document.createElement('div');
  62. div.setAttribute("id","storage:"+window.location);
  63. div.setAttribute("class","GSstorage");
  64. div.setAttribute("style","visibility:hidden; display:none;");
  65. div.innerHTML = document.getElementsByTagName("body")[0].innerHTML;
  66. //console.log(div.innerHTML);
  67. document.getElementById("footer").appendChild(div);
  68. location.parentNode.insertBefore(scoutTable,location);
  69. var checkBox = document.createElement("input");
  70. checkBox.checked = true;
  71. checkBox.setAttribute("class","GScheckbox");
  72. checkBox.setAttribute("id",window.location+"");
  73. checkBox.setAttribute("style","visibility:hidden;");
  74. document.getElementById("footer").appendChild(checkBox);
  75. showEverything = true;
  76. }
  77. else {
  78. location = document.getElementById("footer");
  79. location.parentNode.insertBefore(scoutTable,location);
  80. }
  81.  
  82. var scheduleContent = document.getElementsByClassName("schedule_content");
  83. if (scheduleContent.length > 0) { //on a team page?
  84. for (var scidx=0; scidx<scheduleContent.length; scidx++) {
  85. var schedules = scheduleContent[scidx];
  86. var rows = schedules.rows;
  87. rows[0].cells[1].innerHTML = "[GS] "+rows[0].cells[1].innerHTML;
  88. for (var i=1; i<rows.length; i++) {
  89. var link = rows[i].cells[2].firstChild.href+"&mode=pbp";
  90. var oldCell = rows[i].cells[1];
  91. rows[i].deleteCell(1);
  92. var checkBox = document.createElement("input");
  93. checkBox.setAttribute("type","checkbox");
  94. checkBox.setAttribute("id",link);
  95. checkBox.setAttribute("class","GScheckbox");
  96. var div = document.createElement("span");
  97. div.appendChild(checkBox);
  98. for (var cidx=0; cidx<oldCell.childNodes.length; cidx++) {
  99. var c = oldCell.childNodes[cidx];
  100. if (c == null) continue;
  101. var c2 = c.nextSibling;
  102. div.appendChild(c);
  103. if (c2 != null) {
  104. div.appendChild(c2);
  105. }
  106. }
  107. var newCell = rows[i].insertCell(1);
  108. newCell.appendChild(div);
  109. }
  110. }
  111. }
  112. else {
  113. var tbl = document.getElementById("career_stats");
  114. if (tbl != null) { //on a player's game log
  115. //console.log("player game log");
  116. forceTeam = [];
  117. var rows = tbl.rows;
  118. for (var i=2; i<rows.length; i++) {
  119. if (rows[i].getAttribute("class").indexOf("nonalternating") != -1) {
  120. break;
  121. }
  122. var s = rows[i].cells[1].innerHTML;
  123. s = s.slice(s.indexOf("team_id=")+"team_id=".length);
  124. s = s.slice(0,s.indexOf('"'));
  125. forceTeam[i-2] = parseFloat(s);
  126. var link = rows[i].cells[3].firstChild.href+"&mode=pbp";
  127. var oldCell = rows[i].cells[0];
  128. rows[i].deleteCell(0);
  129. var checkBox = document.createElement("input");
  130. checkBox.setAttribute("type","checkbox");
  131. checkBox.setAttribute("id",link);
  132. checkBox.setAttribute("class","GScheckbox");
  133. var div = document.createElement("span");
  134. div.appendChild(checkBox);
  135. for (var cidx=0; cidx<oldCell.childNodes.length; cidx++) {
  136. var c = oldCell.childNodes[cidx];
  137. if (c == null) continue;
  138. var c2 = c.nextSibling;
  139. div.appendChild(c);
  140. if (c2 != null) {
  141. div.appendChild(c2);
  142. }
  143. }
  144. var newCell = rows[i].insertCell(0);
  145. newCell.appendChild(div);
  146. }
  147. }
  148. }
  149. storageStats = new Array(document.getElementsByClassName("GScheckbox").length);
  150.  
  151. var button = document.createElement("input");
  152. button.setAttribute("value","Run Game Scout");
  153. button.setAttribute("type","button");
  154. button.setAttribute("id","gsbutton");
  155. button.addEventListener("click",input,false);
  156.  
  157. var counter = document.createElement("div");
  158. counter.setAttribute("class","medium_head");
  159. counter.setAttribute("id","gspagecounter");
  160. counter.innerHTML = "0 of 0";
  161.  
  162. var spn = document.createElement("span");
  163. spn.appendChild(button);
  164. spn.appendChild(counter);
  165. scoutTable.insertBefore(spn,scoutTable.firstChild);
  166. }
  167. //---------------------- end --------------------------------
  168.  
  169. function handlePageLoad(address,page) {
  170. var storage = document.getElementById('storage:'+address);
  171. var index = -1;
  172. var s = document.getElementsByClassName("GScheckbox");
  173. for (var i=0; i<s.length; i++) {
  174. if (s[i].id == address) {
  175. index = i;
  176. break;
  177. }
  178. }
  179. if (storageStats[index] == null) {
  180. storage.innerHTML = page.responseText.replace(/<img/g,"<div").replace(/\/img/g,"/div>");
  181. storageStats[index] = gameScout(address,storage);
  182. if (window.location.toString().indexOf("mode=pbp") != -1) {
  183. //on the play by play
  184. //cannot delete storage so filtering still works
  185. }
  186. else {
  187. storage.innerHTML = "";
  188. }
  189. }
  190. else {
  191. console.log("already calculated: "+address);
  192. }
  193. var tscout = document.getElementById("gamescout");
  194. var evt = document.createEvent("HTMLEvents");
  195. evt.initEvent("game loaded",false,false);
  196. tscout.dispatchEvent(evt);
  197. }
  198.  
  199. var total = null;
  200. function fillScoutTable() {
  201. var fstFinished = true;
  202. clearPageCount();
  203. var checkBoxes = document.getElementsByClassName("GScheckbox");
  204. for (var i=0; i<storageStats.length; i++) {
  205. if (checkBoxes[i].checked == true) {
  206. if (storageStats[i] == null) {
  207.  
  208.  
  209.  
  210. fstFinished = false;
  211. }
  212. else {
  213. incrementPageCount();
  214. }
  215. }
  216. }
  217. if (fstFinished == false) {
  218. return;
  219. }
  220. if (total != null) return;
  221. total = new Stats();
  222. if (document.getElementById("career_stats") != null) { //on a game log
  223. total.team_name[0] = "My Team";
  224. total.team_id[0] = forceTeam;
  225. total.team_name[1] = "Opponents";
  226. }
  227. else {
  228. var teamHeading = document.getElementsByClassName("big_head subhead_head");
  229. if (teamHeading[0].childNodes.length == 1) { //on a team page
  230. total.team_name[0] = teamHeading[0].innerHTML;
  231. total.team_id[0] = (window.location+"").slice((window.location+"").indexOf("team_id=")+8);
  232. total.team_name[1] = "Opponents";
  233. var id = (window.location+"").slice((window.location+"").indexOf("team_id=")+8);
  234. total.team_id[0] = new Array(checkBoxes.length);
  235. for (var i=0; i<total.team_id[0].length; i++) {
  236. total.team_id[0][i] = id;
  237. }
  238. }
  239. else if (teamHeading[0].firstChild.innerHTML == null) {
  240. //on a team page with rename link
  241. var str = teamHeading[0].innerHTML;
  242. str = str.slice(0,str.indexOf(" (<a href="));
  243. total.team_name[0] = str;
  244. total.team_name[1] = "Opponents";
  245. var id = (window.location+"").slice((window.location+"").indexOf("team_id=")+8);
  246. total.team_id[0] = new Array(checkBoxes.length);
  247. for (var i=0; i<total.team_id[0].length; i++) {
  248. total.team_id[0][i] = id;
  249. }
  250. }
  251. else {
  252. // on a play-by-play page
  253. total.team_name[0] = teamHeading[0].firstChild.innerHTML;
  254. total.team_name[1] = teamHeading[0].lastChild.innerHTML;
  255. }
  256. }
  257. var stats = [];
  258. //console.log(checkBoxes.length+" -- "+storageStats.length);
  259. for (var i=0; i<checkBoxes.length; i++) {
  260. if (checkBoxes[i].checked == true) {
  261. var s = eval(uneval(storageStats[i]));
  262. if (total.team_id[0] == null) {
  263. total = addition(total, s);
  264. }
  265. else if (total.team_id[0].length != null) {
  266. var save = total.team_id[0];
  267. total.team_id[0] = save[i];
  268. total = addition(total, s);
  269. total.team_id[0] = save;
  270. }
  271. else {
  272. total = addition(total, s);
  273. }
  274. stats.push(storageStats[i]);
  275. }
  276. }
  277. fillTables(total);
  278.  
  279. var tables = document.getElementById("gamescout");
  280. changeVisibility(0,2);
  281. tables.setAttribute("style","visibility: visible;");
  282. if (window.location.toString().match("team.pl")) {
  283. var addr = (window.location+"").replace("team.pl","roster.pl");
  284. var div = document.getElementById("storage:"+addr);
  285. if (div == null) {
  286. getInetPage(addr, parsePlayerFromRoster);
  287. }
  288. else {
  289. p = []; p.page = div.innerHTML;
  290. parsePlayerFromRoster(addr,p);
  291. }
  292. }
  293. else if (window.location.toString().match("player_game_log.pl")) {
  294. var last = null;
  295. for (var i=0; i<total.team_id[0].length; i++) {
  296. if (total.team_id[0][i] != last) {
  297. var addr = "/game/roster.pl?team_id="+total.team_id[0][i];
  298. var div = document.getElementById("storage:"+addr);
  299. if (div == null) {
  300. getInetPage(addr, parsePlayerFromRoster);
  301. }
  302. else {
  303. p = []; p.page = div.innerHTML;
  304. parsePlayerFromRoster(addr,p);
  305. }
  306. }
  307. last = total.team_id[0][i];
  308. }
  309. }
  310. else { //on a play-by-play page
  311. var addr = window.location.toString();
  312. addr = addr.slice(0,addr.indexOf("&mode=pbp"));
  313. var div = document.getElementById("storage:"+addr);
  314. if (div == null) {
  315. getInetPage(addr,parsePlayerFromBoxScore);
  316. }
  317. else {
  318. p = []; p.page = div.innerHTML;
  319. parsePlayerFromBoxScore(addr,p);
  320. }
  321. storageStats = new Array(document.getElementsByClassName("GScheckbox").length);
  322. }
  323. }
  324.  
  325. function clearPageCount() {
  326. var text = document.getElementById("gspagecounter");
  327. text.innerHTML = "0 of ";
  328. var inc = 0;
  329. var checkBoxes = document.getElementsByClassName("GScheckbox");
  330. for (var cidx=0; cidx<checkBoxes.length; cidx++) {
  331. var c = checkBoxes[cidx];
  332. if (c.checked == true) {
  333. inc++;
  334. }
  335. }
  336. text.innerHTML += inc;
  337. }
  338. function incrementPageCount() {
  339. var text = document.getElementById("gspagecounter");
  340. var num = parseInt(text.innerHTML.slice(0,2));
  341. num += 1;
  342. text.innerHTML = num+" "+text.innerHTML.slice(text.innerHTML.indexOf("of"));
  343. }
  344.  
  345. function input() {
  346. /*
  347. var location = document.getElementById("pbp");
  348. if (location != null) {
  349. var old = document.getElementById("storage:"+window.location);
  350. if (old != null) {
  351. old.parentNode.removeChild(old);
  352. }
  353. var div = document.createElement('div');
  354. div.setAttribute("id","storage:"+window.location);
  355. div.setAttribute("class","GSstorage");
  356. div.setAttribute("style","visibility:hidden; display:none;");
  357. div.innerHTML = document.getElementsByTagName("body")[0].innerHTML;
  358. //console.log(div.innerHTML);
  359. document.getElementById("footer").appendChild(div);
  360. }
  361. */
  362. total = null;
  363. positionsFilled = false;
  364. var updating = false;
  365. clearPageCount();
  366. var checkBoxes = document.getElementsByClassName("GScheckbox");
  367. //console.log("cb.len="+checkBoxes.length);
  368. for (var i=0; i<checkBoxes.length; i++) {
  369. if (checkBoxes[i] == null) continue;
  370.  
  371. if (checkBoxes[i].checked == true) {
  372. var storage = document.getElementById("storage:"+checkBoxes[i].id);
  373. if (storage == null) {
  374. //haven't downloaded this game yet
  375. var div = document.createElement('div');
  376. div.setAttribute("id","storage:"+checkBoxes[i].id);
  377. div.setAttribute("class","GSstorage");
  378. div.setAttribute("style","visibility:hidden; display:none;");
  379. document.getElementById("footer").appendChild(div);
  380.  
  381. console.log("downloading this one: "+checkBoxes[i].id);
  382. updating = true;
  383. getInetPage(checkBoxes[i].id, handlePageLoad);
  384. }
  385. else {
  386. //downloaded this one already
  387. //hold off on updating the tables for now
  388. console.log("already downloaded this one: "+checkBoxes[i].id);
  389. var p = [];
  390. p.responseText = storage.innerHTML;
  391. handlePageLoad(checkBoxes[i].id,p);
  392. }
  393. }
  394. }
  395. if (updating == false) {
  396. //updating = true;
  397. //make sure tables have updated at least once
  398. fillScoutTable();
  399. }
  400. }
  401.  
  402.  
  403. //------------ start box score loading ------------------------
  404.  
  405. function parsePlayerFromBoxScore(address, page) {
  406. console.log("parsePlayerFromBoxScore("+address+")");
  407. var s = document.getElementById("storage:"+address);
  408. if (s == null) {
  409. var footer = document.getElementById("footer");
  410. var div = document.createElement("div");
  411. div.setAttribute("id","storage:"+address);
  412. div.setAttribute("style","visibility: hidden; display:none;");
  413. div.innerHTML = page.responseText.replace(/<img/g,"<div").replace(/\/img/g,"/div>");
  414. footer.appendChild(div);
  415. }
  416. else {
  417. page.responseText = s.innerHTML;
  418. }
  419. var text = page.responseText.replace(/<img/g,"<div").replace(/\/img/g,"/div>");
  420. var playerLinks = [];
  421. var header = "<td class=\"box_score_player_stat_name\">";
  422.  
  423. var t = text;
  424. var i=-1;
  425. while ( (i=t.indexOf(header)) != -1) {
  426. t = t.slice(i+header.length);
  427.  
  428. if (t.indexOf("<span") != 0) {
  429. continue;
  430. }
  431. var end = t.indexOf("</td");
  432. playerLinks.push(t.slice(0,end));
  433. t = t.slice(end+1);
  434. }
  435. addPositionsToTables(playerLinks);
  436. console.log("end --> parsePlayerFromBoxScore("+address+")");
  437. }
  438.  
  439. function parsePlayerFromRoster(address, page) {
  440. console.log("parsePlayerFromRoster("+address+")");
  441. var s = document.getElementById("storage:"+address);
  442. if (s == null) {
  443. var footer = document.getElementById("footer");
  444. var div = document.createElement("div");
  445. div.setAttribute("id","storage:"+address);
  446. div.setAttribute("style","visibility: hidden; display:none;");
  447. div.innerHTML = page.responseText.replace(/<img/g,"<div").replace(/\/img/g,"/div>");
  448. footer.appendChild(div);
  449. }
  450. var playerLinks = [];
  451. var s = document.getElementById("storage:"+address);
  452. var l = s.getElementsByClassName("player_name");
  453. for (var pidx=0; pidx<l.length; pidx++) {
  454. var p = l[pidx];
  455. if (p.parentNode == null) continue;
  456. var name = p.firstChild.innerHTML;
  457. var pos = p.parentNode.getElementsByClassName("player_position")[0].firstChild.innerHTML;
  458. while (pos.length < 4) {
  459. pos += "&nbsp;";
  460. }
  461. var html = "<span class=\"cpu\">"+pos+"</span>"+name;
  462. playerLinks.push(html);
  463. }
  464. addPositionsToTables(playerLinks);
  465. }
  466.  
  467. function addPositionsToTables(playerLinks) {
  468. console.log("addPositionsToTables()");
  469. var nodes = document.getElementsByClassName("pbp_pbr_title_row");
  470. for (var i=0;i<nodes.length; i++) {
  471. var rowName = nodes[i].firstChild.innerHTML;
  472. for (var pidx=0; pidx<playerLinks.length; pidx++) {
  473. var p = playerLinks[pidx];
  474. if (trim(rowName).length == 0) continue;
  475.  
  476. if ((p.indexOf(">"+rowName+"<") != -1) ||
  477. (p.indexOf("> "+rowName+"<") != -1) ||
  478. (p.indexOf(">"+rowName+" <") != -1)) {
  479. nodes[i].firstChild.innerHTML = p;
  480. }
  481. else if (p.indexOf(">"+fixEscapedText(rowName)+"<") != -1) {
  482. nodes[i].firstChild.innerHTML = p;
  483. }
  484. }
  485. }
  486. }
  487.  
  488. //------------ end box score loading ------------------------
  489.  
  490.  
  491.  
  492. //------------ game scout start -----------------------------
  493.  
  494. function arrayPush(ct, arr1, data1, arr2, data2) {
  495. if (arr1 == null) console.log("arr1 is null");
  496. if (arr1[ct] == null) console.log("arr["+ct+"] is null");
  497. //console.log("ap arr1["+ct+"]--> "+arr1[ct]);
  498. var d = trim(data1);
  499. var index = arr1[ct].indexOf(d);
  500. if (index == -1) {
  501. index = arr1[ct].length;
  502. arr1[ct].push(d);
  503. arr2[ct].push(data2);
  504. }
  505. return index;
  506. }
  507.  
  508. function convertTime(s) {
  509. if (s == null) {
  510. console.log("convertTime == null | '"+s+"'");
  511. return 0;
  512. }
  513. var v = s.split(':');
  514. return parseFloat(v[0])*60 + parseFloat(v[1]);
  515. }
  516.  
  517. function yardReverse(marker) {
  518. var y = parseFloat(marker.slice(4));
  519. if (marker.indexOf("OWN") == 0) return "OPP "+y;
  520. else return "OWN "+y;
  521. }
  522.  
  523. function kickDistance(start, add) {
  524. if ((start == null) || (add == null)) return 0;
  525. var y = parseFloat(start.slice(4));
  526. if (start.slice(0,3) == "OPP") {
  527. y = 100-y;
  528. }
  529. y += add;
  530. if (y < 50) {
  531. y = "OWN "+y;
  532. }
  533. else {
  534. y = 100 - y;
  535. y = "OPP "+y;
  536. }
  537. return y;
  538. }
  539.  
  540. function yardAddition(start, add) {
  541. if ((start == null) || (add == null)) return 0;
  542. var y = parseFloat(start.slice(4));
  543. if (start.slice(0,3) == "OPP") {
  544. y += 50;
  545. }
  546. y += add;
  547. if (y < 50) {
  548. y = "OWN "+y;
  549. }
  550. else {
  551. y = 100 - y;
  552. y = "OPP "+y;
  553. }
  554. //console.log(start+" - "+add+" : "+y);
  555. return y;
  556. }
  557.  
  558. function yardDiff(start, end) {
  559. if ((start == null) || (end == null)) return 0;
  560. var starty = parseFloat(start.slice(4));
  561. var endy = parseFloat(end.slice(4));
  562. //console.log(starty+"--"+endy);
  563. var yards = -1000;
  564. if (start.slice(0,3) == "OWN") {
  565. if (end.slice(0,3) == "OWN") {
  566. yards = endy - starty;
  567. }
  568. else {
  569. yards = 100-endy-starty;
  570. }
  571. }
  572. else if (start.slice(0,3) == "OPP") {
  573. if (end.slice(0,3) == "OPP") {
  574. yards = starty - endy;
  575. }
  576. else {
  577. yards = starty+endy-100;
  578. }
  579. }
  580. return yards;
  581. }
  582.  
  583. function Play() {
  584. this.quarter;
  585. this.team;
  586. this.timeRemaining;
  587. this.timeoutsRemaining;
  588. this.marker;
  589. this.down;
  590. this.togo;
  591. this.play;
  592. this.replay;
  593. this.yards;
  594. this.toString = function() {
  595. return this.quarter+" : "+this.team+" - "+this.timeRemaining+" - "+
  596. this.marker+" - "+this.down+"&"+this.togo;
  597. }
  598. }
  599.  
  600. function penaltyHandler(stats, p) {
  601. var playText = p.play;
  602.  
  603. var s1 = playText.indexOf(" penalty committed by ")
  604. var s2 = s1 + (" penalty committed by ").length;
  605. var penalty = playText.slice(0,s1);
  606. var player = playText.slice(s2);
  607. if (penalty == "False start") {
  608. var ct = current_team;
  609. var playerIndex = arrayPush(ct,stats.playerPenaltyName,player,
  610. stats.playerPenaltyStats,[0,0,0]);
  611. stats.playerPenaltyStats[ct][playerIndex][0] += 1;
  612. stats.team_penalty[ct*6+0] += 1;
  613. stats.team_penalty[ct*6+(parseFloat(p.quarter))] += 1;
  614. }
  615. else if (penalty == "Offside") {
  616. var ct = (current_team+1)%2;
  617. var playerIndex = arrayPush(ct,stats.playerPenaltyName,player,
  618. stats.playerPenaltyStats,[0,0,0]);
  619. stats.playerPenaltyStats[ct][playerIndex][1] += 1;
  620. stats.team_penalty[ct*6+0] += 1;
  621. stats.team_penalty[ct*6+(parseFloat(p.quarter))] += 1;
  622. }
  623. else if (penalty == "Encroachment") {
  624. var ct = (current_team+1)%2;
  625. var playerIndex = arrayPush(ct,stats.playerPenaltyName,player,
  626. stats.playerPenaltyStats,[0,0,0]);
  627. stats.playerPenaltyStats[ct][playerIndex][2] += 1;
  628. stats.team_penalty[ct*6+0] += 1;
  629. stats.team_penalty[ct*6+(parseFloat(p.quarter))] += 1;
  630. }
  631. else {
  632. console.log("report this!!! ==>> unknown penalty : "+penalty);
  633. }
  634. return stats;
  635. }
  636.  
  637. function sliceBrackets(str, idx) {
  638. //console.log(str);
  639. var lead = str.substring(0,idx);
  640. var slice = str.substring(idx).indexOf("]");
  641. var tail = str.substring(lead.length+slice);
  642.  
  643. var string = lead+tail;
  644. //console.log(string);
  645. return string;
  646. }
  647.  
  648. function defenseHandler(stats, shift, p, playType) {
  649. //defenders
  650. var playText = p.play;
  651. var ct = (current_team+1)%2;
  652. var dt = false;
  653. var s1 = -1;
  654.  
  655.  
  656. playText = playText.replace( new RegExp("diving tackle: ","g"), "tackle: ");
  657. playText = playText.replace("[Big Hit tackle: ","[tackle: ");
  658. playText = playText.replace("[Monster Hit tackle: ","[tackle: ");
  659. playText = playText.replace("[Big Sack tackle: ","[tackle: ");
  660.  
  661. var s1 = playText.indexOf("[tackle: ");
  662. if (s1 == -1) {
  663. s1 = playText.indexOf("[diving tackle: ");
  664. dt = true;
  665. }
  666. if (s1 != -1) {
  667. if (dt == false) s1 += "[tackle: ".length;
  668. else s1 += "[diving tackle: ".length;
  669.  
  670. var s2 = playText.slice(s1).indexOf("]");
  671. s = playText.slice(s1,s1+s2);
  672. //s = trim(s); //am I necessary?
  673. //console.log(s);
  674. var defeat = false;
  675. var stop = 0.45;
  676. if (p.down == 2) stop = 0.6;
  677. if (p.down > 2) {
  678. stop = 1.0;
  679. defeat = true;
  680. }
  681. if (playType == "rush") {
  682. var playerIndex = arrayPush(ct,stats.playerDefensiveRushName,s,
  683. stats.playerDefensiveRushStats,[0,0,0,0,0,0]);
  684. stats.playerDefensiveRushStats[ct][playerIndex][0] += 1;
  685. stats.playerDefensiveRushStats[ct][playerIndex][2] += p.yards;
  686. if (p.yards < (p.togo*stop)) {
  687. stats.playerDefensiveRushStats[ct][playerIndex][3] += 1;
  688. if ((defeat == true) || (p.yards < 0)) {
  689. stats.playerDefensiveRushStats[ct][playerIndex][4] += 1;
  690. }
  691. }
  692. //console.log(stats.playerDefensiveRushName[ct][playerIndex]+" -- "+stats.playerDefensiveRushStats[ct][playerIndex]+" : "+p.play);
  693. }
  694. else if (playType == "pass") {
  695. var playerIndex = arrayPush(ct,stats.playerDefensivePassName,s,
  696. stats.playerDefensivePassStats,[0,0,0,0,0,0,0,0,0]);
  697. stats.playerDefensivePassStats[ct][playerIndex][0] += 1;
  698. stats.playerDefensivePassStats[ct][playerIndex][2] += p.yards;
  699. if (p.yards < (p.togo*stop)) {
  700. stats.playerDefensivePassStats[ct][playerIndex][3] += 1;
  701. if ((defeat == true) || (p.yards < 0)) {
  702. stats.playerDefensivePassStats[ct][playerIndex][4] += 1;
  703. }
  704. }
  705. }
  706. else if (playType == "st") {
  707. var playerIndex = arrayPush(ct,stats.playerDefensiveSTName,s,
  708. stats.playerDefensiveSTStats,[0,0,0,0]);
  709. stats.playerDefensiveSTStats[ct][playerIndex][0] += 1;
  710. stats.playerDefensiveSTStats[ct][playerIndex][2] += p.yards;
  711. }
  712. else console.log("defenseHandler says WTF?!?!");
  713. }
  714.  
  715. var string = playText+"";
  716.  
  717. //var string = sliceBrackets(p.play, s1);
  718.  
  719. while ( (s1 = string.indexOf("[missed tackle: ")) != -1) {
  720. string = string.slice(s1+"[missed tackle: ".length);
  721. s2 = string.indexOf("]");
  722. if (string.indexOf(" (Spin)]") > 0) {
  723. s2 = Math.min(s2,string.indexOf(" (Spin)]"));
  724. }
  725. else if (string.indexOf(" (Juke)]") > 0) {
  726. s2 = Math.min(s2,string.indexOf(" (Juke)]"));
  727. }
  728. else if (string.indexOf(" (Power Through)]") > 0) {
  729. s2 = Math.min(s2,string.indexOf(" (Power Through)]"));
  730. }
  731. else if (string.indexOf(" (Lower the Shoulder)]") > 0) {
  732. s2 = Math.min(s2,string.indexOf(" (Lower the Shoulder)]"));
  733. }
  734. else if (string.indexOf(" (Stiff Arm)]") > 0) {
  735. s2 = Math.min(s2,string.indexOf(" (Stiff Arm)]"));
  736. }
  737. else if (string.indexOf(" (Hurdle)]") > 0) {
  738. s2 = Math.min(s2,string.indexOf(" (Hurdle)]"));
  739. }
  740. s = string.slice(0,s2);
  741. //s = trim(s); // am I necessary?
  742.  
  743. if (playType == "rush") {
  744. var playerIndex = arrayPush(ct,stats.playerDefensiveRushName,s,
  745. stats.playerDefensiveRushStats,[0,0,0,0,0,0]);
  746. stats.playerDefensiveRushStats[ct][playerIndex][1] += 1;
  747. }
  748. else if (playType == "pass") {
  749. var playerIndex = arrayPush(ct,stats.playerDefensivePassName,s,
  750. stats.playerDefensivePassStats,[0,0,0,0,0,0,0,0,0]);
  751. stats.playerDefensivePassStats[ct][playerIndex][1] += 1;
  752. }
  753. else if (playType == "st") {
  754. var playerIndex = arrayPush(ct,stats.playerDefensiveSTName,s,
  755. stats.playerDefensiveSTStats,[0,0,0,0]);
  756. stats.playerDefensiveSTStats[ct][playerIndex][1] += 1;
  757. }
  758. else console.log("defenseHandler says WTF?!?!");
  759. string = string.slice(s2);
  760. }
  761. //forced fumble
  762. string = p.play+"";
  763. if ( (s1 = string.indexOf("[forced fumble: ")) != -1) {
  764. string = string.slice(s1+"[forced fumble: ".length);
  765. s2 = string.indexOf("]");
  766. s = string.slice(0,s2);
  767. if (playType == "rush") {
  768. var playerIndex = arrayPush(ct,stats.playerDefensiveRushName,s,
  769. stats.playerDefensiveRushStats,[0,0,0,0,0,0]);
  770. stats.playerDefensiveRushStats[ct][playerIndex][5] += 1;
  771. }
  772. else if (playType == "pass") {
  773. var playerIndex = arrayPush(ct,stats.playerDefensivePassName,s,
  774. stats.playerDefensivePassStats,[0,0,0,0,0,0,0,0,0]);
  775. stats.playerDefensivePassStats[ct][playerIndex][5] += 1;
  776. }
  777. else if (playType == "st") {
  778. var playerIndex = arrayPush(ct,stats.playerDefensiveSTName,s,
  779. stats.playerDefensiveSTStats,[0,0,0,0]);
  780. stats.playerDefensiveSTStats[ct][playerIndex][3] += 1;
  781. }
  782. else console.log("defenseHandler says WTF?!?!");
  783. }
  784. if (playType == "pass") {
  785. //deflected by
  786. string = p.play+"";
  787.  
  788. var kl = string.indexOf(", knocked loose by ") != -1;
  789. while ( (s1 = string.indexOf("[deflected by ")) != -1) {
  790. string = string.slice(s1+"[deflected by ".length);
  791. s2 = string.indexOf("]");
  792. s = string.slice(0,s2);
  793. //s = trim(s); // am I necessary?
  794. if ((string.indexOf("(incomplete)") != -1) ||
  795. (string.indexOf("(incomplete - bad throw)") != -1)) {
  796. var playerIndex = arrayPush(ct,stats.playerDefensivePassName,s,
  797. stats.playerDefensivePassStats,[0,0,0,0,0,0,0,0,0]);
  798. stats.playerDefensivePassStats[ct][playerIndex][7] += 1;
  799. //stats.playerDefensivePassStats[ct][playerIndex][3] += 1;
  800. if (p.down > 2) {
  801. //stats.playerDefensivePassStats[ct][playerIndex][4] += 1;
  802. }
  803. if (kl == true) {
  804. stats.playerDefensivePassStats[ct][playerIndex][8] += 1;
  805. }
  806. }
  807. string = string.slice(s2);
  808. }
  809. string = p.play+"";
  810. if ( (s1 = string.indexOf(" sacked by ")) != -1) {
  811. string = string.slice(s1+" sacked by ".length);
  812. s2 = string.indexOf(" (");
  813. s = string.slice(0,s2);
  814. //console.log(p.yards+" -- "+p.play);
  815. if (p.yards < 0) {
  816. var playerIndex = arrayPush(ct,stats.playerDefensivePassName,s,
  817. stats.playerDefensivePassStats,[0,0,0,0,0,0,0,0,0]);
  818. stats.playerDefensivePassStats[ct][playerIndex][0] += 1;
  819. stats.playerDefensivePassStats[ct][playerIndex][2] += p.yards;
  820. stats.playerDefensivePassStats[ct][playerIndex][3] += 1;
  821. stats.playerDefensivePassStats[ct][playerIndex][4] += 1;
  822. }
  823. else console.log("DH: fuckup?");
  824. }
  825. }
  826. return stats;
  827. }
  828.  
  829. function intDefenseHandler(stats, shift, p, playType) {
  830. var ct = (current_team+1)%2;
  831. var s1 = -1;
  832. var string = p.play+"";
  833.  
  834. if (playType == "pass") {
  835. //intercepted by
  836. string = p.play+"";
  837. if ( (s1 = string.indexOf(" intercepted by ")) != -1) {
  838. string = string.slice(s1+" intercepted by ".length);
  839. s2 = Math.min(string.indexOf("("),string.indexOf("["));
  840. if (string.indexOf(", PAT m") != -1) {
  841. s2 = Math.min(s2,string.indexOf(", PAT m"));
  842. }
  843. s = string.slice(0,s2);
  844. s = trim(s);
  845.  
  846. if (string.indexOf("yd return") != -1) {
  847. var playerIndex = arrayPush(ct,stats.playerDefensivePassName,s,
  848. stats.playerDefensivePassStats,[0,0,0,0,0,0,0,0,0]);
  849. stats.playerDefensivePassStats[ct][playerIndex][6] += 1;
  850. }
  851. }
  852.  
  853. //deflected by
  854. string = p.play+"";
  855. while ( (s1 = string.indexOf("[deflected by ")) != -1) {
  856. string = string.slice(s1+"[deflected by ".length);
  857. s2 = string.indexOf("]");
  858. s = string.slice(0,s2);
  859.  
  860. if ((string.indexOf("(incomplete)") != -1) ||
  861. (string.indexOf("(incomplete - bad throw)") != -1)) {
  862. var playerIndex = arrayPush(ct,stats.playerDefensivePassName,s,
  863. stats.playerDefensivePassStats,[0,0,0,0,0,0,0,0,0]);
  864. stats.playerDefensivePassStats[ct][playerIndex][7] += 1;
  865. //stats.playerDefensivePassStats[ct][playerIndex][3] += 1;
  866. if (p.down > 2) {
  867.  
  868. //stats.playerDefensivePassStats[ct][playerIndex][4] += 1;
  869. }
  870. }
  871. string = string.slice(s2);
  872. }
  873. }
  874. return stats;
  875. }
  876.  
  877.  
  878. function playHandler(stats, drive,p) {
  879. //console.log("playHandler loop: "+pages+" - "+p.replay);
  880. //console.log(p);
  881. //console.log(p.play);
  882. var playText = p.play;
  883. playText = trim(playText);
  884. var quarter = parseFloat(p.quarter);
  885. var down = parseFloat(p.down);
  886. var togo = -1;
  887. var minGain = -1;
  888.  
  889. if (p.team == stats.team_name[0]) current_team = 0;
  890. else current_team = 1;
  891.  
  892. try {
  893. try {
  894. if (p.togo == null) {
  895. p.togo = -1;
  896. }
  897. else if (p.togo == "G") {
  898. togo = parseFloat(p.marker.slice(4));
  899. }
  900. else if (p.togo.indexOf("inches") != -1) {
  901. togo = 0.5;
  902. }
  903. else {
  904. togo = parseFloat(p.togo);
  905. }
  906. }
  907. catch (err) {
  908. //console.log(err);
  909. togo = 0.5;
  910. }
  911. if (down == 1) {
  912. minGain = togo*0.40;
  913. }
  914. else if (down == 2) {
  915. minGain = togo*0.60;
  916. }
  917. else {
  918. minGain = togo;
  919. }
  920. var sp = -1;
  921. var ep = -1;
  922. var y = NaN;
  923. var yt;
  924.  
  925. var line = playText;
  926. do {
  927. //unfortunately, some people have parentheses in their names
  928. sp = line.indexOf('(')+1;
  929. ep = line.indexOf(')');
  930. if ((sp == -1) || (ep == -1)) {
  931. //no parentheses left in this line
  932. y = NaN;
  933. break;
  934. }
  935. else {
  936. //one complete set of parentheses found
  937. yt = line.slice(sp,ep);
  938. if (yt.indexOf("incomplete") != -1) {
  939. y = 0;
  940. }
  941. else if (yt.indexOf("no gain") != -1) {
  942. y = 0;
  943. }
  944. else {
  945. y = parseFloat(yt);
  946. }
  947. line = line.slice(ep+1);
  948.  
  949. if(yt.indexOf(" yd gain") != -1) {
  950. //y = y;
  951. }
  952. else if(yt.indexOf(" yd loss") != -1) {
  953. y = -y;
  954. }
  955. else if(yt.indexOf(" yd return") != -1) {
  956. }
  957. else if(yt.indexOf("no return") != -1) {
  958. }
  959. else if(yt.indexOf("touchback") != -1) {
  960. }
  961. else {
  962. if (y != 0) { //this stupid parenthesized name has numbers first
  963. y = NaN;
  964. }
  965. }
  966. }
  967. } while (isNaN(y) == true);
  968. }
  969. catch (error) {
  970. console.log(error);
  971. }
  972. p.yards = y;
  973.  
  974. if (drive.numOfPlays == 0) {
  975. drive.driveBegan = null;
  976. drive.quarter = quarter;
  977. lastDrive.endTime = p.timeRemaining;
  978. }
  979. if (drive.startTime == null) {
  980. drive.startTime = p.timeRemaining;
  981. }
  982. if (drive.driveBegan == null) {
  983. drive.driveBegan = p.marker;
  984. }
  985. drive.endTime = p.timeRemaining;
  986. drive.driveEnded = p.marker; // fix me?
  987. drive.numOfPlays++;
  988. //console.log(drive+" -- "+playText.slice(0,30));
  989.  
  990.  
  991. if ((playText.match(" rush") != null) || (playText.match(" pitch to ") != null)) {
  992. //console.log("rush "+playText.slice(0,20));
  993.  
  994. var inside = true;
  995. if (playText.match(" pitch to ") != null) {
  996. inside = false;
  997. }
  998.  
  999. if ((yt.indexOf(" yd return") != -1) || (playText.indexOf("(touchback)") != -1)) {
  1000. //must have been a fumble here
  1001. //can't include without calculating the position
  1002. //and still won't know the direction of the run
  1003. if (drive.numOfPlays == 1) {
  1004. lastDrive.result = "Fumble";
  1005. lastDrive.numOfPlays += 1;
  1006. if (lastDrive.driveBegan == null) {
  1007. lastDrive.driveBegan = p.marker;
  1008. }
  1009. lastDrive.driveEnded = p.marker;
  1010. lastDrive.endTime = p.timeRemaining;
  1011.  
  1012. drive.numOfPlays = 0;
  1013. if (playText.indexOf("[TD]") != -1) {
  1014. drive.result = "Touchdown";
  1015. drive.driveEnded = "OPP 0";
  1016. drive.driveStarted = p.marker;
  1017. }
  1018. }
  1019. // can't display this stuff as I don't know
  1020. // which team recovered if the play was the
  1021. // first play of a drive
  1022. // stats = defenseHandler(stats,0,p,"rush");
  1023. }
  1024. else if(playText.indexOf("[SAFETY]") != -1) {
  1025. //must have been a safety here
  1026. //and, of course, it's a possession for the wrong team
  1027. //ignoring it for now as we don't know where the runner was tackled
  1028. if (drive.numOfPlays == 1) {
  1029. lastDrive.result = "Safety";
  1030. }
  1031. stats = defenseHandler(stats,0,p,"rush");
  1032. }
  1033. else {
  1034. // 0 - 1 - 2 - 3 - 4
  1035. var index = current_team * 5;
  1036. var r1 = -1;
  1037. var r2 = -1;
  1038. var s;
  1039. if (inside == false) {
  1040. if ( (r2 = playText.indexOf(" to the left")) != -1) {
  1041. //index += 0;
  1042. }
  1043. else if( (r2 = playText.indexOf(" up the middle")) != -1) {
  1044. // sometimes outside runs get stuffed immediately, so
  1045. // I'm just calling it a middle run regardless
  1046. index += 2;
  1047. }
  1048. else if ( (r2 = playText.indexOf(" to the right")) != -1) {
  1049. index += 4;
  1050. }
  1051. r3 = playText.indexOf("[missed");
  1052. if (r3 != -1) {
  1053. if (playText[r3-1] == ' ') r3--;
  1054. r2 = Math.min(r2,r3);
  1055. }
  1056. r3 = playText.indexOf(", out of bounds ");
  1057. if (r3 != -1) {
  1058. if (playText[r3-1] == ' ') r3--;
  1059. r2 = Math.min(r2,r3);
  1060. }
  1061. r1 = playText.slice(0,r2).indexOf(" pitch to ")+" pitch to ".length;
  1062. s = playText.slice(r1,r2);
  1063. if ( (r2 = s.indexOf(", PAT m")) != -1) {
  1064. s = s.slice(0,r2);
  1065. }
  1066. }
  1067. else {
  1068. if ( (r2=playText.indexOf(" to the left")) != -1) {
  1069. index += 1;
  1070. }
  1071. else if ( (r2=playText.indexOf(" up the middle")) != -1) {
  1072. index += 2;
  1073. }
  1074. else if ( (r2=playText.indexOf(" to the right")) != -1) {
  1075. index += 3;
  1076. }
  1077. r1 = 0;
  1078. r2 = playText.indexOf(" rush");
  1079. r3 = playText.indexOf("[missed");
  1080. if (r3 != -1) r2 = Math.min(r2,r3);
  1081. s = playText.slice(r1,r2);
  1082. }
  1083. if (s.indexOf(" [TD]") == (s.length-5)) {
  1084. s = s.slice(0,s.length-5);
  1085. }
  1086.  
  1087. var playerIndex = arrayPush(current_team,stats.playerRushingName,s,
  1088. stats.playerRushingStats,[0,0,0,0,0,0]);
  1089. stats.team_att[index] += 1;
  1090. stats.team_yards[index] += y;
  1091. var ytemp = Math.min(y,10);
  1092. var ly = 0;
  1093. if (ytemp < 0) ly += ytemp*1.2;
  1094. else {
  1095. ly += Math.min(ytemp,5);
  1096. if (ytemp > 5) {
  1097. ly += (Math.min(ytemp,10)-5)*0.5;
  1098. }
  1099. }
  1100. stats.team_lyards[index] += ly;
  1101. //console.log(y+" -- "+ytemp+" -- "+ly);
  1102. stats.team_quarter_totals[0][0+current_team*7] += 1;
  1103. stats.team_quarter_totals[0][1+current_team*7] += y;
  1104. stats.team_quarter_totals[quarter][0+current_team*7] += 1;
  1105. stats.team_quarter_totals[quarter][1+current_team*7] += y;
  1106.  
  1107. stats.team_att_down[(down-1)+(current_team*4)] += 1;
  1108. stats.team_yards_down[(down-1)+(current_team*4)] += y;
  1109. stats.team_lyards_down[(down-1)+(current_team*4)] += ly;
  1110.  
  1111. stats.playerRushingStats[current_team][playerIndex][0] += 1;
  1112. stats.playerRushingStats[current_team][playerIndex][1] += y;
  1113. stats.playerRushingStats[current_team][playerIndex][2] =
  1114. Math.max(stats.playerRushingStats[current_team][playerIndex][2],y);
  1115. if (y >= minGain) {
  1116. stats.team_success[index] += 1;
  1117. stats.team_success_down[(down-1)+(current_team*4)] += 1;
  1118.  
  1119. stats.team_quarter_totals[0][2+current_team*7] += 1;
  1120. stats.team_quarter_totals[quarter][2+current_team*7] += 1;
  1121.  
  1122. stats.playerRushingStats[current_team][playerIndex][3] += 1;
  1123. }
  1124. if (y >= togo) {
  1125. stats.team_firsts[index] += 1;
  1126. stats.team_firsts_down[(down-1)+(current_team*4)] += 1;
  1127. stats.playerRushingStats[current_team][playerIndex][4] += 1;
  1128. }
  1129.  
  1130. stats = defenseHandler(stats,0,p,"rush");
  1131.  
  1132. if (playText.indexOf("[TD]") != -1) {
  1133. drive.result = "Touchdown";
  1134. drive.driveEnded = "OPP 0";
  1135. }
  1136. var m = playText.split("[missed tackle:");
  1137. if (m.length > 1) {
  1138. stats.playerRushingStats[current_team][playerIndex][5] += m.length-1;
  1139. }
  1140. m = playText.split("[missed diving tackle:");
  1141. if (m.length > 1) {
  1142. stats.playerRushingStats[current_team][playerIndex][5] += m.length-1;
  1143. }
  1144. }
  1145. //console.log((down-1)+" "+((down-1)+current_team*4)+" "+downs[down_index].innerHTML+" "+playText);
  1146. }
  1147. else if (playText.indexOf(" pass to ") != -1) {
  1148. // console.log(playText);
  1149. playText = playText.replace(" screen pass to ", " pass to ");
  1150. var index = current_team * 3;
  1151. var dindex;
  1152. var isBad = false;
  1153.  
  1154. var p1 = playText.indexOf(" bad pass to ")+" bad pass to ".length;
  1155. if (p1 == (-1 + " bad pass to ".length)) {
  1156. p1 = playText.indexOf(" pass to ")+" pass to ".length;
  1157. }
  1158. else {
  1159. isBad = true;
  1160. }
  1161. var p2;
  1162. if (playText.indexOf(" the left side") != -1) {
  1163. //index += 0;
  1164. dindex = 0;
  1165. p2 = playText.indexOf(" the left side") - 3;
  1166. }
  1167. else if(playText.indexOf(" over the middle") != -1) {
  1168. index += 1;
  1169. dindex = 1;
  1170. p2 = playText.indexOf(" over the middle");
  1171. }
  1172. else if (playText.indexOf(" the right side") != -1) {
  1173. index += 2;
  1174. dindex = 2;
  1175. p2 = playText.indexOf(" the right side") - 3;
  1176. }
  1177.  
  1178. var d = current_team*9 + dindex*3;
  1179. var s = playText.slice(p1,p2);
  1180. var h = s.indexOf(", hurried by");
  1181. if (h != -1) {
  1182. s = s.slice(0,h);
  1183. }
  1184.  
  1185. var qbn = playText.slice(0,playText.indexOf(" pass to"));
  1186. if (isBad == true) {
  1187. qbn = playText.slice(0,playText.indexOf(" bad pass to"));
  1188. }
  1189. var qbIndex = arrayPush(current_team,stats.playerPassingName,qbn,
  1190. stats.playerPassingStats,[0,0,0,0,0,0,0,0,0]);
  1191. var playerIndex = arrayPush(current_team,stats.playerReceivingName,s,
  1192. stats.playerReceivingStats,[0,0,0,0,0,0,0,0,0,0]);
  1193. // console.log(qbn+" : "+qbIndex+" : "+playerIndex);
  1194. if ((yt.indexOf(" yd return") != -1) || (playText.indexOf("(touchback)") != -1)) {
  1195. // some sort of turnover
  1196. if ((playText.indexOf(" intercepted by ") != -1) &&
  1197. (playText.indexOf("fumbled , recovered by") == -1)) {
  1198. //intercepted & not fumbled
  1199. stats.team_pass_att[(index+3)%6] += 1;
  1200. stats.team_pass_att_down[((down-1)+(current_team*4)+4)%8] += 1;
  1201.  
  1202. stats.team_quarter_totals[0][4+((current_team*7)+7)%14] += 1;
  1203. stats.team_quarter_totals[quarter][4+((current_team*7)+7)%14] += 1;
  1204.  
  1205. if (h != -1) {
  1206. stats.team_pass_pressure_down[((down-1)+(current_team*4)+4)%8] += 1;
  1207. stats.team_quarter_totals[0][6+((current_team*7)+7)%14] += 1;
  1208. stats.team_quarter_totals[quarter][6+((current_team*7)+7)%14] += 1;
  1209. }
  1210.  
  1211. stats.playerPassingName[current_team].pop();
  1212. stats.playerPassingStats[current_team].pop();
  1213. stats.playerReceivingName[current_team].pop();
  1214. stats.playerReceivingStats[current_team].pop();
  1215. current_team = (current_team+1)%2;
  1216.  
  1217. var qbIndex = arrayPush(current_team,stats.playerPassingName,qbn,
  1218. stats.playerPassingStats,[0,0,0,0,0,0,0,0,0]);
  1219. var playerIndex = arrayPush(current_team,stats.playerReceivingName,s,
  1220. stats.playerReceivingStats,[0,0,0,0,0,0,0,0,0,0]);
  1221. stats.playerPassingStats[current_team][qbIndex][1] += 1; //att
  1222. stats.playerReceivingStats[current_team][playerIndex][1] += 1;
  1223. stats.playerPassingStats[current_team][qbIndex][4] += 1; //int
  1224. if (h != -1) {
  1225. stats.playerPassingStats[current_team][qbIndex][8] += 1; //pressure
  1226. }
  1227. if (isBad == true) {
  1228. stats.playerPassingStats[current_team][qbIndex][7] += 1; //bad pass
  1229. }
  1230. if (playText.indexOf("[deflected by ") != -1) {
  1231. stats.playerReceivingStats[current_team][playerIndex][6] += 1; //pd
  1232. stats.playerPassingStats[current_team][qbIndex][6] += 1;
  1233. if (playText.indexOf(", knocked loose by ") != -1) {
  1234. stats.playerReceivingStats[current_team][playerIndex][9] += 1; //kl
  1235. }
  1236. }
  1237. //can't do it yet
  1238. stats = intDefenseHandler(stats,2,p,"pass");
  1239. current_team = (current_team+1)%2;
  1240. if (drive.numOfPlays == 1) {
  1241. lastDrive.result = "Interception";
  1242. //console.log(lastDrive.endTime+" -- "+drive.startTime+" -- "+p.timeRemaining);
  1243. lastDrive.numOfPlays += 1;
  1244. lastDrive.endTime = p.timeRemaining;
  1245. if (lastDrive.driveBegan == null) {
  1246. lastDrive.driveBegan = p.marker;
  1247. }
  1248. //console.log(lastDrive+"\n\n"+drive);
  1249. lastDrive.driveEnded = p.marker;
  1250.  
  1251. drive.numOfPlays = 0;
  1252. if (playText.indexOf("[TD]") != -1) {
  1253. drive.result = "Touchdown";
  1254. drive.driveEnded = "OPP 0";
  1255. drive.driveStarted = p.marker;
  1256. }
  1257. }
  1258. }
  1259. else if ((playText.indexOf(" intercepted by ") != -1) &&
  1260. (playText.indexOf("fumbled , recovered by") != -1)) {
  1261. // intercepted and fumbled
  1262. // can't display this stuff as I don't know
  1263. // which team recovered if the play was the
  1264. // first play of a drive
  1265. //stats = defenseHandler(stats,2,p,"pass");
  1266. if (stats.playerPassingStats[current_team][qbIndex][1] == 0) {
  1267. stats.playerPassingName[current_team].pop();
  1268. stats.playerPassingStats[current_team].pop();
  1269. stats.playerReceivingName[current_team].pop();
  1270. stats.playerReceivingStats[current_team].pop();
  1271. }
  1272. if (drive.numOfPlays == 1) {
  1273. lastDrive.result = "Interception";
  1274. //console.log(lastDrive.endTime+" -- "+drive.startTime+" -- "+p.timeRemaining);
  1275. lastDrive.numOfPlays += 1;
  1276. lastDrive.endTime = p.timeRemaining;
  1277. if (lastDrive.driveBegan == null) {
  1278. lastDrive.driveBegan = p.marker;
  1279. }
  1280. //console.log(lastDrive+"\n\n"+drive);
  1281. lastDrive.driveEnded = p.marker;
  1282.  
  1283. drive.numOfPlays = 0;
  1284. if (playText.indexOf("[TD]") != -1) {
  1285. drive.result = "Touchdown";
  1286. drive.driveEnded = "OPP 0";
  1287. drive.driveStarted = p.marker;
  1288. }
  1289. }
  1290. }
  1291. else if ((playText.indexOf(" intercepted by ") == -1) &&
  1292. (playText.indexOf(" recovered by") != -1)) {
  1293.  
  1294. if (stats.playerPassingStats[current_team][qbIndex][1] == 0) {
  1295. stats.playerPassingName[current_team].pop();
  1296. stats.playerPassingStats[current_team].pop();
  1297. stats.playerReceivingName[current_team].pop();
  1298. stats.playerReceivingStats[current_team].pop();
  1299. }
  1300. // not intercepted, but fumbled reception
  1301. // can't display this stuff as I don't know
  1302. // which team recovered if the play was the
  1303. // first play of a drive
  1304. //stats = defenseHandler(stats,2,p,"pass");
  1305. if (drive.numOfPlays == 1) {
  1306. lastDrive.result = "Fumble";
  1307. //console.log(lastDrive.endTime+" -- "+drive.startTime+" -- "+p.timeRemaining);
  1308. lastDrive.numOfPlays += 1;
  1309. lastDrive.endTime = p.timeRemaining;
  1310. if (lastDrive.driveBegan == null) {
  1311. lastDrive.driveBegan = p.marker;
  1312. }
  1313. //console.log(lastDrive+"\n\n"+drive);
  1314. lastDrive.driveEnded = p.marker;
  1315.  
  1316. drive.numOfPlays = 0;
  1317. if (playText.indexOf("[TD]") != -1) {
  1318. drive.result = "Touchdown";
  1319. drive.driveEnded = "OPP 0";
  1320. drive.driveStarted = p.marker;
  1321. }
  1322. }
  1323. }
  1324. }
  1325. else if (yt.indexOf("incomplete") != -1) {
  1326. stats.team_pass_att[index] += 1;
  1327. stats.team_pass_att_down[(down-1)+(current_team*4)] += 1;
  1328.  
  1329. stats.team_quarter_totals[0][4+current_team*7] += 1;
  1330. stats.team_quarter_totals[quarter][4+current_team*7] += 1;
  1331.  
  1332. stats.playerPassingStats[current_team][qbIndex][1] += 1;
  1333. if (h != -1) {
  1334. stats.team_pass_pressure_down[(down-1)+(current_team*4)] += 1;
  1335. stats.playerPassingStats[current_team][qbIndex][8] += 1;
  1336. stats.team_quarter_totals[0][6+current_team*7] += 1;
  1337. stats.team_quarter_totals[quarter][6+current_team*7] += 1;
  1338. }
  1339.  
  1340. var ta = "[thrown away] (incomplete)";
  1341. if (playText.indexOf(ta) != playText.length-ta.length) {
  1342. stats.playerReceivingStats[current_team][playerIndex][1] += 1;
  1343. }
  1344. if (yt.indexOf("dropped - incomplete") != -1) {
  1345. stats.playerPassingStats[current_team][qbIndex][5] += 1;
  1346. stats.playerReceivingStats[current_team][playerIndex][2] += 1;
  1347. }
  1348. else if ((yt.indexOf("incomplete - bad throw") != -1) || (isBad == true)) {
  1349. stats.playerPassingStats[current_team][qbIndex][7] += 1;
  1350. }
  1351. if (playText.indexOf("[deflected by ") != -1) {
  1352. stats.playerPassingStats[current_team][qbIndex][6] += 1;
  1353. stats.playerReceivingStats[current_team][playerIndex][6] += 1;
  1354.  
  1355. stats = defenseHandler(stats,2,p,"pass");
  1356. if (playText.indexOf(", knocked loose by ") != -1) {
  1357. stats.playerReceivingStats[current_team][playerIndex][9] += 1; //kl
  1358. }
  1359. //console.log("pt= '"+playText+"'");
  1360. }
  1361. }
  1362. else {
  1363. stats.team_pass_comp[index] += 1;
  1364. stats.team_pass_att[index] += 1;
  1365. stats.team_pass_yards[index] += y;
  1366.  
  1367. stats.team_quarter_totals[0][3+current_team*7] += 1;
  1368. stats.team_quarter_totals[0][4+current_team*7] += 1;
  1369. stats.team_quarter_totals[0][5+current_team*7] += y;
  1370. stats.team_quarter_totals[quarter][3+current_team*7] += 1;
  1371. stats.team_quarter_totals[quarter][4+current_team*7] += 1;
  1372. stats.team_quarter_totals[quarter][5+current_team*7] += y;
  1373.  
  1374. stats.team_pass_att_down[(down-1)+(current_team*4)] += 1;
  1375. stats.team_pass_comp_down[(down-1)+(current_team*4)] += 1;
  1376. stats.team_pass_yards_down[(down-1)+(current_team*4)] += y;
  1377.  
  1378. stats.playerPassingStats[current_team][qbIndex][0] += 1;
  1379. stats.playerPassingStats[current_team][qbIndex][1] += 1;
  1380. stats.playerPassingStats[current_team][qbIndex][2] += y;
  1381. if (isBad == true) {
  1382. stats.playerPassingStats[current_team][qbIndex][7] += 1;
  1383. }
  1384. if (h != -1) {
  1385. stats.team_pass_pressure_down[(down-1)+(current_team*4)] += 1;
  1386. stats.playerPassingStats[current_team][qbIndex][8] += 1;
  1387. stats.team_quarter_totals[0][6+current_team*7] += 1;
  1388. stats.team_quarter_totals[quarter][6+current_team*7] += 1;
  1389. }
  1390.  
  1391. stats.playerReceivingStats[current_team][playerIndex][0] += 1;
  1392. stats.playerReceivingStats[current_team][playerIndex][1] += 1;
  1393. stats.playerReceivingStats[current_team][playerIndex][3] += y;
  1394. stats.playerReceivingStats[current_team][playerIndex][4] =
  1395. Math.max(stats.playerReceivingStats[current_team][playerIndex][4],y);
  1396. if (playText.indexOf("[deflected by ") != -1) {
  1397. stats.playerPassingStats[current_team][qbIndex][6] += 1;
  1398. stats.playerReceivingStats[current_team][playerIndex][6] += 1;
  1399. }
  1400. if (y >= togo) {
  1401. stats.team_pass_firsts[index] += 1;
  1402. stats.team_pass_firsts_down[(down-1)+(current_team*4)] += 1;
  1403. stats.playerReceivingStats[current_team][playerIndex][7] += 1;
  1404. }
  1405.  
  1406. if (y >= longPass) {
  1407. stats.distanceStats[0][d] += 1;
  1408. stats.distanceStats[0][d+1] += 1;
  1409. stats.distanceStats[0][d+2] += y;
  1410. }
  1411. else if (y >= mediumPass) {
  1412. stats.distanceStats[1][d] += 1;
  1413. stats.distanceStats[1][d+1] += 1;
  1414. stats.distanceStats[1][d+2] += y;
  1415. }
  1416. else if (y >= shortPass) {
  1417. stats.distanceStats[2][d] += 1;
  1418. stats.distanceStats[2][d+1] += 1;
  1419. stats.distanceStats[2][d+2] += y;
  1420. }
  1421. else {
  1422. stats.distanceStats[3][d] += 1;
  1423. stats.distanceStats[3][d+1] += 1;
  1424. stats.distanceStats[3][d+2] += y;
  1425. }
  1426.  
  1427. //stats = defenseHandler(stats,2,playText,"pass");
  1428. stats = defenseHandler(stats,2,p,"pass");
  1429.  
  1430. if (playText.indexOf("[TD]") != -1) {
  1431. drive.result = "Touchdown";
  1432. drive.driveEnded = "OPP 0";
  1433. stats.playerPassingStats[current_team][qbIndex][3] += 1;
  1434. }
  1435. var m = playText.split("[missed tackle:");
  1436. if (m.length > 1) {
  1437. stats.playerReceivingStats[current_team][playerIndex][8] += m.length-1;
  1438. }
  1439. m = playText.split("[missed diving tackle:");
  1440. if (m.length > 1) {
  1441. stats.playerReceivingStats[current_team][playerIndex][8] += m.length-1;
  1442. }
  1443. }
  1444. //console.log((down-1)+" "+((down-1)+current_team*4)+" "+downs[down_index].innerHTML+" "+playText);
  1445. }
  1446. else if (playText.indexOf("Kickoff by ") == 0) {
  1447. if (playText.indexOf(", fumbled") == -1) {
  1448. var ct = (current_team+1)%2;
  1449. var s1 = "Kickoff by ".length;
  1450. var s2 = playText.slice(s1).indexOf(', ');
  1451. var s = playText.slice(s1,s1+s2);
  1452. var s3 = playText.slice(s1+s2).indexOf(" yd");
  1453. var yardstring = playText.slice(s1+s2+s3-3,s1+s2+s3);
  1454. if (yardstring[1] == ".") {
  1455. //fix for the out of the endzone decimal lengths
  1456. yardstring = playText.slice(s1+s2+s3-3-2,s1+s2+s3);
  1457. }
  1458. var len = parseInt(yardstring,10);
  1459. if (isNaN(len) == true) {
  1460. return stats;
  1461. }
  1462. var playerIndex = arrayPush(ct,stats.playerKickingName,s,
  1463. stats.playerKickingStats,[0,0,0,0,0,0]);
  1464. stats.playerKickingStats[ct][playerIndex][0] += 1;
  1465. stats.playerKickingStats[ct][playerIndex][1] += len;
  1466. if (len > stats.playerKickingStats[ct][playerIndex][2]) {
  1467. stats.playerKickingStats[ct][playerIndex][2] = len;
  1468. }
  1469. var kd = kickDistance(p.marker,len);
  1470. if (p.marker == null) kd = kickDistance("Own 30",len);
  1471. if ((parseFloat(kd.slice(4)) < 20) && (playText.indexOf("(touchback)") == -1)) {//inside 20?
  1472. stats.playerKickingStats[ct][playerIndex][4] += 1;
  1473. }
  1474. if (playText.indexOf("(touchback)") != -1) {
  1475. stats.playerKickingStats[ct][playerIndex][3] += 1;
  1476. stats.playerKickingStats[ct][playerIndex][5] += len+parseFloat(kd.slice(4))-20; //net
  1477. }
  1478. else if (playText.indexOf(" yd return)") != -1) {
  1479. var ct = current_team;
  1480. var namestr = playText.slice(playText.indexOf(" fielded by ")+" fielded by ".length);
  1481.  
  1482. var yidx = namestr.indexOf(" yd return)")-6;
  1483. yidx = yidx+namestr.slice(yidx).indexOf(" (");
  1484. var y = parseFloat(namestr.slice(yidx+2));
  1485.  
  1486. var namestr = namestr.slice(0,yidx);
  1487. if (namestr.indexOf(", out of bounds") == (namestr.length-", out of bounds".length)) {
  1488. namestr = namestr.slice(0,namestr.indexOf(", out of bounds"));
  1489. }
  1490.  
  1491. if (namestr.indexOf(" [missed tackle:") != -1) {
  1492. namestr = namestr.slice(0,namestr.indexOf(" [missed tackle:"));
  1493. }
  1494. if (namestr.indexOf(" [missed diving tackle:") != -1) {
  1495. namestr = namestr.slice(0,namestr.indexOf(" [missed diving tackle:"));
  1496. }
  1497.  
  1498. if (namestr.indexOf(", PAT m") != -1) {
  1499. namestr = namestr.slice(0,namestr.indexOf(", PAT m"));
  1500. }
  1501. if (namestr.indexOf(" [TD]") == (namestr.length-5)) {
  1502. namestr = namestr.slice(0,namestr.length-5);
  1503. }
  1504. var returnerIndex = arrayPush(ct, stats.playerKickReturnName,namestr,
  1505. stats.playerKickReturnStats,[0,0,0,0,0,0]);
  1506. stats.playerKickReturnName[ct][returnerIndex] = namestr;
  1507. stats.playerKickReturnStats[ct][returnerIndex][0] += 1;
  1508. stats.playerKickReturnStats[ct][returnerIndex][1] += y;
  1509. if (y > stats.playerKickReturnStats[ct][returnerIndex][2]) {
  1510. stats.playerKickReturnStats[ct][returnerIndex][2] = y;
  1511. }
  1512. var m = playText.split("[missed tackle:");
  1513. if (m.length > 1) {
  1514. stats.playerKickReturnStats[ct][returnerIndex][4] += m.length-1;
  1515. }
  1516. m = playText.split("[missed diving tackle:");
  1517. if (m.length > 1) {
  1518. stats.playerKickReturnStats[ct][returnerIndex][4] += m.length-1;
  1519. }
  1520. stats.playerKickingStats[(ct+1)%2][playerIndex][5] += Math.max(len-y,0); //net
  1521. stats.playerKickReturnStats[ct][returnerIndex][5] += Math.min(1,y/len);
  1522. //console.log(len+" -- "+y+" -- "+(y/len).toFixed(3));
  1523. }
  1524. stats = defenseHandler(stats,4,p,"st");
  1525.  
  1526. drive.startTime = p.timeRemaining;
  1527. if (playText.indexOf("[TD]") != -1) {
  1528. drive.driveBegan = kickDistance("OPP 30",-len);
  1529. drive.driveEnded = "OPP 0";
  1530. drive.result = "Touchdown";
  1531. stats.playerKickReturnStats[ct][returnerIndex][3] += 1;
  1532. }
  1533. else if (playText.indexOf("(touchback)") != -1) {
  1534. drive.driveBegan = "OWN 20";
  1535. }
  1536. else {
  1537. drive.driveBegan = kickDistance("OPP 30",-len+y);
  1538.  
  1539. }
  1540. }
  1541. else {
  1542. //a damn fumble
  1543. /*
  1544. if (drive.numOfPlays != 1) {
  1545. stats.playerKickingName[ct].pop();
  1546. stats.playerKickingStats[ct].pop();
  1547. playerIndex = arrayPush(current_team,stats.playerKickingName,s,
  1548. stats.playerKickingStats,[0,0,0,0]);
  1549. stats.playerKickingStats[current_team][playerIndex][0] += 1;
  1550. stats.playerKickingStats[current_team][playerIndex][1] += len;
  1551. if (len > stats.playerKickingStats[current_team][playerIndex][2]) {
  1552. stats.playerKickingStats[current_team][playerIndex][2] = len;
  1553. }
  1554. }
  1555. else {
  1556. //kicking team recovered
  1557. stats.playerKickingStats[ct][playerIndex][0] += 1;
  1558. stats.playerKickingStats[ct][playerIndex][1] += len;
  1559. if (len > stats.playerKickingStats[ct][playerIndex][2]) {
  1560. stats.playerKickingStats[ct][playerIndex][2] = len;
  1561. }
  1562. }
  1563. */
  1564. // can't display this stuff as I don't know
  1565. // which team recovered if the play was the
  1566. // first play of a drive
  1567. //stats = defenseHandler(stats,4,p,"st");
  1568. }
  1569. }
  1570. else if (playText.indexOf("Punt by ") == 0) {
  1571. var ct = (current_team+1)%2;
  1572. var s1 = "Punt by ".length;
  1573.  
  1574. var s2 = playText.slice(s1).indexOf(', ');
  1575. var s = playText.slice(s1,s1+s2);
  1576.  
  1577. var lenstr = playText.slice(s1+s2+2);
  1578. var len = parseFloat(lenstr);
  1579. if (isNaN(len) == true) {
  1580. return stats;
  1581. }
  1582. var playerIndex = arrayPush(ct,stats.playerPuntingName,s,
  1583. stats.playerPuntingStats,[0,0,0,0,0,0]);
  1584. stats.playerPuntingStats[ct][playerIndex][0] += 1;
  1585. stats.playerPuntingStats[ct][playerIndex][1] += len;
  1586. if (len > stats.playerPuntingStats[ct][playerIndex][2]) {
  1587. stats.playerPuntingStats[ct][playerIndex][2] = len;
  1588. }
  1589. var kd = kickDistance(p.marker,len);
  1590. if ((parseFloat(kd.slice(4)) < 20) && (playText.indexOf("(touchback)") == -1)) {//inside 20?
  1591. stats.playerPuntingStats[ct][playerIndex][4] += 1;
  1592. }
  1593. if (playText.indexOf(", fumbled") == -1) {
  1594. //was a return, no fumbles
  1595. if (playText.indexOf("(touchback)") != -1) {
  1596. stats.playerPuntingStats[ct][playerIndex][3] += 1;
  1597. stats.playerPuntingStats[ct][playerIndex][5] += len+parseFloat(kd.slice(4))-20;
  1598. //console.log("tb: punted="+len+" || net="+(len+parseFloat(kd.slice(4))-20)+" \\ kd="+kd);
  1599. }
  1600. else if (playText.indexOf(" yd return)") != -1) {
  1601. var ct = current_team;
  1602. var namestr = playText.slice(playText.indexOf(" fielded by ")+" fielded by ".length);
  1603.  
  1604. var yidx = namestr.indexOf(" yd return)")-6;
  1605. yidx = yidx+namestr.slice(yidx).indexOf(" (");
  1606. var y = parseFloat(namestr.slice(yidx+2));
  1607.  
  1608. var namestr = namestr.slice(0,yidx);
  1609. if (namestr.indexOf(", out of bounds") == (namestr.length-", out of bounds".length)) {
  1610. namestr = namestr.slice(0,namestr.indexOf(", out of bounds"));
  1611. }
  1612.  
  1613. if (namestr.indexOf(" [missed tackle:") != -1) {
  1614. namestr = namestr.slice(0,namestr.indexOf(" [missed tackle:"));
  1615. }
  1616. if (namestr.indexOf(" [missed diving tackle:") != -1) {
  1617.  
  1618. namestr = namestr.slice(0,namestr.indexOf(" [missed diving tackle:"));
  1619. }
  1620.  
  1621. if (namestr.indexOf(", PAT m") != -1) {
  1622. namestr = namestr.slice(0,namestr.indexOf(", PAT m"));
  1623. }
  1624. if (namestr.indexOf(" [TD]") == (namestr.length-5)) {
  1625. namestr = namestr.slice(0,namestr.length-5);
  1626. }
  1627. var returnerIndex = arrayPush(ct, stats.playerPuntReturnName,namestr,
  1628. stats.playerPuntReturnStats,[0,0,0,0,0,0]);
  1629. stats.playerPuntReturnName[ct][returnerIndex] = namestr;
  1630. stats.playerPuntReturnStats[ct][returnerIndex][0] += 1;
  1631. stats.playerPuntReturnStats[ct][returnerIndex][1] += y;
  1632. if (y > stats.playerPuntReturnStats[ct][returnerIndex][2]) {
  1633. stats.playerPuntReturnStats[ct][returnerIndex][2] = y;
  1634. }
  1635. if (playText.indexOf("[TD]") != -1) {
  1636. stats.playerPuntReturnStats[ct][returnerIndex][3] += 1;
  1637. }
  1638. var m = playText.split("[missed tackle:");
  1639. if (m.length > 1) {
  1640. stats.playerPuntReturnStats[ct][returnerIndex][4] += m.length-1;
  1641. }
  1642. m = playText.split("[missed diving tackle:");
  1643. if (m.length > 1) {
  1644. stats.playerPuntReturnStats[ct][returnerIndex][4] += m.length-1;
  1645. }
  1646. stats.playerPuntingStats[(ct+1)%2][playerIndex][5] += Math.max(len-y,0);
  1647. //console.log("ret: punted="+len+" || net="+Math.max(len-y,0)+" // ret="+y);
  1648. if (isNaN(len) == false) {
  1649. stats.playerPuntReturnStats[ct][returnerIndex][5] += Math.min(1,y/len);
  1650. //console.log(stats.playerPuntReturnStats[ct][returnerIndex][5]);
  1651. }
  1652. else {
  1653. //console.log("isNaN==true : "+playText);
  1654. }
  1655. }
  1656. else {
  1657. stats.playerPuntingStats[ct][playerIndex][5] += len;
  1658. //console.log("no ret: punted="+len+" || net="+(len));
  1659. }
  1660. stats = defenseHandler(stats,4,p,"st");
  1661.  
  1662. lastDrive.result = "Punt";
  1663. lastDrive.numOfPlays += 1;
  1664. lastDrive.driveEnded = p.marker;
  1665.  
  1666. drive.numOfPlays = 0;
  1667. drive.startTime = p.timeRemaining;
  1668. if (playText.indexOf("[TD]") != -1) {
  1669. drive.driveBegan = kickDistance(p.marker,len);
  1670. drive.driveBegan = yardReverse(drive.driveBegan);
  1671. drive.driveEnded = "OPP 0";
  1672. drive.result = "Touchdown";
  1673. }
  1674. else if (playText.indexOf("(touchback)") != -1) {
  1675. drive.driveBegan = "OWN 20";
  1676. }
  1677. else {
  1678. drive.driveBegan = kickDistance(p.marker,-len+y);
  1679. }
  1680. }
  1681. else {
  1682. if (drive.numOfPlays == 1) {
  1683. //punt was fumbled & return team recovered
  1684. lastDrive.result = "Punt";
  1685. lastDrive.numOfPlays += 1;
  1686. lastDrive.driveEnded = p.marker;
  1687. lastDrive.endTime = p.timeRemaining;
  1688.  
  1689. drive.numOfPlays = 0;
  1690. drive.startTime = p.timeRemaining;
  1691. stats.playerPuntingStats[ct][playerIndex][5] += len;
  1692. //console.log("fum retrec: punted="+len+" || net="+(len));
  1693. }
  1694. else {
  1695. //punt was fumbled & kickoff team recovered
  1696. stats.playerPuntingName[ct].pop();
  1697. stats.playerPuntingStats[ct].pop();
  1698. ct = (ct+1)%2;
  1699. var playerIndex = arrayPush(ct,stats.playerPuntingName,s,
  1700. stats.playerPuntingStats,[0,0,0,0,0,0]);
  1701. stats.playerPuntingStats[ct][playerIndex][0] += 1;
  1702. stats.playerPuntingStats[ct][playerIndex][1] += len;
  1703. if (len > stats.playerPuntingStats[ct][playerIndex][2]) {
  1704. stats.playerPuntingStats[ct][playerIndex][2] = len;
  1705. }
  1706. stats.playerPuntingStats[ct][playerIndex][5] += len;
  1707. //console.log("fum punrec: punted="+len+" || net="+(len));
  1708. }
  1709. // can't display this stuff as I don't know
  1710. // which team recovered if the play was the
  1711. // first play of a drive
  1712. //stats = defenseHandler(stats,4,p,"st");
  1713. }
  1714. }
  1715. else if (playText.indexOf("yd field goal attempted by") != -1) {
  1716. if (playText.indexOf(", missed") == (playText.length - ", missed".length)) {
  1717. lastDrive.result = "Missed FG";
  1718. lastDrive.endTime = p.timeRemaining;
  1719. lastDrive.driveEnded = p.marker;
  1720. lastDrive.numOfPlays++;
  1721. drive.numOfPlays = 0;
  1722. }
  1723. else {
  1724. drive.result = "FG";
  1725. }
  1726. }
  1727. else if ((playText.indexOf("[forced fumble:") == 0) ||
  1728. (playText.indexOf("[Big Sack forced fumble:") == 0)) {
  1729. //sack with fumble
  1730. //can't handle this right now since we don't know
  1731. //which team has the ball
  1732. if (drive.numOfPlays == 1) {
  1733. //lost fumble on a sack
  1734. if (playText.indexOf("[SAFETY]") != -1) {
  1735. lastDrive.result = "Safety";
  1736. lastDrive.numOfPlays += 1;
  1737. lastDrive.driveEnded = p.marker;
  1738. lastDrive.endTime = p.timeRemaining;
  1739.  
  1740. drive.numOfPlays = 0;
  1741. drive.startTime = p.timeRemaining;
  1742. }
  1743. else if (playText.indexOf("forced fumble:") != -1) {
  1744. lastDrive.result = "Fumble";
  1745. lastDrive.numOfPlays += 1;
  1746. lastDrive.driveEnded = p.marker;
  1747. lastDrive.endTime = p.timeRemaining;
  1748.  
  1749. drive.numOfPlays = 0;
  1750. drive.startTime = p.timeRemaining;
  1751. if (playText.indexOf("[TD]") != -1) {
  1752. drive.driveEnded = "Opp 0";
  1753. drive.result = "Touchdown";
  1754. }
  1755. }
  1756. }
  1757. }
  1758. else if ((playText.match(" sacked by ") != null) ||
  1759. (playText.indexOf("[tackle:") == 0) ||
  1760. (playText.indexOf("[Monster Hit tackle:") == 0) ||
  1761. (playText.indexOf("[Big Sack tackle:") == 0) ||
  1762. (playText.indexOf("[diving tackle:") == 0)) {
  1763. //sack without fumble
  1764. //console.log("sack "+playText.slice(0,40));
  1765. if (playText.indexOf("] [SAFETY]") != -1) {
  1766. current_team = (current_team+1)%2;
  1767. stats = defenseHandler(stats,2,p,"pass");
  1768. current_team = (current_team+1)%2;
  1769. }
  1770. else {
  1771. stats = defenseHandler(stats,2,p,"pass");
  1772. }
  1773. if (drive.numOfPlays == 1) {
  1774. //lost fumble on a sack
  1775. if (playText.indexOf("[SAFETY]") != -1) {
  1776. lastDrive.result = "Safety";
  1777. lastDrive.numOfPlays += 1;
  1778. lastDrive.driveEnded = p.marker;
  1779. lastDrive.endTime = p.timeRemaining;
  1780.  
  1781. drive.numOfPlays = 0;
  1782. drive.startTime = p.timeRemaining;
  1783. }
  1784. else if (playText.indexOf("[forced fumble:") != -1) {
  1785. lastDrive.result = "Fumble";
  1786. lastDrive.numOfPlays += 1;
  1787. lastDrive.driveEnded = p.marker;
  1788. lastDrive.endTime = p.timeRemaining;
  1789.  
  1790. drive.numOfPlays = 0;
  1791. drive.startTime = p.timeRemaining;
  1792. if (playText.indexOf("[TD]") != -1) {
  1793. drive.driveEnded = "Opp 0";
  1794. drive.result = "Touchdown";
  1795. }
  1796. }
  1797. }
  1798. }
  1799. else if (playText.indexOf("penalty committed by") != -1) {
  1800. //console.log("Penalty: "+playText.slice(0,40));
  1801. stats = penaltyHandler(stats, p);
  1802. }
  1803. else if (playText.indexOf(" calls timeout") != -1) {
  1804. //nothing to do here
  1805. }
  1806. else if (playText.indexOf("Offensive Timeout Called") == 0) {
  1807. //nothing to do here
  1808. }
  1809. else if (playText.indexOf("Extra point attempted by") == 0) {
  1810. //nothing to do here
  1811. }
  1812. else {
  1813. //something really wierd
  1814. console.log("You shouldn't see me, so I'm probably a bug: '"+playText+"'");
  1815. }
  1816.  
  1817. if (playText.indexOf("turnover on downs") != -1) {
  1818. drive.result = "Downs";
  1819. //drive.driveEnded = p.marker;
  1820. }
  1821.  
  1822. if (lastTime == null) {
  1823. }
  1824. else {
  1825. if (lastTime < convertTime(p.timeRemaining)) {
  1826. stats.team_possession[current_team*6] += lastTime;
  1827. stats.team_possession[current_team*6+quarter-1] += lastTime;
  1828. }
  1829. else {
  1830. stats.team_possession[current_team*6] += lastTime - convertTime(p.timeRemaining);
  1831. stats.team_possession[current_team*6+quarter] += lastTime - convertTime(p.timeRemaining);
  1832. }
  1833. }
  1834. lastTime = convertTime(p.timeRemaining);
  1835.  
  1836. //console.log(stats.playerRushingName);
  1837. //console.log(stats.playerReceivingName);
  1838. //console.log(stats.playerDefensiveName);
  1839. return stats;
  1840. }
  1841.  
  1842. function getTeamNames(stats, page) {
  1843. var heading = page.getElementsByClassName("big_head subhead_head");
  1844. heading = heading[0];
  1845. var teams = heading.innerHTML.split("team_id=");
  1846. stats.team_id[0] = teams[1].slice(0,teams[1].indexOf('"'));
  1847. stats.team_name[0] = heading.firstChild.innerHTML;
  1848. stats.team_id[1] = teams[2].slice(0,teams[2].indexOf('"'));
  1849. stats.team_name[1] = heading.lastChild.innerHTML;
  1850. }
  1851.  
  1852. var current_team = 0;
  1853. var lastTime = 900;
  1854. var quarter = 0;
  1855. var team;
  1856. var lastDrive = new Drive();
  1857.  
  1858. function Drive() {
  1859. this.teamName;
  1860. this.quarter;
  1861. this.startTime;
  1862. this.endTime;
  1863. this.driveBegan;
  1864. this.driveEnded;
  1865. this.numOfPlays = 0;
  1866. this.netYards = 0;
  1867. this.result;
  1868.  
  1869. this.toString = function() {
  1870. return this.quarter+" : "+this.startTime+" : "+this.endTime+" : " +
  1871. this.timePoss+" : "+this.driveBegan+" : " +
  1872. this.driveEnded+" : "+this.numOfPlays+" : " +
  1873. yardDiff(this.driveBegan,this.driveEnded) +
  1874. " : "+this.result;
  1875. }
  1876. }
  1877.  
  1878. function gameScout(inetAddress,page) {
  1879. var stats = new Stats();
  1880. current_team = 0;
  1881. lastTime = 900;
  1882. quarter = 0;
  1883. lastDrive = new Drive();
  1884. var d = null;
  1885. var p = null;
  1886. var pbpTable = findChild("play_by_play_table",page);
  1887. if (pbpTable == null) {
  1888. console.log("pbpTable is null. exiting. gamescout 28938user.js");
  1889. return stats;
  1890. }
  1891. console.log("start");
  1892. getTeamNames(stats, page);
  1893. pages = pbpTable.rows.length;
  1894. //for each (htmlTableRowElement in pbpTable.rows) {
  1895. for (var hidx=0; hidx<pbpTable.rows.length; hidx++) {
  1896. var htmlTableRowElement = pbpTable.rows[hidx];
  1897. //console.log(htmlTableRowElement.textContent);
  1898. var className = htmlTableRowElement.className;
  1899. if (className == null) {
  1900. continue;
  1901. }
  1902. if (className.match("pbp_quarter") != null) {
  1903. quarter++;
  1904. if (quarter == 3) {
  1905. if (d != null) {
  1906. if (d.result == null) {
  1907. d.result = "End of Half";
  1908. }
  1909. d.endTime = "0:00";
  1910. //console.log(d);
  1911. lastDrive = d;
  1912. stats.driveList[current_team].push(d);
  1913. d = new Drive();
  1914. }
  1915. }
  1916. }
  1917. else if (className.match("pbp_team") != null) {
  1918. var coll = htmlTableRowElement.cells;
  1919. var node = coll.item(0);
  1920. var idx = 0;
  1921. do {
  1922. var s = node.innerHTML.slice(idx,node.innerHTML.length);
  1923. var i = s.indexOf(" ");
  1924. if (i != -1) idx += i + 1;
  1925. }
  1926. while (i != -1);
  1927. team = node.innerHTML.slice(0,idx-1);
  1928.  
  1929. var found = false;
  1930. for (var tidx=0; tidx<stats.team_name.length; tidx++) {
  1931. var t = stats.team_name[tidx];
  1932. if (t == team) {
  1933. found = true;
  1934. break;
  1935. }
  1936. }
  1937. if (found == false) {
  1938. stats.team_name.push(team);
  1939. console.log(stats.team_name+" -- "+stats.team_id);
  1940. }
  1941. if (d != null) {
  1942. if (d.quarter != null) {
  1943. //console.log(d);
  1944. lastDrive = d;
  1945. stats.driveList[current_team].push(lastDrive);
  1946. }
  1947. }
  1948. d = new Drive();
  1949. d.teamName = team;
  1950. }
  1951. else if (className.match("pbp_play_row") != null) {
  1952. p = new Play();
  1953. p.quarter = quarter;
  1954. p.team = team;
  1955.  
  1956. var coll = htmlTableRowElement.cells;
  1957. //for each (node in coll) {
  1958. for (var nidx=0; nidx<coll.length; nidx++) {
  1959. var node = coll[nidx];
  1960. var cName = node.className;
  1961. if (cName.match("pbp_time_remaining") != null) {
  1962. p.timeRemaining = node.innerHTML;
  1963. }
  1964. else if (cName.match("pbp_marker") != null) {
  1965. p.marker = node.innerHTML;
  1966. }
  1967. else if (cName.match("pbp_down") != null) {
  1968. p.down = node.innerHTML.slice(0,1);
  1969. p.togo = node.innerHTML.slice(node.innerHTML.indexOf("amp; ")+5);
  1970. }
  1971. else if (cName.match("pbp_replay") != null) {
  1972. p.replay = node.firstChild;
  1973. //if (p.playText != null) {
  1974. if (htmlTableRowElement.className.toString().indexOf("pbrfiltered") == -1) {
  1975. //console.log(htmlTableRowElement.className+" -- "+p.play);
  1976. stats = playHandler(stats,d,p);
  1977. }
  1978. //}
  1979. }
  1980. else if (cName.match("pbp_play") != null) {
  1981. p.play = node.firstChild.data;
  1982. if (isNaN(parseInt(p.play)) == false) {
  1983. p.play = p.play.slice(p.play.indexOf(" "));
  1984. }
  1985. var playText = p.play;
  1986. p.score = 0;
  1987. while (playText.indexOf("[") != -1) {
  1988. var startidx = playText.indexOf("[")+1;
  1989. playText = playText.substring(startidx);
  1990. var endidx = playText.indexOf("]");
  1991. if (endidx == -1) break;
  1992.  
  1993. var score = playText.substring(0, endidx);
  1994. if (score == "FG") {
  1995. p.score = 3;
  1996. }
  1997. else if (score == "TD") {
  1998. p.score = 6;
  1999. if (p.play.indexOf(", PAT made by ") != -1) {
  2000. p.score += 1;
  2001. }
  2002. }
  2003. else if (score == "SAFETY") {
  2004. p.score = 2;
  2005. }
  2006. else if (score.indexOf("deflected by ") != 0) p.score = 0;
  2007. }
  2008. }
  2009. /*
  2010. var playText = p.play;
  2011. if (playText.indexOf("made [FG]") != -1) p.score = 3;
  2012. else if (playText.indexOf("[TD]") != -1) p.score = 6;
  2013. else if (playText.indexOf("[SAFETY]") != -1) p.score = 2;
  2014. else p.score = 0;
  2015. if (playText.indexOf(", PAT made by ") != -1) p.score += 1;}
  2016. */
  2017. }
  2018. }
  2019. else {
  2020. // console.log("main loop removal : "+pages+" / "+pbpTable.rows.length);
  2021. }
  2022.  
  2023. }
  2024. console.log("game over");
  2025.  
  2026. d.endTime = "00:00";
  2027. d.result = "End of Game";
  2028. stats.driveList[current_team].push(d);
  2029.  
  2030. //time of possession for last play
  2031. if ((p.quarter != 5) && ((window.location.toString()).indexOf("quarter=5") == -1)) {
  2032. stats.team_possession[current_team*6] += lastTime;
  2033. stats.team_possession[current_team*6+p.quarter] += lastTime;
  2034. }
  2035. if (p.quarter == 1) {
  2036. d.result = "End of Quarter";
  2037. }
  2038. console.log("main loop done");
  2039.  
  2040. /*//shouldn't be needed anymore
  2041. var pbp = findChild("pbp",page);
  2042. if (pbp != null) {
  2043. pbp.parentNode.removeChild(pbp);
  2044. }
  2045. */
  2046.  
  2047. //var index = links.indexOf(inetAddress);
  2048. var index = -1;
  2049. var s = document.getElementsByClassName("GScheckbox");
  2050. for (var i=0; i<s.length; i++) {
  2051. if (s[i].id == inetAddress) {
  2052. index = i;
  2053. break;
  2054. }
  2055. }
  2056. //console.log("storageArr[]: "+(index+1)+" of "+storageArr.length);
  2057. //storageArr[index] = stats;
  2058.  
  2059. console.log("exiting gs run");
  2060.  
  2061. return stats;
  2062. }
  2063.  
  2064. function loadPBPSimple(page) {
  2065. var timeouts = [3, 3];
  2066. var quarter = 0;
  2067. var p = null;
  2068. var team;
  2069. plays = [];
  2070. var div = document.createElement("div");
  2071. /*
  2072. div.innerHTML = page.responseText.replace(/<img/g,"<div").replace(/\/img/g,"/div>");
  2073. var pbpTable = findChild("play_by_play_table",div);
  2074. */
  2075. var string = page.responseText.replace(/<img/g,"<div").replace(/\/img/g,"/div>");
  2076. string = string.slice(string.indexOf('<div id="page_box_score"'));
  2077. string = string.slice(0,string.indexOf('<div id="footer"'));
  2078. div.innerHTML = string;
  2079.  
  2080. var pbpTable = findChild("play_by_play_table",div);
  2081. console.log("pbpTable = "+pbpTable);
  2082. if (pbpTable == null) {
  2083. console.log("pbpTable is null. exiting. loadpbpsimple 28938user.js");
  2084. return;
  2085. }
  2086. for (var hidx=0; hidx<pbpTable.rows.length; hidx++) {
  2087. var htmlTableRowElement = pbpTable.rows[hidx];
  2088. var className = htmlTableRowElement.className;
  2089. if (className == null) {
  2090. continue;
  2091. }
  2092. if (className.match("pbp_quarter") != null) {
  2093. quarter++;
  2094. if (quarter%2 == 1) timeouts = [3, 3];
  2095. }
  2096. else if (className.match("pbp_team") != null) {
  2097. var coll = htmlTableRowElement.cells;
  2098. var node = coll.item(0);
  2099. var idx = 0;
  2100. do {
  2101. var s = node.innerHTML.slice(idx,node.innerHTML.length);
  2102. var i = s.indexOf(" ");
  2103. if (i != -1) idx += i + 1;
  2104. }
  2105. while (i != -1);
  2106. team = node.innerHTML.slice(0,idx-1);
  2107.  
  2108. var temp = timeouts[0];
  2109. timeouts[0] = timeouts[1];
  2110. timeouts[1] = temp;
  2111. }
  2112. else if (className.match("pbp_play_row") != null) {
  2113. p = new Play();
  2114. p.quarter = quarter;
  2115. p.team = team;
  2116. p.timeoutsRemaining = new Array();
  2117. p.timeoutsRemaining[0] = timeouts[0];
  2118. p.timeoutsRemaining[1] = timeouts[1];
  2119.  
  2120. var coll = htmlTableRowElement.cells;
  2121. for (var nidx=0; nidx<coll.length; nidx++) {
  2122. var node = coll[nidx];
  2123. var cName = node.className;
  2124. if (cName.match("pbp_time_remaining") != null) {
  2125. p.timeRemaining = node.innerHTML;
  2126. }
  2127. else if (cName.match("pbp_marker") != null) {
  2128. p.marker = node.innerHTML;
  2129. }
  2130. else if (cName.match("pbp_down") != null) {
  2131. p.down = node.innerHTML.slice(0,1);
  2132. p.togo = node.innerHTML.slice(node.innerHTML.indexOf("amp; ")+5);
  2133. }
  2134. else if (cName.match("pbp_replay") != null) {
  2135. p.replay = node.firstChild;
  2136. }
  2137. else if (cName.match("pbp_play") != null) {
  2138. p.play = node.firstChild.data;
  2139. p.score = 0;
  2140. var playText = p.play;
  2141. p.score = 0;
  2142. while (playText.indexOf("[") != -1) {
  2143. var startidx = playText.indexOf("[")+1;
  2144. playText = playText.substring(startidx);
  2145. var endidx = playText.indexOf("]");
  2146. if (endidx == -1) break;
  2147.  
  2148. var score = playText.substring(0, endidx);
  2149. if (score == "FG") {
  2150. p.score = 3;
  2151. }
  2152. else if (score == "TD") {
  2153. p.score = 6;
  2154. if (p.play.indexOf(", PAT made by ") != -1) {
  2155. p.score += 1;
  2156. }
  2157. }
  2158. else if (score == "SAFETY") {
  2159. p.score = 2;
  2160. }
  2161. else if (score.indexOf("deflected by ") != 0) p.score = 0;
  2162. // if (p.score != 0) console.log(p.score+" : "+p.play+" : "+playText);
  2163. }
  2164. if (p.play.indexOf("Offensive Timeout Called: ") == 0) {
  2165. var tm = p.play.slice("Offensive Timeout Called: ".length);
  2166. timeouts[0]--;
  2167. }
  2168. else if (p.play.indexOf("Defensive Timeout Called: ") == 0) {
  2169. var tm = p.play.slice("Defensive Timeout Called: ".length);
  2170. timeouts[1]--;
  2171. }
  2172. else if (p.play.indexOf(" calls timeout") != -1) {
  2173. var tm = p.play.slice(0,p.play.indexOf(" calls timeout"));
  2174. if (tm == p.team) {
  2175. timeouts[0]--;
  2176. }
  2177. else {
  2178. timeouts[1]--;
  2179. }
  2180. }
  2181. }
  2182. }
  2183. plays.push(p);
  2184. }
  2185. }
  2186. console.log(plays.length);
  2187. }