Replay Rewrite

Adds some new features to the GoallineBlitz.com replay page.

目前为 2014-05-21 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Replay Rewrite
  3. // @namespace pbr/rr
  4. // @include http://*goallineblitz.com/game/replay.pl?game_id=*&pbp_id=*
  5. // @include http://glb.warriorgeneral.com/game/replay.pl?game_id=*&pbp_id=*
  6. // @copyright 2010, pabst
  7. // @license (CC) Attribution Share Alike; http://creativecommons.org/licenses/by-sa/3.0/
  8. // @version 13.12.29
  9. // @require http://userscripts.org/scripts/source/28938.user.js
  10. // @require http://userscripts.org/scripts/source/31573.user.js
  11. // @require http://userscripts.org/scripts/source/54630.user.js
  12. // @description Adds some new features to the GoallineBlitz.com replay page.
  13. // ==/UserScript==
  14.  
  15. /*
  16. *
  17. * pabst did this 09/07/21+
  18. *
  19. *
  20. */
  21.  
  22. var scriptName = "Replay Rewrite";
  23. var scriptVersion = "13.12.29";
  24. var scriptWebpage = "http://userscripts.org/scripts/show/31640";
  25.  
  26. // you can modify the following variables
  27. var preDelay = 3000;
  28. var postDelay = 3000;
  29. var alwaysPause = false;
  30.  
  31. var alwaysShowPlayText = (unsafeWindow.hide_scores != 1); // <--account option
  32.  
  33. var showFallenPlayers = true; //should pancakes/falls/jukes be shown
  34. var showShrinkAnimation = false;
  35.  
  36. var offenseOnBottom = false;
  37. var horizontalField = false;
  38. var frameRate = 1000/unsafeWindow.frameSpeed; // <--account option
  39.  
  40. var visionDivSize = 2;
  41. var visionDivSkip = 4;
  42. // you can modify the previous variables
  43.  
  44. // don't screw with these
  45. var ihavearealoperatingsystem = false;
  46. var pancakeCheck = function() {
  47. return;
  48. };
  49. if (showFallenPlayers == true) {
  50. if (showShrinkAnimation == true) {
  51. pancakeCheck = playerShrink;
  52. }
  53. else {
  54. pancakeCheck = playerTrim;
  55. }
  56. }
  57.  
  58. var replayRewrite = true;
  59.  
  60. var plays = null;
  61. var currentPlay = -1;
  62.  
  63. var playDone = false;
  64. var playPaused = false;
  65.  
  66. var prePlayTimer = null;
  67. var postPlayTimer = null;
  68. var playFinishedTimer = null;
  69.  
  70. var httpRequest = null;
  71.  
  72. var frameSpeed = 925/frameRate;
  73. var frameTimer = null;
  74.  
  75. var hometeam = unsafeWindow.home;
  76. var showVision = true;
  77. var showIcons = !unsafeWindow.drawIcons;
  78.  
  79. var vision_data = null;
  80. var cam_data = null;
  81. var play_data = null;
  82. var poss_data = null;
  83. var currentFrame = 0;
  84. var playerDiv = new Array();
  85. var playerOvr = new Array();
  86. var ptid = unsafeWindow.ptid;
  87. var useDefaultColors = unsafeWindow.useDefaultColors;
  88. var replayArea = null;
  89. var lastTime = -1;
  90. var thisScore = unsafeWindow.this_score;
  91. var scoreUpdate = unsafeWindow.score_update;
  92.  
  93. var playerExtrasIn = new Array();
  94. var playerExtrasOut = new Array();
  95.  
  96. var firstRun = true;
  97.  
  98. var ballImage = "/images/ball.gif";
  99. var ballMotionImg = null;
  100.  
  101. var gradient = [["#910000"],["#9a0000"],["#a30000"],["#ad0000"],["#b60000"],["#bf0000"],["#c90000"],["#d20000"],["#db0000"],["#e40000"],["#ed0000"],["#f70000"],["#ff0100"],["#ff0e00"],["#ff1c00"],["#ff2900"],["#ff3600"],["#ff4300"],["#ff5000"],["#ff5d00"],["#ff6a00"],["#ff7700"],["#ff8400"],["#ff9200"],["#ff9f00"],["#ffa600"],["#ffa800"],["#ffaa00"],["#ffad00"],["#ffaf00"],["#ffb200"],["#ffb400"],["#ffb600"],["#ffb900"],["#ffbb00"],["#ffbd00"],["#ffc000"],["#ffc200"],["#ffc500"],["#ffc700"],["#ffc900"],["#ffcc00"],["#ffce00"],["#ffd100"],["#ffd300"],["#ffd500"],["#ffd800"],["#ffda00"],["#ffdc00"],["#ffdf00"],["#ffe100"],["#ffe400"],["#ffe600"],["#ffe800"],["#ffeb00"],["#ffed00"],["#fff000"],["#fff200"],["#fff400"],["#fff700"],["#fff900"],["#fffc00"],["#fffe00"],["#fafc00"],["#f3f900"],["#ecf500"],["#e5f200"],["#dfef00"],["#d8eb00"],["#d1e800"],["#cae400"],["#c3e100"],["#bdde00"],["#b6da00"],["#afd700"],["#a8d300"],["#a2d000"],["#9bcd00"],["#94c900"],["#8dc600"],["#86c200"],["#80bf00"],["#79bc00"],["#72b900"],["#6bb500"],["#65b200"],["#5eaf00"],["#57ab00"],["#50a800"],["#49a400"],["#43a100"],["#3c9e00"],["#359a00"],["#2e9700"],["#289400"],["#219000"],["#1a8d00"],["#138900"],["#0c8600"],["#068300"],["#068300"]];
  102.  
  103. window.setTimeout(
  104. function() {
  105. unsafeWindow.pause();
  106. clearTimeout(unsafeWindow.frameTimer);
  107. unsafeWindow.frameTimer = null;
  108.  
  109. main();
  110. }
  111. , 1);
  112.  
  113. function main() {
  114. clearPlayers();
  115. addScriptTags();
  116. restructurePage();
  117. addPlayerLinks();
  118. bortFix();
  119. pbpSetup();
  120. }
  121.  
  122. function createButton(title, cls) {
  123. var btn = document.createElement("a");
  124. btn.className = "button left "+cls;
  125. btn.innerHTML = "<span>"+title+"</span>";
  126. return btn;
  127. }
  128.  
  129. function addScriptTags() {
  130. var rrtag = document.createElement("div");
  131. rrtag.setAttribute("id","rrtag");
  132.  
  133. var div = document.createElement("div");
  134. div.id = "active_list";
  135. div.innerHTML = "<b>Active GM Scripts</b>";
  136. rrtag.appendChild(div);
  137.  
  138. var rrplay = document.createElement("input");
  139. rrplay.setAttribute("id","rrplay");
  140. rrplay.setAttribute("style","display:none; visibility:hidden;");
  141. rrplay.setAttribute("type","text");
  142. rrplay.setAttribute("value",window.location.toString());
  143.  
  144. document.body.appendChild(rrtag);
  145. document.body.appendChild(rrplay);
  146. addToActive();
  147. }
  148.  
  149. function restructurePage() {
  150. var repfoot = document.getElementById("replay_footer");
  151. repfoot.style.height = "90px";
  152.  
  153. var playHeader = document.getElementById("replay_header");
  154. var playInfo = document.getElementById("play_info");
  155. var playDesc = document.getElementById("play_outcome");
  156. if (alwaysShowPlayText == false) {
  157. playDesc.style.display = "block";
  158. playDesc.style.visibility = "hidden";
  159. }
  160.  
  161. var cnt = document.getElementById("play_container");
  162. cnt.setAttribute("class","play_container");
  163.  
  164. var color = document.getElementById("color_options");
  165. color.style.width = "190px";
  166.  
  167. var pposs = createButton("<< Prev Poss","ppossbtn");
  168. var pplay = createButton("< Prev", "pplaybtn");
  169. var rst = createButton("Reset","resetbtn");
  170. var nplay = createButton("Next >", "nplaybtn");
  171. var nposs = createButton("Next Poss >>", "npossbtn");
  172.  
  173. var rewbtn = document.createElement("a");
  174. rewbtn.className = "button left rewbtn";
  175. rewbtn.innerHTML = '<span class="button_ff_rw"><img src="/images/game/design/replay/button_rw.gif"/></span>';
  176.  
  177. var pausebtn = document.createElement("a");
  178. pausebtn.setAttribute("class","button left pausebtn");
  179. pausebtn.innerHTML = '<span class="button_ff_rw"><img src="/images/game/design/replay/button_pause.gif"/></span>';
  180.  
  181. var playbtn = document.createElement("a");
  182. playbtn.setAttribute("class","button left playbtn");
  183. playbtn.innerHTML = '<span class="button_ff_rw"><img src="/images/game/design/replay/button_play.gif"/></span>';
  184.  
  185. var ffbtn = document.createElement("a");
  186. ffbtn.setAttribute("class","button left ffbtn");
  187. ffbtn.innerHTML = '<span class="button_ff_rw"><img src="/images/game/design/replay/button_ff.gif"/></span>';
  188.  
  189. var control = document.getElementById("controls");
  190. control.style.width = "650px";
  191. control.style.marginLeft = "0px";
  192. while (control.childNodes.length > 0) {
  193. control.removeChild(control.firstChild);
  194. }
  195.  
  196. control.appendChild(pposs);
  197. control.appendChild(pplay);
  198. control.appendChild(rst);
  199. control.appendChild(rewbtn);
  200. control.appendChild(pausebtn);
  201. control.appendChild(playbtn);
  202. control.appendChild(ffbtn);
  203. control.appendChild(nplay);
  204. control.appendChild(nposs);
  205.  
  206. pposs.addEventListener("click",input,true);
  207. pplay.addEventListener("click",input,true);
  208. rst.addEventListener("click", reset, true);
  209. rewbtn.addEventListener("click",rew,true);
  210. playbtn.addEventListener("click",play,true);
  211. pausebtn.addEventListener("click",pauseReplay,true);
  212. ffbtn.addEventListener("click",ff,true);
  213. nplay.addEventListener("click",input,true);
  214. nposs.addEventListener("click",input,true);
  215.  
  216. var div = document.createElement("div");
  217. div.setAttribute("style","float: right");
  218. div.style.marginRight = "10px";
  219. div.style.marginTop = "15px";
  220.  
  221. var area = document.getElementById("replay_area");
  222. area.style.width = "520px";
  223. area.style.height = "1160px";
  224. var fimg = area.style.backgroundImage;
  225. area.style.backgroundImage = "none";
  226.  
  227. var img = document.createElement("img");
  228. if (fimg.toString().indexOf('url("') == 0) {
  229. console.log("firefox >3.6");
  230. img.src = fimg.slice(fimg.indexOf("/"),fimg.indexOf('")'));
  231. }
  232. else if (fimg.toString().indexOf('url(') == 0) {
  233. console.log("firefox <3.6");
  234. img.src = fimg.slice(fimg.indexOf("/"),fimg.indexOf(")"));
  235. }
  236. else {
  237. console.log("what firefox version is this?");
  238. console.log(fimg.toString());
  239. img.src = fimg.slice(fimg.indexOf("/"),fimg.indexOf(")"));
  240. }
  241. img.id = "field_image";
  242. img.style.zIndex = 0;
  243. area.appendChild(img);
  244.  
  245. inp = document.createElement("input");
  246. inp.id = "use_vision";
  247. inp.type = "checkbox";
  248. var data = "0";
  249. if (GM_getValue) {
  250. data = GM_getValue("use_vision",1);
  251. if (data == "1") {
  252. inp.checked = true;
  253. }
  254. showVision = (data == "1");
  255. }
  256.  
  257. var vs = document.getElementById("use_hidden_qb_vision");
  258. if (vs != null) {
  259. vs.parentNode.insertBefore(inp,vs);
  260. vs.parentNode.removeChild(vs);
  261. inp.nextSibling.textContent = " Show QB Vision";
  262. }
  263. else {
  264. var text = document.createElement("text");
  265. text.textContent = " Show QB Vision";
  266. var options = document.getElementById("options_popup");
  267. options.appendChild(inp);
  268. options.appendChild(text);
  269. options.appendChild(document.createElement("br"));
  270. }
  271. inp.addEventListener("click",visionClicked,false);
  272.  
  273. var br = document.createElement("br");
  274. inp = document.createElement("input");
  275. inp.id = "variable_framerate";
  276. inp.type = "checkbox";
  277. var data = "0";
  278. if (GM_getValue) {
  279. data = GM_getValue("variable_framerate",0);
  280. if (data == "1") {
  281. inp.checked = true;
  282. }
  283. ihavearealoperatingsystem = (data == "1");
  284. }
  285.  
  286. var text = document.createElement("text");
  287. text.textContent = " Variable Framerate";
  288. var options = document.getElementById("options_popup");
  289. options.appendChild(br);
  290. options.appendChild(inp);
  291. options.appendChild(text);
  292. inp.addEventListener("click",framerateChanged,false);
  293.  
  294. var inp = document.getElementById("use_hidden_icons");
  295. if (inp == null) {
  296. inp = document.createElement("input");
  297. inp.id = "use_hidden_icons";
  298. inp.type = "checkbox";
  299. text = document.createElement("text");
  300. text.textContent = " Hide Popup Icons";
  301. var options = document.getElementById("options_popup");
  302. options.appendChild(br);
  303. options.appendChild(inp);
  304. options.appendChild(text);
  305. }
  306. showIcons = !inp.checked;
  307. inp.addEventListener("click",iconsClicked,false);
  308.  
  309. options.style.top = "575px";//parseInt(options.style.top)-100+"px";
  310. options.style.height = "150px";
  311.  
  312. if (document.getElementById("rrframe") == null) {
  313. var div = document.createElement("input");
  314. div.type = "hidden";
  315. div.id = "rrframe";
  316. div.value = 0;
  317. document.getElementById("footer").appendChild(div);
  318. }
  319.  
  320. var page = new Object();
  321. page.responseText = window.document.body.innerHTML;
  322. addPlayInfo(page);
  323. }
  324.  
  325. function framerateChanged(e) {
  326. if (e.target.checked == false) {
  327. if (GM_setValue) {
  328. GM_setValue("variable_framerate",0);
  329. }
  330. ihavearealoperatingsystem = false;
  331. frameSpeed = 925/frameRate;
  332. }
  333. else {
  334. if (GM_setValue) {
  335. GM_setValue("variable_framerate",1);
  336. }
  337. ihavearealoperatingsystem = true;
  338. }
  339. }
  340.  
  341. function iconsClicked(e) {
  342. if (e.target.checked == true) {
  343. showIcons = false;
  344. }
  345. else {
  346. showIcons = true;
  347. }
  348. }
  349.  
  350. function visionClicked(e) {
  351. if (e.target.checked == false) {
  352. if (GM_setValue) {
  353. GM_setValue("use_vision",0);
  354. }
  355. showVision = true;
  356. var vis = document.getElementById("vision");
  357. if (vis != null) {
  358. vis.parentNode.removeChild(vis);
  359. }
  360. }
  361. else {
  362. if (GM_setValue) {
  363. GM_setValue("use_vision",1);
  364. }
  365. showVision = false;
  366. }
  367. }
  368.  
  369. function pbpSetup() {
  370. var pbptag = document.createElement("div");
  371. pbptag.setAttribute("id","pbp");
  372.  
  373. var pbp = document.getElementById("pbp");
  374. if (pbp == null) {
  375. document.body.appendChild(pbptag);
  376.  
  377. var href = window.location.toString();
  378. href = href.replace("replay.pl","game.pl");
  379. var idx = href.indexOf("&pbp_id");
  380. href = href.slice(0,idx) + "&mode=pbp";
  381.  
  382. getInetPage(href, importPBP);
  383. setTimeout(pbpSetup, 300);
  384. return;
  385. }
  386. else if (pbp.childNodes.length == 0) {
  387. setTimeout(pbpSetup, 300);
  388. return;
  389. }
  390.  
  391. var page = new Object();
  392. page.responseText = pbp.innerHTML;
  393. if (plays == null) {
  394. loadPBPSimple(page);
  395. }
  396. resetPlay();
  397. buttonSetup();
  398.  
  399. if (alwaysPause == false) {
  400. play();
  401. }
  402. }
  403.  
  404. function addPlayInfo(page) {
  405. if (document.getElementById("use_playcall").checked == true) return;
  406.  
  407. var odesc = null;
  408. try {
  409. odesc = page.responseText.split("Offense Play:<br>")[1].split("<")[0];
  410. }
  411. catch (e) {
  412. console.log("first play? : "+e);
  413. return;
  414. }
  415. if (odesc != null) {
  416. var ddesc = null;
  417. try {
  418. ddesc = page.responseText.split("Defense Play:<br>")[1].split("<")[0];
  419. }
  420. catch (e) {
  421. console.log("no AI access? : "+e);
  422. }
  423.  
  424. if (ddesc == null) {
  425. ddesc = "Unknown";
  426. if (odesc == "Field Goal") ddesc = "Field Goal Block";
  427. else if (odesc == "Kickoff Return") ddesc = "Kickoff";
  428. else if (odesc == "Punt") ddesc = "Punt Return";
  429. else {
  430. var dl = 0;
  431. var lb = 0;
  432. var cb = 0;
  433. var s = 0;
  434. for (p in unsafeWindow.players) {
  435. var pos = unsafeWindow.players[p].position;
  436. console.log(pos);
  437. switch (pos) {
  438. case "LDE": case "DT": case "NT": case "RDE": dl++; break;
  439. case "LOLB": case "LILB": case "MLB": case "RILB": case "ROLB" : lb++; break;
  440. case "CB1": case "CB2": case "CB3": case "CB4": case "CB5" : cb++; break;
  441. case "FS": case "SS": s++;
  442. }
  443. }
  444. console.log(dl+" : "+lb+" : "+cb+" : "+s);
  445. if (lb == 4) {
  446. if (dl == 3) ddesc = "3-4";
  447. else ddesc = "4-4";
  448. }
  449. else if (cb == 5) ddesc = "3-1-7 Quarter";
  450. else if (cb == 4) {
  451. if (lb == 1) ddesc = "4-1-6 Dime";
  452. else ddesc = "3-2-6 Dime";
  453. }
  454. else if (cb == 3) {
  455. if (lb == 2) ddesc = "4-2-5 Nickel";
  456. else ddesc = "3-3-5 Nickel";
  457. }
  458. else if (lb == 3) ddesc = "4-3";
  459. else if (cb == 2) ddesc = "Goalline Small";
  460. else ddesc = "Goalline";
  461. }
  462. }
  463.  
  464. var diff = 4;
  465. if (goingUp(unsafeWindow.play_data) == true) {
  466. diff += 456;
  467. }
  468.  
  469. while (document.getElementsByClassName("play_container").length > 0) {
  470. var pc = document.getElementsByClassName("play_container");
  471. pc[0].parentNode.removeChild(pc[0]);
  472. }
  473.  
  474. console.log(odesc+" : "+ddesc);
  475. var odiv = document.createElement("div");
  476. odiv.setAttribute("class","play_container");
  477. odiv.setAttribute("id","play_container");
  478. odiv.setAttribute("style","top:"+diff+"px; left:4px");
  479. odiv.innerHTML = "Offense Play:<br>"+odesc;
  480. document.getElementById("replay_container").appendChild(odiv);
  481.  
  482. var ddiv = document.createElement("div");
  483. ddiv.setAttribute("class","play_container");
  484. ddiv.setAttribute("id","play_container");
  485. ddiv.setAttribute("style","top:"+diff+"px; left:269px;");
  486. ddiv.innerHTML = "Defense Play:<br>"+ddesc;
  487. document.getElementById("replay_container").appendChild(ddiv);
  488. }
  489. }
  490.  
  491. function buttonSetup(play) {
  492. var currentPlay = -1;
  493. if (play == null) {
  494. var addr = document.getElementById("rrplay").value;
  495. for (var i=0; i<plays.length; i++) {
  496. if (plays[i].replay == addr) {
  497. currentPlay = i;
  498. document.getElementById("rrplay").setAttribute("index",i);
  499. break;
  500. }
  501. }
  502. }
  503. else {
  504. currentPlay = play;
  505. }
  506. console.log("currentPlay = "+currentPlay);
  507.  
  508. var control = document.getElementById("controls");
  509. var buttons = control.getElementsByClassName("button");
  510. for (var i=0; i<buttons.length; i++) {
  511. var b = buttons[i];
  512. if (b.firstChild.innerHTML == "Next &gt;") {
  513. b.id = Math.min(currentPlay+1, plays.length-1);
  514. }
  515. else if (b.firstChild.innerHTML == "Next Poss &gt;&gt;") {
  516. b.id = Math.min(currentPlay+100, findPoss(currentPlay,99));
  517. }
  518. else if (b.firstChild.innerHTML == "&lt; Prev") {
  519. b.id = Math.max(currentPlay-1, 0);
  520. }
  521. else if (b.firstChild.innerHTML == "&lt;&lt; Prev Poss") {
  522. b.id = Math.max(currentPlay-100, findPoss(currentPlay,-99));
  523. }
  524. }
  525.  
  526. var playText = plays[currentPlay].play;
  527. if ((playText.indexOf("Kickoff") == 0) || (playText.indexOf("Punt by ") == 0) ||
  528. (playText.indexOf(" attempted by ") != -1)) {
  529. ballMotionImg = "kicking-ball.gif";
  530. }
  531. else {
  532. ballMotionImg = "passing-ball.gif";
  533. }
  534. }
  535.  
  536. function addPlayerLinks() {
  537. var links = document.getElementsByClassName("player_name");
  538. for (var i=0; i<links.length; i++) {
  539. var id = links[i].href.split("=")[1];
  540. links[i].id = "player_link_"+id;
  541. }
  542. }
  543.  
  544. function clearPlayers() {
  545. var area = document.getElementById("replay_area");
  546.  
  547. var list = area.getElementsByClassName("player_icon_overlay");
  548. while (list.length > 0) {
  549. list[0].parentNode.removeChild(list[0]);
  550. list = area.getElementsByClassName("player_icon_overlay");
  551. }
  552.  
  553. list = area.getElementsByClassName("player_icon");
  554. while (list.length > 0) {
  555. list[0].parentNode.removeChild(list[0]);
  556. list = area.getElementsByClassName("player_icon");
  557. }
  558.  
  559. list = area.getElementsByClassName("player_popup_icon");
  560. while (list.length > 0) {
  561. list[0].parentNode.removeChild(list[0]);
  562. list = area.getElementsByClassName("player_popup_icon");
  563. }
  564.  
  565. }
  566.  
  567. //var diffarray = new Array();
  568. var startTime = 0;
  569. var endTime = 0;
  570. var adj = [0,0];
  571.  
  572. function render() {
  573. //console.log("render: pP="+playPaused+" : pFT="+(playFinishedTimer != null)+" : cF="+currentFrame+" / "+play_data.length);
  574. //console.log(playPaused);
  575. //console.log(playFinishedTimer == null);
  576. if (playPaused == true) {
  577. return;
  578. }
  579. if (playFinishedTimer != null) {
  580. return;
  581. }
  582. if (lastTime == -1) {
  583. lastTime = new Date().getTime();
  584. if (alwaysPause == true) {
  585. playPaused = true;
  586. return;
  587. }
  588. else {
  589. frameTimer = setTimeout(render,preDelay);
  590. return;
  591. }
  592. }
  593.  
  594. if (currentFrame == 0) {
  595. startTime = new Date().getTime();
  596. }
  597.  
  598. //console.log("a "+currentFrame+" --- "+(play_data.length));
  599. if (currentFrame < play_data.length) {
  600. var newTime = new Date().getTime();
  601. var diff = newTime - lastTime;
  602. if (ihavearealoperatingsystem == true) {
  603. //diffarray.push(diff);
  604. if (diff < frameSpeed) {
  605. frameTimer = setTimeout(render,frameSpeed-diff);
  606. return;
  607. }
  608. //draw frame here
  609. drawFrame();
  610. currentFrame++;
  611.  
  612. if ((1000/(newTime-lastTime)) < (frameRate-0.5)) {
  613. frameSpeed = frameSpeed * 0.95;
  614. adj[0]++;
  615. }
  616. else if ((1000/(newTime-lastTime)) > (frameRate+0.5)) {
  617. frameSpeed = frameSpeed * 1.05;
  618. adj[1]++;
  619. }
  620. lastTime = newTime;
  621. }
  622. else {
  623. //diffarray.push(diff);
  624. if (diff < frameSpeed) {
  625. frameTimer = setTimeout(render,5);
  626. return;
  627. }
  628. //draw frame here
  629. drawFrame();
  630. currentFrame++;
  631. lastTime = newTime;
  632. }
  633. }
  634.  
  635. //console.log("b "+currentFrame+" --- "+(play_data.length));
  636. if (currentFrame > play_data.length-1) {
  637. endTime = new Date().getTime();
  638. console.log(startTime+" - "+endTime+" = "+(endTime-startTime)+" | "+play_data.length+" | "+(play_data.length/((endTime-startTime)/1000)).toFixed(2)+" - "+frameSpeed.toFixed(2)+" | "+frameRate+"["+adj[0]+"/"+adj[1]+"]");
  639. clearTimeout(frameTimer);
  640. frameTimer = null;
  641. adj = [0,0];
  642.  
  643. var p = document.getElementById("play_outcome");
  644. p.style.display = "block";
  645. p.style.visibility = "visible";
  646.  
  647. currentFrame = 0;
  648. playDone = true;
  649. if (parseInt(thisScore) != 0) {
  650. var sdiv = null;
  651. if (scoreUpdate == "O") {
  652. sdiv = document.getElementById("off_score");
  653. }
  654. else {
  655. sdiv = document.getElementById("def_score");
  656. }
  657. sdiv.innerHTML = parseInt(sdiv.innerHTML) + parseInt(thisScore);
  658. sdiv.style.outlineStyle = "solid";
  659. sdiv.style.outlineColor = "white";
  660. sdiv.style.color = "gold";
  661. thisScore = 0;
  662. }
  663. if (playFinishedTimer == null) {
  664. //console.log("setting playIsFinished");
  665. playFinishedTimer = setTimeout(playIsFinished,postDelay);
  666. }
  667. else {
  668. console.log("not setting playIsFinished");
  669. }
  670. //console.log(diffarray);
  671. //diffarray = new Array();
  672. }
  673. else {
  674. frameTimer = setTimeout(render,5);//frameSpeed>>2);
  675. }
  676. }
  677.  
  678. function play() {
  679. if (frameTimer != null) {
  680. clearTimeout(frameTimer);
  681. frameTimer = null;
  682. }
  683.  
  684. var div = document.getElementById("rrplay");
  685. if (div.childNodes.length > 0) {
  686. //console.log("waiting ("+div.childNodes.length+") ...");
  687. setTimeout(play, 200);
  688. return;
  689. }
  690. playPaused = false;
  691. render();
  692. }
  693.  
  694. function pauseReplay() {
  695. // console.log("pauseReplay");
  696. if (playDone == true) {
  697. if (postPlayTimer != null) {
  698. clearTimeout(postPlayTimer);
  699. postPlayTimer = null;
  700. }
  701. playPaused = true;
  702. playDone = false;
  703. }
  704. else {
  705. playPaused = !playPaused;
  706. }
  707.  
  708. // console.log("playDone is "+playDone);
  709. if (playPaused == true) {
  710. clearTimeout(frameTimer);
  711. frameTimer = null;
  712. }
  713. else {
  714. if (playDone == false) {
  715. play();
  716. }
  717. }
  718. }
  719.  
  720. function findPlayer(player, arr) {
  721. //console.log("findPlayer");
  722. var output = -1;
  723. for (var i=0; i<arr.length; i++) {
  724. if (player.id == arr[i].id) {
  725. output = i;
  726. break;
  727. }
  728. }
  729. //console.log(player.id+" <--> "+arr[output].id);
  730. //console.log(" : returning "+output);
  731. if (output == -1) {
  732. console.log("this is -1 : "+player.id);
  733. }
  734. return output;
  735. }
  736.  
  737. function bortFix() {
  738. if (firstRun == true) {
  739. for (var f=0; f<unsafeWindow.play_data.length; f++) {
  740. for (var p=0; p<unsafeWindow.play_data[f].length; p++) {
  741. unsafeWindow.play_data[f][p].x = (unsafeWindow.play_data[f][p].x - 20) / 3;
  742. unsafeWindow.play_data[f][p].y = (unsafeWindow.play_data[f][p].y - 40) / 3;
  743. if (unsafeWindow.frameSpeed != 100) {
  744. if (unsafeWindow.play_data[f][p].tx != null) {
  745. unsafeWindow.play_data[f][p].tx = (unsafeWindow.play_data[f][p].tx - 20) / 3;
  746. unsafeWindow.play_data[f][p].ty = (unsafeWindow.play_data[f][p].ty - 40) / 3;
  747. }
  748. }
  749. }
  750. }
  751.  
  752. if (offenseOnBottom == true) {
  753. if (goingUp(unsafeWindow.play_data) == false) {
  754. for (var f=0; f<unsafeWindow.play_data.length; f++) {
  755. for (var p = 0; p < unsafeWindow.play_data[f].length; p++) {
  756. unsafeWindow.play_data[f][p].x = 160 - unsafeWindow.play_data[f][p].x;
  757. unsafeWindow.play_data[f][p].y = 360 - unsafeWindow.play_data[f][p].y;
  758. if (unsafeWindow.play_data[f][p].tx != null) {
  759. unsafeWindow.play_data[f][p].tx = 160 - unsafeWindow.play_data[f][p].tx;
  760. unsafeWindow.play_data[f][p].ty = 360 - unsafeWindow.play_data[f][p].ty;
  761. }
  762. }
  763. }
  764. }
  765. }
  766.  
  767. firstRun = false;
  768. }
  769. }
  770.  
  771. function goingUp(pd) {
  772. if (pd.length == 0) return 0;
  773. var count = 0;
  774. for (var i=1; i<pd[0].length; i++) {
  775. if (pd[0][0].y >= pd[0][i].y) {
  776. count++;
  777. }
  778. else {
  779. count--;
  780. }
  781. }
  782. return count > 0;
  783. }
  784.  
  785. var rotation = null;
  786.  
  787. function fixFrames() {
  788. //console.log("fixFrames");
  789. var stime = new Date();
  790. var uwpd = new Array();
  791. for (var i=0; i<unsafeWindow.play_data.length; i++) {
  792. uwpd.push(new Array());
  793. }
  794.  
  795. var missing = 0;
  796. for (var p=0; p<unsafeWindow.play_data[0].length; p++) {
  797. var id = unsafeWindow.play_data[0][p].id;
  798.  
  799. for (var cf=0; cf<unsafeWindow.play_data.length; cf++) {
  800. var found = false;
  801. for (var i=0; i<unsafeWindow.play_data[cf].length; i++) {
  802. if (id == unsafeWindow.play_data[cf][i].id) {
  803. found = true;
  804. uwpd[cf].push(eval(uneval(unsafeWindow.play_data[cf][i])));
  805. break;
  806. }
  807. }
  808. if (!found) {
  809. uwpd[cf].push(eval(uneval(uwpd[cf-1][p])));
  810. missing++;
  811. }
  812. }
  813. }
  814. var time = new Date() - stime;
  815. console.log("uwpd copy ("+missing+" missing): "+time.toFixed(0)+"ms");
  816.  
  817. var stime = new Date();
  818. for (var i=1; i<uwpd[0].length; i++) {
  819. var u = uwpd[0][i];
  820.  
  821. if (document.getElementById("breathcon_"+u.id) != null) {
  822. document.getElementById("breathcon_"+u.id).parentNode.removeChild(document.getElementById("breathcon_"+u.id));
  823. document.getElementById("morcon_"+u.id).parentNode.removeChild(document.getElementById("morcon_"+u.id));
  824. }
  825.  
  826. if ((u.br > 0) || (u.mo > 0)) {
  827. var li = document.getElementById("player_link_"+u.id);
  828. if (li != null) {
  829. var brdiv = document.createElement("div");
  830. brdiv.setAttribute("id","breathcon_"+u.id);
  831. brdiv.setAttribute("style","margin: 0px; padding: 0px; position: relative; top: -5px; left: 20px; width: 100px; height: 3px; text-align: left; visibility: visible; background-color: rgb(0, 0, 0);");
  832. var brimg = document.createElement("img");
  833. brimg.setAttribute("id","breath_"+u.id);
  834. brimg.setAttribute("src","/images/spacer.gif");
  835. brimg.setAttribute("style","position: relative; top: -9px; width: 100px; height: 3px;");
  836.  
  837. brdiv.appendChild(brimg);
  838. li.parentNode.appendChild(brdiv);
  839.  
  840. var modiv = document.createElement("div");
  841. modiv.setAttribute("id","morcon_"+u.id);
  842. modiv.setAttribute("style","margin: 0px; padding: 0px; position: relative; top: -8px; left: 125px; width: 100px; height: 3px; text-align: left; visibility: visible; background-color: rgb(0, 0, 0);");
  843. var moimg = document.createElement("img");
  844. moimg.setAttribute("id","morale_"+u.id);
  845. moimg.setAttribute("src","/images/spacer.gif");
  846. moimg.setAttribute("style","position: relative; top: -9px; width: 100px; height: 3px;");
  847.  
  848. modiv.appendChild(moimg);
  849. li.parentNode.appendChild(modiv);
  850. }
  851.  
  852. var div = document.getElementById("breathcon_"+u.id);
  853. div.addEventListener("mouseover",function (e) {
  854. unsafeWindow.set_tip("Energy: "+parseInt(this.firstChild.style.width), 0, 1, 1, 1);
  855. },false);
  856. div.addEventListener("mouseout",function (e) {
  857. unsafeWindow.unset_tip();
  858. },false);
  859.  
  860. var div = document.getElementById("morcon_"+u.id);
  861. div.addEventListener("mouseover",function (e) {
  862. unsafeWindow.set_tip("Morale: "+parseInt(this.firstChild.style.width), 0, 1, 1, 1);
  863. },false);
  864. div.addEventListener("mouseout",function (e) {
  865. unsafeWindow.unset_tip();
  866. },false);
  867. }
  868. }
  869. var time = new Date() - stime;
  870. console.log("breath/morale : "+time.toFixed(0)+"ms");
  871.  
  872. var stime = new Date();
  873. if (uwpd[0] != null) {
  874. for (var f=0; f<uwpd.length; f++) {
  875. uwpd[f][0].x = parseInt(uwpd[f][0].x*3 + 20 - 3);
  876. uwpd[f][0].y = parseInt(uwpd[f][0].y*3 + 40 - 6);
  877. if (uwpd[f][0].z != null) {
  878. uwpd[f][0].z = Math.min(100+(uwpd[f][0].z-4)*3, 200)/100;
  879. }
  880. else {
  881. uwpd[f][0].z = 1;
  882. }
  883. if (uwpd[f][0].tx != null) {
  884. uwpd[f][0].tx = parseInt(uwpd[f][0].tx*3 + 20 - 3);
  885. uwpd[f][0].ty = parseInt(uwpd[f][0].ty*3 + 40 - 6);
  886. }
  887. for (var g=1; g<uwpd[f].length; g++) {
  888. uwpd[f][g].x = parseInt(uwpd[f][g].x*3 + 20 - 6);
  889. uwpd[f][g].y = parseInt(uwpd[f][g].y*3 + 40 - 6);
  890. }
  891. }
  892. }
  893. else {
  894. return new Array();
  895. }
  896. var time = new Date() - stime;
  897. console.log("multiply : "+time.toFixed(0)+"ms");
  898.  
  899. var stime = new Date();
  900. var pd = new Array();
  901. for (var cf=0; cf<uwpd.length-1; cf++) {
  902. var arr = new Array();
  903. var arr2 = null;
  904. for (var i = 0; i < uwpd[cf].length; i++) {
  905. var data = uwpd[cf][i];
  906. arr.push(data);
  907. //console.log(data.id+" -- "+data.x+" -- "+data.y+" -- "+data.p+" -- "+data.tx+","+data.ty);
  908. if (unsafeWindow.frameSpeed == 50) {
  909. if (arr2 == null) {
  910. arr2 = new Array();
  911. }
  912. var data2 = uwpd[cf+1][i];
  913.  
  914. var d = new Object();
  915. d.id = data.id;
  916. d.x = (data.x + data2.x) / 2;
  917. d.y = (data.y + data2.y) / 2;
  918. d.z = (data.z + data2.z) / 2;
  919.  
  920. if (data2.p != null) d.p = data2.p;
  921.  
  922. if (data.tx != null) {
  923. d.tx = data.tx;
  924. d.ty = data.ty;
  925. }
  926. if ((data.tx != null) && (data2.tx != null)) {
  927. d.tx = (data.tx + data2.tx) / 2;
  928. d.ty = (data.ty + data2.ty) / 2;
  929. }
  930. arr2.push(d);
  931. }
  932. }
  933. pd.push(arr);
  934. if (arr2 != null) {
  935. pd.push(arr2);
  936. }
  937. }
  938. pd.push(uwpd[uwpd.length-1]);
  939. var time = new Date() - stime;
  940. console.log("10-20 : "+time.toFixed(0)+"ms");
  941.  
  942. var stime = new Date();
  943. vision_data = new Array();
  944. if (pd[0] != null) {
  945. for (var f=0; f<pd.length; f++) {
  946. var div = document.createElement("div");
  947. div.setAttribute("id","vision");
  948. div.style.position = "absolute";
  949.  
  950. var ball = pd[f][0];
  951. if (ball.tx != null) {
  952. //console.log("("+ball.x+","+ball.y+") -1-to ("+ball.tx+","+ball.ty+")");
  953. var x1 = Math.round(ball.x);
  954. var y1 = Math.round(ball.y);
  955. var x2 = Math.round(ball.tx);
  956. var y2 = Math.round(ball.ty);
  957. if (ball.x > ball.tx) {
  958. var temp = x1;
  959. x1 = x2;
  960. x2 = temp;
  961.  
  962. temp = y1;
  963. y1 = y2;
  964. y2 = temp;
  965. }
  966. // console.log("("+x1+","+y1+") -2-to ("+x2+","+y2+")");
  967.  
  968. div.style.left = (x1-1)+"px";
  969. div.style.top = (y1-1)+"px";
  970. div.style.width = Math.abs(x2-x1+2)+"px";
  971. // console.log(y2+"-"+y1+"+2 = "+(y2-y1+2));
  972. div.style.height = Math.abs(y2-y1+2)+"px";
  973. div.style.zIndex = 750;
  974.  
  975. // console.log("("+(ball.x-x1)+","+(ball.y-y1)+") -3-to ("+(ball.tx-x1)+","+(ball.ty-y1)+")");
  976. drawLine(div, parseInt(ball.x-x1), parseInt(ball.y-y1),
  977. parseInt(ball.tx-x1), parseInt(ball.ty-y1));
  978. vision_data[f] = div;
  979. }
  980. }
  981. }
  982. var time = new Date() - stime;
  983. console.log("vision : "+time.toFixed(0)+"ms");
  984.  
  985. var stime = new Date();
  986. poss_data = new Array();
  987. if (pd[0] != null) {
  988. for (var f=0; f<pd.length; f++) {
  989. var current = null;
  990. var ball = pd[f][0];
  991. for (var p=1; p<pd[f].length; p++) {
  992. var player = pd[f][p];
  993. if (ball.y != player.y) continue;
  994. var dx = Math.max(ball.x,player.x) - Math.min(ball.x,player.x);
  995. if ((dx != 0) && (dx != 3) && (dx != 9) || (ball.z != 1)) continue;
  996. current = player.id;
  997. break;
  998. }
  999. poss_data.push(current);
  1000. }
  1001. }
  1002. var time = new Date() - stime;
  1003. console.log("possession : "+time.toFixed(0)+"ms");
  1004.  
  1005. var stime = new Date();
  1006. cam_data = new Array();
  1007. if (pd != null) {
  1008. for (var i=0; i<pd.length; i++) {
  1009. cam_data.push(0);
  1010. if (pd[i] == null) break;
  1011.  
  1012. if (pd[i].length < 23) {
  1013. cam_data[i] = cam_data[i-1];
  1014. }
  1015. else {
  1016. for (var p=0; p<pd[i].length; p++) {
  1017. cam_data[i] += pd[i][p].y;
  1018. }
  1019. cam_data[i] = cam_data[i]/pd[i].length;
  1020.  
  1021. var ballTop = pd[i][0].y;
  1022. var top = cam_data[i] - 250;
  1023. if (top+425 < ballTop) {
  1024. top = ballTop - 425;
  1025. }
  1026. else if (top+75 > ballTop) {
  1027. top = ballTop-75;
  1028. }
  1029. var val = 0 - top;
  1030. val = Math.min(0, val);
  1031. val = Math.max(val, -660);
  1032. cam_data[i] = parseInt(val);
  1033. }
  1034. }
  1035. }
  1036. var time = new Date() - stime;
  1037. console.log("cam : "+time.toFixed(0)+"ms");
  1038.  
  1039. var stime = new Date();
  1040. var j=0;
  1041. rotation = null;
  1042. for (var i=0; i<pd.length-1; i++) {
  1043. //console.log(i+") "+pd[i][0].x+","+pd[i][0].y+","+pd[i][0].z);
  1044. if (rotation == null) {
  1045. if (pd[i][0].z > 1.07) {
  1046. j=i;
  1047. rotation = pd[i][0];
  1048. rotation.start = i;
  1049. for (var j=i; j<poss_data.length; j++) {
  1050. if (poss_data[j] != null) {
  1051. rotation.stop = j;
  1052. break;
  1053. }
  1054. }
  1055. }
  1056. }
  1057. else {
  1058. if (rotation.x < pd[i+1][0].x) {
  1059. mul = 1;
  1060. }
  1061. else {
  1062. mul = -1;
  1063. }
  1064. if (rotation.y < pd[i+1][0].y) {
  1065. mul = mul * -1;
  1066. }
  1067. else {
  1068. mul = mul * 1;
  1069. }
  1070. rotation.val = mul * Math.atan(Math.abs(rotation.x-pd[i+1][0].x)/Math.abs(rotation.y-pd[i+1][0].y));
  1071. rotation.val += 2*Math.PI;
  1072. break;
  1073. }
  1074. }
  1075. if (rotation == null) {
  1076. rotation = 0;
  1077. rotation.val = 0;
  1078. rotation.start = pd.length;
  1079. rotation.stop = pd.length;
  1080. }
  1081. var time = new Date() - stime;
  1082. console.log("rotation ("+j+","+i+","+rotation.val+","+rotation.start+"/"+rotation.stop+"): "+time.toFixed(0)+"ms");
  1083.  
  1084. var stime = new Date();
  1085. playerExtrasIn = new Array();
  1086. playerExtrasOut = new Array();
  1087.  
  1088. for (var cf=0; cf<pd.length-1; cf++) {
  1089. for (var i = 0; i < pd[cf].length; i++) {
  1090. var data = pd[cf][i];
  1091. if (pd[cf][i].icon != null) {
  1092. if (pd[cf][i].icon.indexOf("s_") == 0) {
  1093. //console.log("removing this icon(!?!?): "+pd[cf][i].icon);
  1094. pd[cf][i].icon = null;
  1095. }
  1096. }
  1097.  
  1098. var deletion = ["looked_off","im_open","pump_faked"];
  1099. for (var dx=0; dx<deletion.length; dx++) {
  1100. if (data.icon == deletion[dx]) {
  1101. for (var j=cf+1; j<pd.length; j++) {
  1102. if (pd[j][i].icon == deletion[dx]) {
  1103. pd[j][i].icon = null;
  1104. }
  1105. }
  1106. }
  1107. }
  1108. }
  1109. }
  1110.  
  1111. for (var cf=0; cf<pd.length-1; cf++) {
  1112. var frame = cf;
  1113. var exl = 8;
  1114. if (unsafeWindow.frameSpeed == 50) {
  1115. exl += exl;
  1116. }
  1117. var expire = frame+exl;
  1118.  
  1119. for (var i = 0; i < pd[cf].length; i++) {
  1120. var data = pd[cf][i];
  1121. if (data.icon != null) {
  1122. if (playerExtrasIn[frame] == null) {
  1123. playerExtrasIn[frame] = new Array();
  1124. }
  1125. playerExtrasIn[frame].push([data.id,data.icon,data.x-12,data.y-16]);
  1126. if ((data.icon.indexOf("sweat") != -1) ||
  1127. (data.icon.indexOf("sad") != -1)) {
  1128. expire = frame + 1;
  1129. }
  1130. // console.log(cf+": i="+i+" : f="+frame+" --> exp="+expire+") "+data.icon);
  1131.  
  1132. if (playerExtrasOut[expire] == null) {
  1133. playerExtrasOut[expire] = new Array();
  1134. }
  1135. playerExtrasOut[expire].push([data.id, data.icon]);
  1136. }
  1137. }
  1138. }
  1139. var time = new Date() - stime;
  1140. console.log("extras : "+time.toFixed(0)+"ms");
  1141.  
  1142. var stime = new Date();
  1143. var t = 0;
  1144. var brskip = 0;
  1145. var moskip = 0;
  1146. for (var i=1; i<pd[0].length; i++) {
  1147. var breath = pd[0][i].br;
  1148. var morale = pd[0][i].mo;
  1149.  
  1150. for (var f=1; f<pd.length; f++) {
  1151. if (pd[f][i] == null) break;
  1152.  
  1153. t++;
  1154. if (pd[f][i].br != null) {
  1155. if (pd[f][i].br == breath) {
  1156. pd[f][i].br = null;
  1157. brskip++;
  1158. }
  1159. else {
  1160. breath = pd[f][i].br;
  1161. }
  1162. }
  1163. if (pd[f][i].mo != null) {
  1164. if (pd[f][i].mo == morale) {
  1165. pd[f][i].mo = null;
  1166. moskip++;
  1167. }
  1168. else {
  1169. morale = pd[f][i].mo;
  1170. }
  1171. }
  1172. }
  1173. }
  1174. console.log("br="+brskip+"/"+t+" : "+(100*brskip/t).toFixed(0)+"%");
  1175. console.log("mo="+moskip+"/"+t+" : "+(100*moskip/t).toFixed(0)+"%");
  1176. var time = new Date() - stime;
  1177. console.log("strip : "+time.toFixed(0)+"ms");
  1178.  
  1179. //console.log("fixFrames end");
  1180. return pd;
  1181. }
  1182.  
  1183. function drawLine(div, x0, y0, x1, y1) {
  1184. //console.log(x0+","+y0+" --> "+x1+","+y1);
  1185. var gstep = 0;
  1186. var slope = Math.abs(y1 - y0) > Math.abs(x1 - x0);
  1187. if (slope) {
  1188. var temp = x0;
  1189. x0 = y0;
  1190. y0 = temp;
  1191. temp = x1;
  1192. x1 = y1;
  1193. y1 = temp;
  1194. }
  1195. if (x0 > x1) {
  1196. var temp = x0;
  1197. x0 = x1;
  1198. x1 = temp;
  1199. temp = y0;
  1200. y0 = y1;
  1201. y1 = temp;
  1202. }
  1203. var deltax = x1 - x0;
  1204. var deltay = Math.abs(y1 - y0);
  1205. var error = deltax << 1;
  1206. var ystep;
  1207. var y = y0;
  1208. if (y0 < y1) {
  1209. ystep = 1;
  1210. }
  1211. else {
  1212. ystep = -1;
  1213. }
  1214. for (var x=x0; x<x1; x++) {
  1215. if (gstep % visionDivSkip == 0) {
  1216. if (slope) {
  1217. plot(div,y,x);
  1218. }
  1219. else {
  1220. plot(div,x,y);
  1221. }
  1222. }
  1223. gstep++;
  1224. error = error - deltay;
  1225. if (error < 0) {
  1226. y = y + ystep;
  1227. error = error + deltax;
  1228. }
  1229. }
  1230. }
  1231.  
  1232. function plot(div, x,y) {
  1233. // console.log(x+","+y+" -- "+visionDivSize);
  1234. var d = document.createElement("div");
  1235. d.style.backgroundColor = "white";
  1236. d.style.position = "absolute";
  1237. d.style.left = x+"px";
  1238. d.style.top = y+"px";
  1239. d.style.width = visionDivSize+"px";
  1240. d.style.height = visionDivSize+"px";
  1241. d.style.zIndex = "751";
  1242. div.appendChild(d);
  1243. //console.log("("+d.style.left+","+d.style.top+")");
  1244. }
  1245.  
  1246. function resetPlay() {
  1247. //console.log("resetPlay");
  1248. clearPlayers();
  1249. playDone = false;
  1250. playerDiv = new Array();
  1251. playerOvr = new Array();
  1252. play_data = fixFrames();
  1253.  
  1254. currentFrame = 0;
  1255. drawFrame();
  1256.  
  1257. if (playPaused == false) {
  1258. setTimeout(play, preDelay);
  1259. }
  1260. //console.log("resetPlay end");
  1261. }
  1262.  
  1263. function drawFrame() {
  1264. //console.log("drawFrame");
  1265.  
  1266. var rrframe = document.getElementById("rrframe");
  1267. rrframe.value = currentFrame;
  1268.  
  1269. var evt = document.createEvent("HTMLEvents");
  1270. evt.initEvent("change",false,false);
  1271. rrframe.dispatchEvent(evt);
  1272.  
  1273. var frame = play_data[currentFrame];
  1274. if (frame == null) {
  1275. return;
  1276. }
  1277.  
  1278. if (replayArea == null) {
  1279. replayArea = document.getElementById("replay_area");
  1280. }
  1281. for (var i = 1; i < frame.length; i++) {
  1282. var data = frame[i];
  1283. drawPlayer(data.id, data.x, data.y, data.z, data.p, data.icon, data.br, data.mo);
  1284. }
  1285. drawPlayer('ball', frame[0].x, frame[0].y, frame[0]['z']);
  1286. drawBall();
  1287.  
  1288. if (showVision == true) {
  1289. var vis = document.getElementById("vision");
  1290. if (vis != null) {
  1291. document.getElementById("replay_area").removeChild(vis);
  1292. }
  1293. if (frame[0].tx != null) {
  1294. document.getElementById("replay_area").appendChild(vision_data[currentFrame]);
  1295. }
  1296. }
  1297.  
  1298. if (playerExtrasOut[currentFrame] != null) {
  1299. for (var i=0; i<playerExtrasOut[currentFrame].length; i++) {
  1300. var d = playerExtrasOut[currentFrame][i];
  1301. //console.log("removing : "+d);
  1302. var img = null;
  1303. do {
  1304. img = document.getElementById("player_extras_"+d[0]);
  1305. if (img != null) {
  1306. replayArea.removeChild(img);
  1307. }
  1308. }
  1309. while (img != null);
  1310. }
  1311. }
  1312.  
  1313. if (showIcons == true) {
  1314. if (playerExtrasIn[currentFrame] != null) {
  1315. for (var i=0; i<playerExtrasIn[currentFrame].length; i++) {
  1316. var d = playerExtrasIn[currentFrame][i];
  1317. var img = document.createElement("img");
  1318. img.setAttribute("class","player_popup_icon");
  1319. img.id = "player_extras_"+d[0];
  1320. img.style.left = d[2]+"px";
  1321. img.style.top = d[3]+"px";
  1322. img.style.zIndex = playerLayerZ+1;
  1323. img.src = "/images/replay_icons/"+d[1]+".gif";
  1324. //console.log("creating : "+d);
  1325. replayArea.appendChild(img);
  1326. }
  1327. }
  1328. }
  1329.  
  1330. replayArea.style.top = cam_data[currentFrame]+"px";
  1331. }
  1332.  
  1333. function createPlayerDot(id, x, y, z, p) {
  1334. if (playerDiv[id] == null) {
  1335. var oldDiv = document.getElementById(id);
  1336. if (oldDiv != null) {
  1337. oldDiv.parentNode.removeChild(oldDiv);
  1338. }
  1339.  
  1340. if (id != "ball") {
  1341. var div = document.createElement('img');
  1342. div.className = 'player_icon';
  1343. div.id = id;
  1344. if (document.getElementById("use_colors").checked == true) {
  1345. if (p != null) {
  1346. div.style.width = "13px";
  1347. div.style.height = "13px";
  1348. }
  1349. div.src = '/images/' + unsafeWindow.players[id].position + '.png';
  1350. }
  1351. else {
  1352. var path = "";
  1353. if (hometeam == ptid[id]) {
  1354. var color1 = unsafeWindow.home_color1;
  1355. var color2 = unsafeWindow.home_color2;
  1356. var border = unsafeWindow.home_border;
  1357. path = color2;
  1358. if (border != 0) {
  1359. path += "_border";
  1360. }
  1361. path += "_home";
  1362. }
  1363. else {
  1364. var color1 = unsafeWindow.away_color1;
  1365. var color2 = unsafeWindow.away_color2;
  1366. var border = unsafeWindow.away_border;
  1367. path = color2;
  1368. if (border != 0) {
  1369. path += "_border";
  1370. }
  1371. }
  1372.  
  1373. if (p == null) {
  1374. div.style.backgroundImage = "url(\"/images/dots/" + color1 + ".gif\")";
  1375. div.src = '/images/dots/' + path + '/' + unsafeWindow.players[id].position + '.gif';
  1376. }
  1377. else {
  1378. if (showShrinkAnimation == true) {
  1379. div.src = '/images/dots/' + path + '/' + unsafeWindow.players[id].position + '.gif';
  1380. div.style.width = "13px";
  1381. div.style.height = "13px";
  1382. div.style.backgroundImage = "url(\"/images/dots/" + color1 + "_small.gif\")";
  1383. div.style.backgroundRepeat = "no-repeat";
  1384. }
  1385. else {
  1386. div.style.backgroundImage = "url(\"/images/dots/" + color1 + ".gif\")";
  1387. div.src = '/images/spacer.gif';
  1388. }
  1389. }
  1390. div.style.zIndex = playerLayerZ;
  1391. }
  1392. div.addEventListener("click",function (e) {
  1393. unsafeWindow.viewPlayer(id);
  1394. },false);
  1395. div.addEventListener("mouseover",function (e) {
  1396. unsafeWindow.set_tip(unsafeWindow.players[id].name.replace(/\\/g, '\\\\').replace(/'/g, "\\" + '&#39;').replace(/"/g, '&quot;'), 0, 1, 1, 1);
  1397. },false);
  1398. div.addEventListener("mouseout",function (e) {
  1399. unsafeWindow.unset_tip();
  1400. },false);
  1401.  
  1402. playerDiv[id] = div;
  1403. replayArea.appendChild(playerDiv[id]);
  1404. }
  1405. else {
  1406. var img = document.createElement('img');
  1407. img.id = 'ball';
  1408.  
  1409. img.className = 'player_icon';
  1410. img.src = ballImage;
  1411. img.style.zIndex = playerLayerZ+1;
  1412. playerDiv["ball"] = img;
  1413. replayArea.appendChild(playerDiv["ball"]);
  1414. }
  1415. }
  1416. }
  1417.  
  1418. function drawPlayer(id, x, y, z, p, icon, br, mo) {
  1419. //console.log("drawPlayer");
  1420. //if (p != null) console.log("mine: "+id+"("+x+","+y+","+z+","+p+")");
  1421. //console.log("mine: "+id+"("+x+","+y+","+z+")");
  1422. if (playerDiv[id] == null) {
  1423. createPlayerDot(id, x, y, z, p);
  1424. }
  1425. else {
  1426. pancakeCheck(id, x, y, z, p);
  1427. }
  1428. if (id == "ball") {
  1429. if (currentFrame == rotation.start) {
  1430. playerDiv["ball"].src = "/images/"+ballMotionImg;
  1431. playerDiv["ball"].setAttribute("style","-moz-transform: rotate("+rotation.val+"rad); "+playerDiv["ball"].getAttribute("style"));
  1432. }
  1433. else if ((currentFrame >= rotation.stop) || (currentFrame == 0)) {
  1434. playerDiv["ball"].src = ballImage;
  1435. playerDiv["ball"].setAttribute("style",playerDiv["ball"].getAttribute("style").split(";",2)[1]);
  1436. playerDiv["ball"].style.width = 10 + 'px';
  1437. playerDiv["ball"].style.height = 17 + 'px';
  1438. playerDiv["ball"].style.zIndex = playerLayerZ + 1;
  1439. }
  1440. if (isNaN(z) == false) {
  1441. playerDiv["ball"].style.width = parseInt(10 * z) + 'px';
  1442. playerDiv["ball"].style.height = parseInt(17 * z) + 'px';
  1443. }
  1444. playerDiv["ball"].style.left = x+'px';
  1445. playerDiv["ball"].style.top = y+'px';
  1446. }
  1447. else {
  1448. playerDiv[id].style.left = x + 'px';
  1449. playerDiv[id].style.top = y + 'px';
  1450. if (br) {
  1451. document.getElementById("breath_"+id).style.width = br+"px";
  1452. document.getElementById("breath_"+id).style.background = gradient[br];
  1453. }
  1454. if (mo) {
  1455. document.getElementById("morale_"+id).style.width = mo+"px";
  1456. document.getElementById("morale_"+id).style.background = gradient[mo];
  1457. }
  1458. }
  1459. }
  1460.  
  1461. function playerShrink(id, x, y, z, p) {
  1462. if (p == null) {
  1463. if (playerDiv[id].style.width == "13px") {
  1464. var bgc = playerDiv[id].style.backgroundColor;
  1465. playerDiv[id].parentNode.removeChild(playerDiv[id]);
  1466. playerDiv[id] = null;
  1467. createPlayerDot(id, x, y, z, p);
  1468. playerDiv[id].style.backgroundColor = bgc;
  1469. }
  1470. }
  1471. else {
  1472. if (playerDiv[id].style.width != "13px") {
  1473. var bgc = playerDiv[id].style.backgroundColor;
  1474. playerDiv[id].parentNode.removeChild(playerDiv[id]);
  1475. playerDiv[id] = null;
  1476. createPlayerDot(id, x, y, z, p);
  1477. playerDiv[id].style.backgroundColor = bgc;
  1478. }
  1479. }
  1480. }
  1481.  
  1482. function playerTrim(id, x, y, z, p) {
  1483. if (p == null) {
  1484. if (playerDiv[id].src.toString().indexOf("spacer") != -1) {
  1485. var bgc = playerDiv[id].style.backgroundColor;
  1486. playerDiv[id].parentNode.removeChild(playerDiv[id]);
  1487. playerDiv[id] = null;
  1488. createPlayerDot(id, x, y, z, p);
  1489. playerDiv[id].style.backgroundColor = bgc;
  1490. }
  1491. }
  1492. else {
  1493. if (playerDiv[id].src.toString().indexOf("spacer") == -1) {
  1494. var bgc = playerDiv[id].style.backgroundColor;
  1495. playerDiv[id].parentNode.removeChild(playerDiv[id]);
  1496. playerDiv[id] = null;
  1497. createPlayerDot(id, x, y, z, p);
  1498. playerDiv[id].style.backgroundColor = bgc;
  1499. }
  1500. }
  1501. }
  1502.  
  1503. function ff() {
  1504. //console.log("ff");
  1505. if (playPaused == true) {
  1506. var pdl = play_data.length;
  1507. currentFrame = (pdl+currentFrame+1)%pdl;
  1508. drawFrame();
  1509. }
  1510. else {
  1511. frameRate += 3;
  1512. frameSpeed = frameSpeed/2;
  1513. }
  1514. //console.log("ff: "+frameSpeed);
  1515. }
  1516.  
  1517. function rew() {
  1518. //console.log("rew");
  1519. if (playPaused == true) {
  1520. var pdl = play_data.length;
  1521. currentFrame = (pdl+currentFrame-1)%pdl;
  1522. drawFrame();
  1523. }
  1524. else {
  1525. frameRate -= 3;
  1526. frameSpeed = frameSpeed*2;
  1527. }
  1528. //console.log("rew: "+frameSpeed);
  1529. }
  1530.  
  1531. function reset() {
  1532. //console.log("reset");
  1533. playPaused = true;
  1534. currentFrame = 0;
  1535. drawFrame();
  1536. }
  1537.  
  1538. function beginPlay() {
  1539. //console.log("beginPlay is not done");
  1540. if (postPlayTimer != null) {
  1541. clearTimeout(postPlayTimer);
  1542. postPlayTimer = null;
  1543. }
  1544. if (playPaused == true) {
  1545. return;
  1546. }
  1547. resetBall();
  1548. play();
  1549. }
  1550.  
  1551. function playIsFinished() {
  1552. //console.log("pIF");
  1553. if (playFinishedTimer != null) {
  1554. clearTimeout(playFinishedTimer);
  1555. playFinishedTimer = null;
  1556. }
  1557. if (postPlayTimer != null) {
  1558. clearTimeout(postPlayTimer);
  1559. postPlayTimer = null;
  1560. }
  1561. if (playPaused == true) {
  1562. return;
  1563. }
  1564. playDone = false;
  1565. if (document.getElementById("use_continuous").checked == false) {
  1566. currentFrame = 0;
  1567. while (document.getElementById("replay_area").getElementsByClassName("player_popup_icon").length > 0) {
  1568. var e = document.getElementById("replay_area").getElementsByClassName("player_popup_icon")[0];
  1569. e.parentNode.removeChild(e);
  1570. }
  1571. beginPlay();
  1572. }
  1573. else {
  1574. var button = document.getElementsByClassName("nplaybtn")[0];
  1575. if (document.getElementById("rrplay").getAttribute("index") == button.id) {
  1576. currentFrame = 0;
  1577. beginPlay();
  1578. }
  1579. else {
  1580. var evt = [];
  1581. evt.target = button.firstChild;
  1582. input(evt);
  1583. }
  1584. }
  1585. }
  1586.  
  1587. function input(evt) {
  1588. if (postPlayTimer != null) {
  1589. clearTimeout(postPlayTimer);
  1590. postPlayTimer = null;
  1591. }
  1592.  
  1593. if (playFinishedTimer != null) {
  1594. clearTimeout(playFinishedTimer);
  1595. playFinishedTimer = null;
  1596. }
  1597.  
  1598. if (prePlayTimer != null) {
  1599. clearTimeout(prePlayTimer);
  1600. prePlayTimer = null;
  1601. }
  1602.  
  1603. if (playPaused != true) {
  1604. pauseReplay();
  1605. }
  1606.  
  1607. var id = evt.target.parentNode.getAttribute("id")+"";
  1608. lastPlay = currentPlay;
  1609. currentPlay = parseFloat(id);
  1610. document.getElementById("rrplay").setAttribute("index",currentPlay);
  1611. //console.log("lastPlay="+lastPlay+" -- currentPlay="+currentPlay);
  1612. if (currentPlay == plays.length) {
  1613. console.log("do something about last play of the game");
  1614. return;
  1615. }
  1616.  
  1617. var address = plays[currentPlay].replay+"";
  1618. if (address == "[object XPCNativeWrapper [object Text]]") {
  1619. buttonSetup(currentPlay);
  1620. handleFieldGoal(currentPlay);
  1621. }
  1622. else {
  1623. //console.log("next address = "+address);
  1624. evt.target.innerHTML = "Loading .";
  1625. httpRequest = getInetPage(address, change, evt.target);
  1626. }
  1627. }
  1628.  
  1629. function change(address, page) {
  1630. clearTimeout(frameTimer); frameTimer = null;
  1631. clearTimeout(postPlayTimer); postPlayTimer = null;
  1632. clearTimeout(prePlayTimer); prePlayTimer = null;
  1633.  
  1634. changeInfo(page);
  1635. changePlays(page);
  1636. buttonSetup(currentPlay);
  1637.  
  1638. addPlayInfo(page);
  1639.  
  1640. resetPlay();
  1641.  
  1642. var rrplay = document.getElementById("rrplay");
  1643. rrplay.value = address;
  1644.  
  1645. var evt = document.createEvent("HTMLEvents");
  1646. evt.initEvent("change", true, true);
  1647. rrplay.dispatchEvent(evt);
  1648.  
  1649. var a = document.createElement("a");
  1650. a.style.color = "white";
  1651. a.innerHTML = "Share this play";
  1652. a.href = address;
  1653.  
  1654. var cont = document.getElementById("share_play");
  1655. cont.removeChild(cont.firstChild);
  1656. for (var i=0; i<cont.firstChild.childNodes.length; i++) {
  1657. var el = cont.firstChild.childNodes[i];
  1658. if (el.href != null) {
  1659. var href = el.href.split("http://")[1];
  1660. el.href = href+address;
  1661. }
  1662. }
  1663. cont.insertBefore(a,cont.firstChild);
  1664. }
  1665.  
  1666. function changeInfo(page) {
  1667. // console.log("changeInfo : "+page.responseText);
  1668. var div = document.createElement("div");
  1669. div.innerHTML = page.responseText.slice(page.responseText.indexOf('<div id="body_container'));
  1670.  
  1671. var desc = document.getElementById("play_outcome");
  1672.  
  1673. if (alwaysShowPlayText == false) {
  1674. desc.style.visibility = "hidden";
  1675. }
  1676. var new_p = div.getElementsByClassName("play")[0];
  1677. var p = document.getElementsByClassName("play")[0];
  1678. p.innerHTML = new_p.innerHTML;
  1679.  
  1680. var timeytg = document.getElementById("time_ytg");
  1681. var new_timeytg = div.getElementsByTagName("h1")[0];
  1682. timeytg.innerHTML = new_timeytg.childNodes[1].innerHTML;
  1683.  
  1684. timeytg.previousSibling.textContent = "Q"+plays[currentPlay].quarter+" ";
  1685.  
  1686. var classes = ["ppossbtn","pplaybtn","nplaybtn","npossbtn"];
  1687. var display = ["<< Prev Poss","< Prev","Next >","Next Poss >>"];
  1688. for (var i=0; i<classes.length; i++) {
  1689. var btn = document.getElementsByClassName(classes[i])[0];
  1690. btn.innerHTML = "<span>"+display[i]+"</span>";
  1691. }
  1692.  
  1693. var offContainer = document.getElementById("offense_container");
  1694. var defContainer = document.getElementById("defense_container");
  1695. offContainer.style.visibility = "hidden";
  1696. offContainer.style.display = "none";
  1697. defContainer.style.visibility = "hidden";
  1698. defContainer.style.display = "none";
  1699.  
  1700. var containers = document.getElementsByClassName("primary_container");
  1701. var new_containers = div.getElementsByClassName("primary_container");
  1702. for (var i=0; i<new_containers.length; i++) {
  1703. containers[i].innerHTML = new_containers[i].innerHTML;
  1704. containers[i].setAttribute("style",new_containers[i].getAttribute("style"));
  1705. }
  1706.  
  1707. var containers = document.getElementsByClassName("secondary_container");
  1708. var new_containers = div.getElementsByClassName("secondary_container");
  1709. for (var i=0; i<new_containers.length; i++) {
  1710. containers[i].innerHTML = new_containers[i].innerHTML;
  1711. containers[i].setAttribute("style",new_containers[i].getAttribute("style"));
  1712. }
  1713.  
  1714. var players = document.getElementsByClassName("players");
  1715. var new_players = div.getElementsByClassName("players");
  1716. for (var i=0; i<new_players.length; i++) {
  1717. players[i].innerHTML = new_players[i].innerHTML;
  1718. }
  1719. addPlayerLinks();
  1720.  
  1721. var oscore = document.getElementById("off_score");
  1722. var dscore = document.getElementById("def_score");
  1723.  
  1724. thisScore = page.responseText.split("var this_score = ")[1];
  1725. if (thisScore != null) {
  1726. thisScore = thisScore.split(";")[0]
  1727. }
  1728. else {
  1729. thisScore = 0;
  1730. }
  1731.  
  1732. if (page.responseText.indexOf("score_update = 'D';") != -1) {
  1733. scoreUpdate = "D";
  1734. }
  1735. else {
  1736. scoreUpdate = "O";
  1737. }
  1738.  
  1739. if (parseInt(thisScore) != 0) {
  1740. if (scoreUpdate == "O") {
  1741. oscore.innerHTML = parseInt(oscore.innerHTML) - parseInt(thisScore);
  1742. }
  1743. else {
  1744. dscore.innerHTML = parseInt(dscore.innerHTML) - parseInt(thisScore);
  1745. }
  1746. }
  1747.  
  1748. oscore.style.display = "block";
  1749. oscore.style.visibility = "visible";
  1750. dscore.style.display = "block";
  1751. dscore.style.visibility = "visible";
  1752.  
  1753. offContainer.style.visibility = "visible";
  1754. offContainer.style.display = "block";
  1755. defContainer.style.visibility = "visible";
  1756. defContainer.style.display = "block";
  1757.  
  1758. var dai = document.getElementById("dai");
  1759. if (dai != null) dai.innerHTML = "";
  1760. }
  1761.  
  1762. function changePlays(page) {
  1763. var idx = page.responseText.indexOf("var players =");
  1764. if (idx != -1) {
  1765. if (playPaused == false) {
  1766. pauseReplay(); //pause everything
  1767. }
  1768. var p = page.responseText.slice(idx+"var players =".length);
  1769. p = p.slice(0,p.indexOf("var play_data"));
  1770. var pd = page.responseText.slice(page.responseText.indexOf("var play_data =")+"var play_data =".length);
  1771. pd = pd.slice(0,pd.indexOf(";"));
  1772. var pt = page.responseText.slice(page.responseText.indexOf("var ptid =")+"var ptid =".length);
  1773. pt = pt.slice(0,pt.indexOf(";"));
  1774. var newplayers = null;
  1775. var newplay_data = null;
  1776. eval("newplayers = "+p);
  1777. newplay_data = eval(pd);
  1778. eval("ptid = "+pt);
  1779.  
  1780. if (newplay_data.length == 0) {
  1781. newplay_data = [unsafeWindow.play_data[0]];
  1782. newplayers = unsafeWindow.players;
  1783. }
  1784. if (newplayers != null) unsafeWindow.players = newplayers;
  1785. if (newplay_data != null) unsafeWindow.play_data = newplay_data.slice();
  1786.  
  1787.  
  1788. if (offenseOnBottom == true) {
  1789. if (goingUp(unsafeWindow.play_data) == false) {
  1790. for (var f=0; f<unsafeWindow.play_data.length; f++) {
  1791. for (var p = 0; p < unsafeWindow.play_data[f].length; p++) {
  1792. unsafeWindow.play_data[f][p].x = 160 - unsafeWindow.play_data[f][p].x;
  1793. unsafeWindow.play_data[f][p].y = 360 - unsafeWindow.play_data[f][p].y;
  1794. if (unsafeWindow.play_data[f][p].tx != null) {
  1795. unsafeWindow.play_data[f][p].tx = 160 - unsafeWindow.play_data[f][p].tx;
  1796. unsafeWindow.play_data[f][p].ty = 360 - unsafeWindow.play_data[f][p].ty;
  1797. }
  1798. }
  1799. }
  1800. }
  1801. }
  1802.  
  1803. currentFrame = 0;
  1804. unsafeWindow.currentFrame = 0;
  1805.  
  1806. if (alwaysPause == true) {
  1807. playPaused = false;
  1808. pauseReplay();
  1809. }
  1810. else {
  1811. playPaused = false;
  1812. }
  1813. }
  1814. else {
  1815. //console.log("am I in here?");
  1816. unsafeWindow.play_data = [unsafeWindow.play_data[0]]
  1817. pauseReplay();
  1818. }
  1819. }
  1820.  
  1821. function handleFieldGoal(play) {
  1822. var p = plays[play];
  1823.  
  1824. var desc = document.getElementById("play_outcome");
  1825. desc = desc.getElementsByClassName("play")[0];
  1826. desc.innerHTML = p.play;
  1827.  
  1828. if (p.score != 0) {
  1829. var containers = document.getElementsByClassName("secondary_container");
  1830. for (var i=0; i<containers.length; i++) {
  1831. if (containers[i].firstChild.innerHTML == p.team) {
  1832. var sdiv = null;
  1833. if (i == 0) {
  1834. sdiv = document.getElementById("off_score");
  1835. }
  1836. else {
  1837. sdiv = document.getElementById("def_score");
  1838. }
  1839. sdiv.style.outlineStyle = "solid";
  1840. sdiv.style.outlineColor = "white";
  1841. sdiv.style.color = "gold";
  1842. sdiv.innerHTML = parseInt(sdiv.innerHTML) + 3;
  1843. break;
  1844. }
  1845. }
  1846. }
  1847.  
  1848. var timeytg = document.getElementById("time_ytg");
  1849. timeytg.innerHTML = p.timeRemaining+" "+p.down+" & "+p.togo+" on "+p.marker;
  1850.  
  1851. timeytg.previousSibling.textContent = "Q"+p.quarter+" ";
  1852.  
  1853. unsafeWindow.play_data = [unsafeWindow.play_data[0]];
  1854. play_data = unsafeWindow.play_data.slice();
  1855.  
  1856. playDone = true;
  1857. if (unsafeWindow.play_data[0] != null) {
  1858. playFinishedTimer = null;
  1859. pauseReplay();
  1860. playPaused = false;
  1861. resetPlay();
  1862. }
  1863. else {
  1864. alert("handleFieldGoal: uW.p_d is null");
  1865. }
  1866. }
  1867.  
  1868. function resetBall() {
  1869. var el = document.getElementById("pbrball");
  1870. if (el != null) {
  1871. var src = el.parentNode.previousSibling.previousSibling;
  1872. if (src == null) {
  1873. src = el.parentNode.nextSibling.nextSibling;
  1874. }
  1875. var img = src.childNodes[1].firstChild;
  1876. el.firstChild.style.backgroundImage = img.style.backgroundImage.toString();
  1877. el.removeAttribute("id");
  1878. }
  1879. else {
  1880. //console.log("el is null");
  1881. }
  1882. }
  1883.  
  1884. function drawBall() {
  1885. if (poss_data[currentFrame] == null) {
  1886. }
  1887. else {
  1888. if (currentFrame > 0) {
  1889. if (poss_data[currentFrame-1] == poss_data[currentFrame]) {
  1890. return;
  1891. }
  1892. }
  1893.  
  1894. resetBall();
  1895. playerId = poss_data[currentFrame];
  1896. var l = document.getElementById("pos_dot_"+playerId);
  1897. if (l != null) {
  1898. l.parentNode.id = "pbrball";
  1899. l.style.backgroundRepeat = "no-repeat";
  1900. l.style.backgroundImage = "url(\"/images/ball.gif\")";
  1901. }
  1902. }
  1903. }
  1904.  
  1905. function findPoss(idx, direction) {
  1906. var play = plays[idx];
  1907. var currTeam = play.team;
  1908.  
  1909. if (direction > 0) {
  1910. for (var i=idx+1; i<plays.length; i++) {
  1911. if (plays[i].team != currTeam) {
  1912. return i;
  1913. }
  1914. }
  1915. return idx;
  1916. }
  1917. else if (direction < 0) {
  1918. var i = idx;
  1919. //console.log("curr="+plays[i]);
  1920. for (i=i; i>0; i--) {
  1921. if (plays[i].team != currTeam) {
  1922. //console.log("prev1="+plays[i]);
  1923. break;
  1924. }
  1925. }
  1926. for (i=i-1; i>0; i--) {
  1927. if (plays[i].team == currTeam) {
  1928. //console.log("prev2="+plays[i+1]);
  1929. return i+1;
  1930. }
  1931. }
  1932. return 0;
  1933. }
  1934. return 0;
  1935. }
  1936.  
  1937. if (unsafeWindow.updateOrientation != null) {
  1938. unsafeWindow.updateOrientation = myUpdateOrientation;
  1939. }
  1940. function myUpdateOrientation() {
  1941. if (document.getElementById("orientation").value == "horizontal") {
  1942. var cnt = document.getElementsByClassName("play_container");
  1943. //do something
  1944.  
  1945. var field = document.getElementById("replay_container");
  1946. field.setAttribute("style","-moz-transform: rotate(90deg);");
  1947.  
  1948. console.log("Horizontal fields look horrible. Deal with it.");
  1949. }
  1950. else if (document.getElementById("orientation").value == "vertical") {
  1951. var field = document.getElementById("replay_container");
  1952. field.setAttribute("style","-moz-transform: rotate(0deg);");
  1953. }
  1954. else {
  1955. // alert("What a stupid fucking idea. WTF is wrong with you? Watch this instead. At least it's more interesting.");
  1956. console.log("refusing to do such a stupid thing.");
  1957. }
  1958. }
  1959.