Guest User

Untitled

a guest
Dec 11th, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 36.76 KB | None | 0 0
  1. // ==UserScript==
  2. // @name ELTP Live In Game F11 (new layout)
  3. // @version 1.2.1
  4. // @include http://*.koalabeast.com*
  5. // @include http://maptest*.newcompte.fr*
  6. // @author RonSpawnson and modified by Chuck_Finley
  7. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
  8. // @grant GM_addStyle
  9. // ==/UserScript==
  10. /*jshint multistr:true*/
  11.  
  12. if (!tagpro.group.socket) return;
  13.  
  14.  
  15. var scoreFontSize = "40px";
  16. var timerFontSize = "35px";
  17. var teamFontSize = "30px";
  18.  
  19. function waitForInitialized(fn) {
  20. if (!tagpro) {
  21. setTimeout(function() {
  22. waitForInitialized(fn);
  23. }, 10);
  24. } else {
  25. fn();
  26. }
  27. }
  28.  
  29. waitForInitialized(function() {
  30. tagpro.ready(function() {
  31. hideElements();
  32.  
  33. var redTeamScore = 0;
  34. var blueTeamScore = 0;
  35. var redTeamName = $.cookie("redTeamName");
  36. var blueTeamName = $.cookie("blueTeamName");
  37. var g1aggregateRedScore = $.cookie("g1aggregate.RedScore");
  38. var g2aggregateRedScore = $.cookie("g2aggregate.RedScore");
  39. var g1aggregateBlueScore = $.cookie("g1aggregate.BlueScore");
  40. var g2aggregateBlueScore = $.cookie("g2aggregate.BlueScore");
  41.  
  42. var halfIndicator = "http://i.imgur.com/5PiE5Vt.png";
  43. var halfIndicator2 = "http://i.imgur.com/aVKc7jA.png";
  44. var halfIndicator3 = "http://i.imgur.com/5B0hZpm.png";
  45. var halfIndicator4 = "http://i.imgur.com/stBbV9A.png";
  46. var halfIndicator5 = "http://i.imgur.com/8lThKal.png";
  47. var halfIndicator6 = "http://i.imgur.com/uUxBdWV.png";
  48. var goldenCap = "http://i.imgur.com/pDgOUvz.png";
  49. var overtime = "http://i.imgur.com/MPw9Ozj.png";
  50. var game1Indicator = "http://i.imgur.com/lkTQudy.png";
  51. var game2Indicator = "http://i.imgur.com/g4jrSHg.png";
  52. var game1_2Indicator = "http://i.imgur.com/kExyhcF.png";
  53. var game1IndicatorInverted = "http://i.imgur.com/nvKeXiO.png";
  54. var game2IndicatorInverted = "http://i.imgur.com/owjAyXQ.png";
  55. var game1_2IndicatorInverted = "http://i.imgur.com/66j6qIV.png";
  56. var game1HalfIndicator = "http://i.imgur.com/uGRiQva.png";
  57. var game2HalfIndicator = "http://i.imgur.com/an1Lonn.png";
  58. var game1_2HalfIndicator = "http://i.imgur.com/rtGAFq3.png";
  59. var scoreboardBanner = "http://i.imgur.com/tmk0Fkr.png";
  60. var scoreboardBannerInverted = "http://i.imgur.com/bZt5ozA.png";
  61.  
  62. //Canvas
  63.  
  64. var canvasWidth = 1280;
  65. var canvasHeight = 800;
  66. var canvasLeft = 180;//320//80
  67. var canvasTop = -654.5;//298.5 (bot)//-672.5 (top without halfindication)
  68.  
  69. //Scoreboard
  70.  
  71. var scoreboardWidth = 486;
  72. var scoreboardHeight = 103;
  73. var scoreboardBotPos = 20;
  74. var scoreboardLineHeight = 32;//36
  75.  
  76. var scoreboardTop = canvasTop + (canvasHeight-(scoreboardBotPos+scoreboardHeight));
  77. var scoreboardLeft = canvasLeft /*+ (0.5*canvasWidth-0.5*scoreboardWidth)*/;
  78.  
  79. //Scores
  80.  
  81. var scoreWidth = 50;
  82. var redScoreTopPos = 16;
  83. var blueScoreTopPos = 56;
  84. var redScoreLeftPos = 100;
  85. var blueScoreLeftPos = 100;
  86. var game1LeftPos= -80;
  87. var game2LeftPos= -140;
  88. var game1TopPos = 10;
  89. var game2TopPos = 10;
  90. var game1Height = 83;
  91. var game2Height = 83;
  92. var game1LineHeight = 42;
  93. var game2LineHeight = 42;
  94. var gameScoreWidth = 81;
  95. var game1HalfHeight = 112;
  96. var game2HalfHeight = 112;
  97. var game1HalfTopPos = -19;
  98. var game2HalfTopPos = -19;
  99.  
  100. var redScoreTop = scoreboardTop + redScoreTopPos;
  101. var blueScoreTop = scoreboardTop + blueScoreTopPos;
  102. var redScoreLeft = scoreboardLeft + redScoreLeftPos;
  103. var blueScoreLeft = scoreboardLeft + blueScoreLeftPos;
  104. var game1Left = scoreboardLeft + game1LeftPos;
  105. var game2Left = scoreboardLeft + game2LeftPos;
  106. var game1ScoreTop = scoreboardTop + game1TopPos;
  107. var game2ScoreTop = scoreboardTop + game2TopPos;
  108. var game1HalfScoreTop = scoreboardTop + game1HalfTopPos;
  109. var game2HalfScoreTop = scoreboardTop + game2HalfTopPos;
  110.  
  111. //Teams
  112.  
  113. var teamWidth = 340;
  114. var redTeamTopPos = 16;
  115. var blueTeamTopPos = 56;
  116. var redTeamLeftPos = 148;
  117. var blueTeamLeftPos = 148;
  118.  
  119. var redTeamTop = scoreboardTop + redTeamTopPos;
  120. var blueTeamTop = scoreboardTop + blueTeamTopPos;
  121. var redTeamLeft = scoreboardLeft + redTeamLeftPos;
  122. var blueTeamLeft = scoreboardLeft + blueTeamLeftPos;
  123.  
  124. //Timer
  125.  
  126. var timerWidth = 96;
  127. var timerTopPos = 34;
  128. var timerLeftPos = 5;
  129.  
  130. var timerTop = scoreboardTop + timerTopPos;
  131. var timerLeft = scoreboardLeft + timerLeftPos;
  132.  
  133. //Half Indicators
  134.  
  135. var indicatorWidth = 197;
  136. var indicatorHeight = 35;
  137. var indicatorTopPos = -22;
  138. var indicator1LeftPos = 52;
  139. var indicator2LeftPos = 52;
  140. var indicator3LeftPos = 52;
  141. var indicator4LeftPos = 52;
  142. var indicator5LeftPos = 52;
  143. var indicator6LeftPos = 52;
  144.  
  145. var indicatorTop = scoreboardTop + indicatorTopPos;
  146. var indicator1Left = scoreboardLeft + indicator1LeftPos;
  147. var indicator2Left = scoreboardLeft + indicator2LeftPos;
  148. var indicator3Left = scoreboardLeft + indicator3LeftPos;
  149. var indicator4Left = scoreboardLeft + indicator4LeftPos;
  150. var indicator5Left = scoreboardLeft + indicator5LeftPos;
  151. var indicator6Left = scoreboardLeft + indicator6LeftPos;
  152.  
  153.  
  154. //Score and Team Text
  155.  
  156. var redFontElement = createFontElement(0, scoreFontSize);
  157. var blueFontElement = createFontElement(0, scoreFontSize);
  158. var redTeamFontElement = createFontElement(redTeamName, teamFontSize);
  159. var blueTeamFontElement = createFontElement(blueTeamName, teamFontSize);
  160. var g1Red = createFontElement(g1aggregateRedScore, teamFontSize);
  161. var g2Red = createFontElement(g2aggregateRedScore, teamFontSize);
  162. var g1Blue = createFontElement(g1aggregateBlueScore, teamFontSize);
  163. var g2Blue = createFontElement(g2aggregateBlueScore, teamFontSize);
  164.  
  165.  
  166. var selectedHalf = "";
  167. var domain = ".koalabeast.com";
  168. //var domain = ".newcompte.fr";
  169.  
  170. GM_addStyle(
  171. 'body {margin-bottom: 0px;}' +
  172. 'a#exit{position:fixed; top:0px;}'
  173. );
  174.  
  175. var element = document.getElementById("loadingMessage");
  176. var newElement = '<div id="scoreboardBannerInvertedOT" style="position:absolute; left:'+ scoreboardLeft + 'px; top:'+ scoreboardTop + 'px;"> \
  177. <img src="'+ scoreboardBannerInverted + '" \> \
  178. </div> \
  179. <div id="scoreboardBannerInverted" style="position:absolute; left:'+ scoreboardLeft + 'px; top:'+ scoreboardTop + 'px;"> \
  180. <img src="'+ scoreboardBannerInverted + '" \> \
  181. </div> \
  182. <div id="scoreboardBanner" style="position:absolute; left:'+ scoreboardLeft + 'px; top:'+ scoreboardTop + 'px;"> \
  183. <img src="'+ scoreboardBanner + '" \> \
  184. </div> \
  185. <div id="redScore" style="position:absolute; top:'+ redScoreTop + 'px; left:'+ redScoreLeft + 'px; width:'+ scoreWidth + 'px; height:'+ scoreboardLineHeight + 'px; line-height:'+ scoreboardLineHeight + 'px"> \
  186. ' + redFontElement + ' \
  187. </div> \
  188. <div id="blueScore" style="position:absolute; top:'+ blueScoreTop + 'px; left:'+ blueScoreLeft + 'px; width:'+ scoreWidth + 'px; height:'+ scoreboardLineHeight + 'px; line-height:'+ scoreboardLineHeight + 'px"> \
  189. ' + blueFontElement + ' \
  190. </div> \
  191. <div id="redTeam" style="position:absolute; top:'+ redTeamTop + 'px; left:'+ redTeamLeft + 'px; width:'+ teamWidth + 'px; height:'+ scoreboardLineHeight + 'px; line-height:'+ scoreboardLineHeight + 'px;"> \
  192. ' + redTeamFontElement + ' \
  193. </div> \
  194. <div id="blueTeam" style="position:absolute; top:'+ blueTeamTop + 'px; left:'+ blueTeamLeft + 'px; width:'+ teamWidth + 'px; height:'+ scoreboardLineHeight + 'px; line-height:'+ scoreboardLineHeight + 'px"> \
  195. ' + blueTeamFontElement + ' \
  196. </div> \
  197. <div id="timer" style="position:absolute; top:'+ timerTop + 'px; left:'+ timerLeft + 'px; width:' + timerWidth + 'px; height:' + scoreboardLineHeight + 'px; line-height:' + scoreboardLineHeight + 'px"> \
  198. 12:00 \
  199. </div> \
  200. <div id="gameScoresHalf3" style="display:none; position:absolute; top:'+ game1HalfScoreTop + 'px; left:'+ game1Left + 'px; width:' + gameScoreWidth + 'px; height:' + game1HalfHeight + 'px; line-height:' + game1LineHeight + 'px; background-image: url(' + game1HalfIndicator + ')"> \
  201. </div> \
  202. <div id="gameScoresHalf4" style="display:none; position:absolute; top:'+ game2HalfScoreTop + 'px; left:'+ game2Left + 'px; width:' + gameScoreWidth + 'px; height:' + game2HalfHeight + 'px; line-height:' + game2LineHeight + 'px; background-image: url(' + game1_2HalfIndicator + ')"> \
  203. </div> \
  204. <div id="gameScoresHalf5" style="display:none; position:absolute; top:'+ game1HalfScoreTop + 'px; left:'+ game1Left + 'px; width:' + gameScoreWidth + 'px; height:' + game1HalfHeight + 'px; line-height:' + game1LineHeight + 'px; background-image: url(' + game2HalfIndicator + ')"> \
  205. </div> \
  206. <div id="gameScores3Invert" style="display:none; position:absolute; top:'+ game1ScoreTop + 'px; left:'+ game1Left + 'px; width:' + gameScoreWidth + 'px; height:' + game1Height + 'px; line-height:' + game1LineHeight + 'px; background-image: url(' + game1Indicator + ')"> \
  207. '+ g1Blue + g1Red + ' \
  208. </div> \
  209. <div id="gameScores3" style="display:none; position:absolute; top:'+ game1ScoreTop + 'px; left:'+ game1Left + 'px; width:' + gameScoreWidth + 'px; height:' + game1Height + 'px; line-height:' + game1LineHeight + 'px; background-image: url(' + game1Indicator + ')"> \
  210. '+ g1Red + g1Blue + ' \
  211. </div> \
  212. <div id="gameScores4Invert" style="display:none; position:absolute; top:'+ game2ScoreTop + 'px; left:'+ game2Left + 'px; width:' + gameScoreWidth + 'px; height:' + game2Height + 'px; line-height:' + game2LineHeight + 'px; background-image: url(' + game1_2Indicator + ')"> \
  213. '+ g1Blue + g1Red + ' \
  214. </div> \
  215. <div id="gameScores4" style="display:none; position:absolute; top:'+ game2ScoreTop + 'px; left:'+ game2Left + 'px; width:' + gameScoreWidth + 'px; height:' + game2Height + 'px; line-height:' + game2LineHeight + 'px; background-image: url(' + game1_2Indicator + ')"> \
  216. ' + g1Red + g1Blue + ' \
  217. </div> \
  218. <div id="gameScores5Invert" style="display:none; position:absolute; top:'+ game1ScoreTop + 'px; left:'+ game1Left + 'px; width:' + gameScoreWidth + 'px; height:' + game1Height + 'px; line-height:' + game1LineHeight + 'px; background-image: url(' + game2Indicator + ')"> \
  219. '+ g2Blue + g2Red + ' \
  220. </div> \
  221. <div id="gameScores5" style="display:none; position:absolute; top:'+ game1ScoreTop + 'px; left:'+ game1Left + 'px; width:' + gameScoreWidth + 'px; height:' + game1Height + 'px; line-height:' + game1LineHeight + 'px; background-image: url(' + game2Indicator + ')"> \
  222. ' + g2Red + g2Blue + ' \
  223. </div> \
  224. <div id="halfIndicator1" style="display:none; position:absolute; top:'+ indicatorTop + 'px; left:'+ indicator1Left + 'px; width:' + indicatorWidth + 'px; height:' + indicatorHeight + 'px; background-image: url(' + halfIndicator + ')"> \
  225. </div> \
  226. <div id="halfIndicator2" style="display:none; position:absolute; top:'+ indicatorTop + 'px; left:'+ indicator2Left + 'px; width:' + indicatorWidth + 'px; height:' + indicatorHeight + 'px; background-image: url(' + halfIndicator2 + ')"> \
  227. </div> \
  228. <div id="halfIndicator3" style="display:none; position:absolute; top:'+ indicatorTop + 'px; left:'+ indicator3Left + 'px; width:' + indicatorWidth + 'px; height:' + indicatorHeight + 'px; background-image: url(' + halfIndicator3 + ')"> \
  229. </div> \
  230. <div id="halfIndicator4" style="display:none; position:absolute; top:'+ indicatorTop + 'px; left:'+ indicator4Left + 'px; width:' + indicatorWidth + 'px; height:' + indicatorHeight + 'px; background-image: url(' + halfIndicator4 + ')"> \
  231. </div> \
  232. <div id="halfIndicator5" style="display:none; position:absolute; top:'+ indicatorTop + 'px; left:'+ indicator5Left + 'px; width:' + indicatorWidth + 'px; height:' + indicatorHeight + 'px; background-image: url(' + halfIndicator5 + ')"> \
  233. </div> \
  234. <div id="halfIndicator6" style="display:none; position:absolute; top:'+ indicatorTop + 'px; left:'+ indicator6Left + 'px; width:' + indicatorWidth + 'px; height:' + indicatorHeight + 'px; background-image: url(' + halfIndicator6 + ')"> \
  235. </div> \
  236. <div id="halfIndicator7" style="display:none; position:absolute; top:'+ indicatorTop + 'px; left:'+ indicator6Left + 'px; width:' + indicatorWidth + 'px; height:' + indicatorHeight + 'px; background-image: url(' + overtime + ')"> \
  237. </div> \
  238. <div id="halfIndicator8" style="display:none; position:absolute; top:'+ indicatorTop + 'px; left:'+ indicator6Left + 'px; width:' + indicatorWidth + 'px; height:' + indicatorHeight + 'px; background-image: url(' + goldenCap + ')"> \
  239. </div>';
  240. element.insertAdjacentHTML('afterend', newElement);
  241.  
  242. //element = document.getElementsByTagName('head');
  243. //newElement = "<link href='http://fonts.googleapis.com/css?family=//Play' rel='stylesheet' type='text/css'>";
  244. //element[0].insertAdjacentHTML('afterend', newElement);
  245.  
  246. addHalfSelection();
  247. createFirstHalfOffsetSection();
  248. setupFirstHalfOffsetOverrideListeners();
  249. createTimeoutOffsetSection();
  250. createTeamNameSwitchButton();
  251. setupTimeoutOffsetOverrideListeners();
  252. setupOnScoreFunction();
  253.  
  254. // update timer text
  255. requestAnimationFrame(function updateTimerText() {
  256. requestAnimationFrame(updateTimerText);
  257. updateTimer();
  258. });
  259. //hide UI Flags
  260. setTimeout(function() {
  261. tagpro.ui.sprites.redFlag.alpha = 0;
  262. tagpro.ui.sprites.blueFlag.alpha = 0;
  263. tagpro.ui.sprites.yellowFlagTakenByRed.alpha = 0;
  264. tagpro.ui.sprites.yellowFlagTakenByBlue.alpha = 0;
  265. }, 1000);
  266.  
  267. function hideSpectatorInfo1() {
  268. if (tagpro.ui.sprites.spectatorInfo1 !== undefined) {
  269. setTimeout(function() {tagpro.ui.sprites.spectatorInfo1.visible = false;}, 0);
  270. } else {
  271. setTimeout(hideSpectatorInfo1, 200);
  272. }
  273. }
  274. function hideSpectatorInfo2() {
  275. if (tagpro.ui.sprites.spectatorInfo2 !== undefined) {
  276. setTimeout(function() {tagpro.ui.sprites.spectatorInfo2.visible = false;}, 0);
  277. } else {
  278. setTimeout(hideSpectatorInfo2, 200);
  279. }
  280. }
  281. function hideRedScore() {
  282. if (tagpro.ui.sprites.redScore !== undefined) {
  283. setTimeout(function() {tagpro.ui.sprites.redScore.visible = false;}, 0);
  284. } else {
  285. setTimeout(hideRedScore, 200);
  286. }
  287. }
  288. function hideBlueScore() {
  289. if (tagpro.ui.sprites.blueScore !== undefined) {
  290. setTimeout(function() {tagpro.ui.sprites.blueScore.visible = false;}, 0);
  291. } else {
  292. setTimeout(hideBlueScore, 200);
  293. }
  294. }
  295. function hideChat() {
  296. document.getElementById("chatHistory").style.display = "all";
  297. }
  298. function hideTimer() {
  299. if (tagpro.ui.sprites.timer !== undefined) {
  300. setTimeout(function() {tagpro.ui.sprites.timer.visible = false;}, 0);
  301. } else {
  302. setTimeout(hideTimer, 200);
  303. }
  304. }
  305. function hideElements() {
  306. hideSpectatorInfo1();
  307. hideSpectatorInfo2();
  308. hideRedScore();
  309. hideBlueScore();
  310. hideChat();
  311. hideTimer();
  312. }
  313.  
  314. function createFontElement(num, size) {
  315. return '<div style="text-align:center; font-weight:normal; color:white; font-family:\'Play\'; font-size:' + size + ';text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;">' + num + '</div>';
  316. }
  317.  
  318. function setupOnScoreFunction() {
  319. tagpro.socket.on('score', function(score) {
  320. console.log(score);
  321. updateScores(score);
  322. });
  323. }
  324.  
  325. function updateScores(score) {
  326. var redFirstHalfOffset = $("#firstHalfRedOffset").val();
  327. var blueFirstHalfOffset = $("#firstHalfBlueOffset").val();
  328.  
  329. var redTimeoutOffset = $("#redTimeoutOffset").val();
  330. var blueTimeoutOffset = $("#blueTimeoutOffset").val();
  331.  
  332. console.log("1: ");
  333. console.log(score);
  334.  
  335. document.getElementById("redScore").innerHTML = createFontElement(parseInt(score.r) + parseInt(redFirstHalfOffset) + parseInt(redTimeoutOffset), scoreFontSize);
  336. document.getElementById("blueScore").innerHTML = createFontElement(parseInt(score.b) + parseInt(blueFirstHalfOffset) + parseInt(blueTimeoutOffset), scoreFontSize);
  337.  
  338. // add new cookie
  339. var options = {
  340. domain: domain,
  341. path: '/'
  342. };
  343.  
  344. $.cookie(selectedHalf + ".RedScore", parseInt(score.r) + parseInt(redTimeoutOffset), options);
  345. $.cookie(selectedHalf + ".BlueScore", parseInt(score.b) + parseInt(blueTimeoutOffset), options);
  346. }
  347.  
  348. function fillInHalfIndicators(num) {
  349. var html = "";
  350. for (var i = 1; i <= 8; i++) {
  351. if (num >= i) {
  352. document.getElementById("halfIndicator" + i).style.display = "block";
  353. } else {
  354. document.getElementById("halfIndicator" + i).style.display = "none";
  355. }
  356. }
  357. }
  358.  
  359. function updateTimer() {
  360. document.getElementById("timer").innerHTML = createFontElement(getTime(), timerFontSize);
  361. }
  362.  
  363. function getTime() {
  364. var millis = Math.max(0, tagpro.gameEndsAt - Date.now());
  365. var min = (millis/1000/60) << 0;
  366. var sec = fixSeconds(((millis/1000) % 60 << 0));
  367. return min + ":" + sec;
  368. }
  369.  
  370. function addHalfSelection() {
  371. var element = document.getElementById("assets");
  372. var newElement = '<div id="halfSelection" style="margin-top:-18px; font-family: arial; font-size: 14px; color: black; margin-left:800px;"> \
  373. <button type="button" id="g1h1" sequence="1" class="halfSelection hideGameScores" style="margin-left:10px; margin-bottom:10px">g1h1</button> \
  374. <button type="button" id="g1h2" sequence="2" class="halfSelection hideGameScores" style="margin-left:10px; margin-bottom:10px">g1h2</button> \
  375. <button type="button" id="g2h1" sequence="3" class="halfSelection game1Scores" style="margin-left:10px; margin-bottom:10px">g2h1</button> \
  376. <button type="button" id="g2h2" sequence="4" class="halfSelection game1Scores" style="margin-left:10px; margin-bottom:10px">g2h2</button> \
  377. <button type="button" id="g3h1" sequence="5" class="halfSelection game2Scores" style="margin-left:10px; margin-bottom:10px">g3h1</button> \
  378. <button type="button" id="g3h2" sequence="6" class="halfSelection game2Scores" style="margin-left:10px; margin-bottom:10px">g3h2</button> \
  379. <button type="button" id="overtime" sequence="7" class="overtimeAndGoldenCap" style="margin-left:10px; margin-bottom:10px; width:85px">Overtime</button> \
  380. <button type="button" id="goldenCap" sequence="8" class="overtimeAndGoldenCap" style="margin-left:10px; margin-bottom:10px">Golden Cap</button> \
  381. </div><div id="message"><p style="font-size:23px;margin-left:1690px;margin-top:-33px;color:red">SELECT A HALF<p></div>';
  382. element.insertAdjacentHTML( 'afterend', newElement );
  383.  
  384. // Add event listeners
  385. $(".halfSelection").each(function(index) {
  386. $(this).on("click", function(){
  387.  
  388. var buttonId = $(this).attr('id');
  389. var sequence = $(this).attr('sequence');
  390.  
  391. selectedHalf = buttonId;
  392.  
  393. console.log("button id: " + selectedHalf);
  394. document.getElementById("message").innerHTML = '<p style="font-size:23px;margin-left:1690px;margin-top:-33px;color:green">' + selectedHalf + ' selected<p>';
  395. loadFirstHalfOffset(selectedHalf);
  396. fillInTeamNames(selectedHalf);
  397. //invertscoreboardBanner(selectedHalf);
  398. fillInHalfIndicators(sequence);
  399. });
  400. });
  401. $(".hideGameScores").each(function(index) {
  402. $(this).on("click", function(){
  403.  
  404. var buttonId = $(this).attr('id');
  405. var sequence = $(this).attr('sequence');
  406.  
  407. selectedHalf = buttonId;
  408.  
  409. hideGameBanner(selectedHalf);
  410.  
  411. });
  412. });
  413. $(".game1Scores").each(function(index) {
  414. $(this).on("click", function(){
  415.  
  416. var buttonId = $(this).attr('id');
  417. var sequence = $(this).attr('sequence');
  418.  
  419. selectedHalf = buttonId;
  420.  
  421. showGame1Banner(selectedHalf);
  422.  
  423. });
  424. });
  425. $(".game2Scores").each(function(index) {
  426. $(this).on("click", function(){
  427.  
  428. var buttonId = $(this).attr('id');
  429. var sequence = $(this).attr('sequence');
  430.  
  431. selectedHalf = buttonId;
  432.  
  433. showGame2Banner(selectedHalf);
  434.  
  435. });
  436. });
  437. $(".overtimeAndGoldenCap").each(function(index) {
  438. $(this).on("click", function(){
  439.  
  440. var buttonId = $(this).attr('id');
  441. var sequence = $(this).attr('sequence');
  442.  
  443. selectedHalf = buttonId;
  444.  
  445. console.log("button id: " + selectedHalf);
  446. fillInHalfIndicators(sequence);
  447. });
  448. });
  449. }
  450.  
  451. function fillInTeamNames() {
  452. var invert = $.cookie(selectedHalf + "Inversion");
  453. if (invert == "true") {
  454. $("#blueTeam").html(createFontElement(redTeamName, teamFontSize));
  455. $("#redTeam").html(createFontElement(blueTeamName, teamFontSize));
  456. } else {
  457. $("#redTeam").html(createFontElement(redTeamName, teamFontSize));
  458. $("#blueTeam").html(createFontElement(blueTeamName, teamFontSize));
  459. }
  460. }
  461. /*function invertscoreboardBanner() {
  462. var invert = $.cookie(selectedHalf + "Inversion");
  463. if (invert == "true") {
  464. $("#scoreboardBannerInverted").show();
  465. $("#scoreboardBanner").hide();
  466. } else {
  467. $("#scoreboardBanner").show();
  468. $("#scoreboardBannerInverted").hide();
  469. }
  470. }*/
  471. function hideGameBanner() {
  472. $("#gameScores3").hide();
  473. $("#gameScores4").hide();
  474. $("#gameScores5").hide();
  475. $("#gameScoresHalf3").hide();
  476. $("#gameScoresHalf4").hide();
  477. $("#gameScoresHalf5").hide();
  478. $("#gameScores3Invert").hide();
  479. $("#gameScores4Invert").hide();
  480. $("#gameScores5Invert").hide();
  481. }
  482. function showGame1Banner() {
  483. var invert = $.cookie(selectedHalf + "Inversion");
  484. if (invert == "true") {
  485. $("#gameScores3").hide();
  486. $("#gameScores4").hide();
  487. $("#gameScores5").hide();
  488. $("#gameScoresHalf3").show();
  489. $("#gameScoresHalf4").hide();
  490. $("#gameScoresHalf5").hide();
  491. $("#gameScores3Invert").show();
  492. $("#gameScores4Invert").hide();
  493. $("#gameScores5Invert").hide();
  494. } else {
  495. $("#gameScores3").show();
  496. $("#gameScores4").hide();
  497. $("#gameScores5").hide();
  498. $("#gameScoresHalf3").show();
  499. $("#gameScoresHalf4").hide();
  500. $("#gameScoresHalf5").hide();
  501. $("#gameScores3Invert").hide();
  502. $("#gameScores4Invert").hide();
  503. $("#gameScores5Invert").hide();
  504. }
  505. }
  506. function showGame2Banner() {
  507. var invert = $.cookie(selectedHalf + "Inversion");
  508. if (invert == "true") {
  509. $("#gameScores3").hide();
  510. $("#gameScores4").hide();
  511. $("#gameScores5").hide();
  512. $("#gameScoresHalf3").hide();
  513. $("#gameScoresHalf4").show();
  514. $("#gameScoresHalf5").show();
  515. $("#gameScores3Invert").show();
  516. $("#gameScores4Invert").show();
  517. $("#gameScores5Invert").show();
  518. } else {
  519. $("#gameScores3").show();
  520. $("#gameScores4").show();
  521. $("#gameScores5").show();
  522. $("#gameScoresHalf3").hide();
  523. $("#gameScoresHalf4").show();
  524. $("#gameScoresHalf5").show();
  525. $("#gameScores3Invert").hide();
  526. $("#gameScores4Invert").hide();
  527. $("#gameScores5Invert").hide();
  528. }
  529. }
  530. function fixSeconds(seconds) {
  531. if (seconds < 10) {
  532. seconds = "0" + seconds;
  533. }
  534. return seconds;
  535. }
  536.  
  537.  
  538. function createFirstHalfOffsetSection() {
  539. var element = document.getElementById("assets");
  540. var newElement = createFirstHalfOffsetElement(0,0);
  541. element.insertAdjacentHTML( 'afterend', newElement );
  542. }
  543.  
  544. function createFirstHalfOffsetElement(redOffset, blueOffset) {
  545. return '<div id="firstHalfOffset" style="margin-left:0px; margin-top:1025px;font-family: arial; font-size: 14px;> \
  546. <label for="firstHalfRedOffset">First Half Red Offset: </label><input id="firstHalfRedOffset" class="firstHalfOffsetOverride" name="firstHalfRedOffset" style="width:40px; margin-left:2px; color: black; " value="' + redOffset + '"/> \
  547. <label for="firstHalfBlueOffset">First Half Blue Offset: </label><input id="firstHalfBlueOffset" class="firstHalfOffsetOverride" name="firstHalfBlueOffset" style="width:40px; color: black; " value="' + blueOffset + '"/> \
  548. </div>';
  549. }
  550.  
  551. function loadFirstHalfOffset(selectedHalf) {
  552. // Only load offset if in half 2
  553. if (selectedHalf.slice(-1) == "2") {
  554. var originalHalf = selectedHalf.slice(0, -1) + "1";
  555. var redOffset = 0;
  556. var blueOffset = 0;
  557.  
  558. console.log($.cookie(originalHalf + "Inversion"));
  559. console.log($.cookie(selectedHalf + "Inversion"));
  560. var invert = $.cookie(originalHalf + "Inversion") != $.cookie(selectedHalf + "Inversion");
  561.  
  562. if ($.cookie(originalHalf + "." + invertTeamIfApplicable(invert, "Red") + "Score") !== undefined) {
  563. redOffset = $.cookie(originalHalf + "." + invertTeamIfApplicable(invert, "Red") + "Score");
  564. }
  565. if ($.cookie(originalHalf + "." + invertTeamIfApplicable(invert, "Blue") + "Score") !== undefined) {
  566. blueOffset = $.cookie(originalHalf + "." + invertTeamIfApplicable(invert, "Blue") + "Score");
  567. }
  568.  
  569. // Update html and trigger score update
  570. $("#firstHalfOffset").html(createFirstHalfOffsetElement(redOffset, blueOffset));
  571.  
  572. setupFirstHalfOffsetOverrideListeners();
  573. updateScores(tagpro.score);
  574. }
  575. }
  576.  
  577. function setupFirstHalfOffsetOverrideListeners() {
  578. $(".firstHalfOffsetOverride").change(overrideFirstHalfOffset);
  579. }
  580.  
  581. function overrideFirstHalfOffset(obj) {
  582. updateScores(tagpro.score);
  583. }
  584.  
  585. function createTimeoutOffsetSection() {
  586. var element = document.getElementById("firstHalfOffset");
  587. var newElement = createTimeoutOffsetElement(0,0);
  588. element.insertAdjacentHTML('afterend', newElement );
  589. }
  590.  
  591. function createTimeoutOffsetElement(redOffset, blueOffset) {
  592. return '<div id="timeoutOffset" style="margin-left:400px; margin-top:-24px;font-family: arial; font-size: 14px; "> \
  593. <label for="redTimeoutOffset">Red Timeout Offset: </label><input id="redTimeoutOffset" class="timeoutOffset" name="redTimeoutOffset" style="width:40px; margin-left:2px; color: black; " value="' + redOffset + '"/> \
  594. <label for="blueTimeoutOffset">Blue Timeout Offset: </label><input id="blueTimeoutOffset" class="timeoutOffset" name="blueTimeoutOffset" style="width:40px; color: black; " value="' + blueOffset + '"/> \
  595. </div>';
  596. }
  597.  
  598. function setupTimeoutOffsetOverrideListeners() {
  599. $(".timeoutOffset").change(overrideTimeoutOffset);
  600. }
  601.  
  602. function overrideTimeoutOffset(obj) {
  603. updateScores(tagpro.score);
  604. }
  605. function createScoreObject(redScore, blueScore) {
  606. console.log("redScore = " + redScore);
  607. return "{r: " + redScore + ", b:" + blueScore + "}";
  608. }
  609.  
  610. function createTeamNameSwitchButton() {
  611. var element = document.getElementById("timeoutOffset");
  612. var newElement = "<div id='teamSwitchButtons' style='margin-left:1382px; margin-top:-24px; padding-bottom:00px;font-family: arial; font-size: 14px; color: black; '> \
  613. <button id='teamSwitchButtonG1' type='button'>Switch Team Names (OT Only)</button> \</div>";
  614. element.insertAdjacentHTML('afterend', newElement );
  615. document.getElementById ("teamSwitchButtonG1").addEventListener ("click", switchTeamNamesG1, false);
  616. //document.getElementById ("teamSwitchButtonG2").addEventListener ("click", switchTeamNamesG2, false);
  617. //document.getElementById ("teamSwitchButtonG3").addEventListener ("click", switchTeamNamesG3, false);
  618. }
  619. function switchTeamNamesG1() {
  620. var blueTeamHTML = $("#blueTeam").html();
  621. var redTeamHTML = $("#redTeam").html();
  622. //var bannerInverted = $("#scoreboardBannerInverted").toggle();
  623. //var banner = $("#scoreboardBanner").toggle();
  624.  
  625. //$("#scoreboardBanner").toggle(bannerInverted);
  626. //$("#scoreboardBannerInverted").toggle(banner);
  627. $("#blueTeam").html(redTeamHTML);
  628. $("#redTeam").html(blueTeamHTML);
  629.  
  630. }
  631. /*function switchTeamNamesG2() {
  632. var blueTeamHTML = $("#blueTeam").html();
  633. var redTeamHTML = $("#redTeam").html();
  634. var bannerInverted = $("#scoreboardBannerInverted").toggle();
  635. var banner = $("#scoreboardBanner").toggle();
  636. var gs3 = $("#gameScores3").toggle();
  637. var gs3i = $("#gameScores3Invert").toggle();
  638.  
  639. $("#scoreboardBanner").toggle(bannerInverted);
  640. $("#scoreboardBannerInverted").toggle(banner);
  641. $("#gameScores3").toggle(gs3i);
  642. $("#gameScores3Invert").toggle(gs3);
  643. $("#blueTeam").html(redTeamHTML);
  644. $("#redTeam").html(blueTeamHTML);
  645.  
  646. }
  647. function switchTeamNamesG3() {
  648. var blueTeamHTML = $("#blueTeam").html();
  649. var redTeamHTML = $("#redTeam").html();
  650. var bannerInverted = $("#scoreboardBannerInverted").toggle();
  651. var banner = $("#scoreboardBanner").toggle();
  652. var gs3 = $("#gameScores3").toggle();
  653. var gs4 = $("#gameScores4").toggle();
  654. var gs5 = $("#gameScores5").toggle();
  655. var gs3i = $("#gameScores3Invert").toggle();
  656. var gs4i = $("#gameScores4Invert").toggle();
  657. var gs5i = $("#gameScores5Invert").toggle();
  658.  
  659. $("#scoreboardBanner").toggle(bannerInverted);
  660. $("#scoreboardBannerInverted").toggle(banner);
  661. $("#gameScores3").toggle(gs3i);
  662. $("#gameScores4").toggle(gs4i);
  663. $("#gameScores5").toggle(gs5i);
  664. $("#gameScores3Invert").toggle(gs3);
  665. $("#gameScores4Invert").toggle(gs4);
  666. $("#gameScores5Invert").toggle(gs5);
  667. $("#blueTeam").html(redTeamHTML);
  668. $("#redTeam").html(blueTeamHTML);
  669.  
  670. }*/
  671.  
  672. function invertTeamIfApplicable(invert, color) {
  673. if (invert) {
  674. if (color == "Red") {
  675. return "Blue";
  676. } else {
  677. return "Red";
  678. }
  679. } else {
  680. return color;
  681. }
  682. }
  683. });
  684.  
  685. //////////////////////////////////
  686. // JQUERY COOKIE PLUGIN FOLLOWS //
  687. //////////////////////////////////
  688.  
  689. (function (factory) {
  690. if (typeof define === 'function' && define.amd) {
  691. // AMD (Register as an anonymous module)
  692. define(['jquery'], factory);
  693. } else if (typeof exports === 'object') {
  694. // Node/CommonJS
  695. module.exports = factory(require('jquery'));
  696. } else {
  697. // Browser globals
  698. factory(jQuery);
  699. }
  700. }(function ($) {
  701.  
  702. var pluses = /\+/g;
  703.  
  704. function encode(s) {
  705. return config.raw ? s : encodeURIComponent(s);
  706. }
  707.  
  708. function decode(s) {
  709. return config.raw ? s : decodeURIComponent(s);
  710. }
  711.  
  712. function stringifyCookieValue(value) {
  713. return encode(config.json ? JSON.stringify(value) : String(value));
  714. }
  715.  
  716. function parseCookieValue(s) {
  717. if (s.indexOf('"') === 0) {
  718. // This is a quoted cookie as according to RFC2068, unescape...
  719. s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
  720. }
  721.  
  722. try {
  723. // Replace server-side written pluses with spaces.
  724. // If we can't decode the cookie, ignore it, it's unusable.
  725. // If we can't parse the cookie, ignore it, it's unusable.
  726. s = decodeURIComponent(s.replace(pluses, ' '));
  727. return config.json ? JSON.parse(s) : s;
  728. } catch(e) {}
  729. }
  730.  
  731. function read(s, converter) {
  732. var value = config.raw ? s : parseCookieValue(s);
  733. return $.isFunction(converter) ? converter(value) : value;
  734. }
  735.  
  736. var config = $.cookie = function (key, value, options) {
  737.  
  738. // Write
  739.  
  740. if (arguments.length > 1 && !$.isFunction(value)) {
  741. options = $.extend({}, config.defaults, options);
  742.  
  743. if (typeof options.expires === 'number') {
  744. var days = options.expires, t = options.expires = new Date();
  745. t.setMilliseconds(t.getMilliseconds() + days * 864e+5);
  746. }
  747.  
  748. return (document.cookie = [
  749. encode(key), '=', stringifyCookieValue(value),
  750. options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
  751. options.path ? '; path=' + options.path : '',
  752. options.domain ? '; domain=' + options.domain : '',
  753. options.secure ? '; secure' : ''
  754. ].join(''));
  755. }
  756.  
  757. // Read
  758.  
  759. var result = key ? undefined : {},
  760. // To prevent the for loop in the first place assign an empty array
  761. // in case there are no cookies at all. Also prevents odd result when
  762. // calling $.cookie().
  763. cookies = document.cookie ? document.cookie.split('; ') : [],
  764. i = 0,
  765. l = cookies.length;
  766.  
  767. for (; i < l; i++) {
  768. var parts = cookies[i].split('='),
  769. name = decode(parts.shift()),
  770. cookie = parts.join('=');
  771.  
  772. if (key === name) {
  773. // If second argument (value) is a function it's a converter...
  774. result = read(cookie, value);
  775. break;
  776. }
  777.  
  778. // Prevent storing a cookie that we couldn't decode.
  779. if (!key && (cookie = read(cookie)) !== undefined) {
  780. result[name] = cookie;
  781. }
  782. }
  783.  
  784. return result;
  785. };
  786.  
  787. config.defaults = {};
  788.  
  789. $.removeCookie = function (key, options) {
  790. // Must not alter options, thus extending a fresh object...
  791. $.cookie(key, '', $.extend({}, options, { expires: -1 }));
  792. return !$.cookie(key);
  793. };
  794.  
  795. }));
  796.  
  797. });
Add Comment
Please, Sign In to add comment