pbr Game Scout - New Gen

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

Skrip ini tidak untuk dipasang secara langsung. Ini adalah pustaka skrip lain untuk disertakan dengan direktif meta // @require https://update.greatest.deepsurf.us/scripts/473624/1239280/pbr%20Game%20Scout%20-%20New%20Gen.js

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