Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name ELTP Live Boxscore (new layout)
- // @version 1.2
- // @include http://*.koalabeast.com/groups/*
- // @include http://*.jukejuice.com/groups/*
- // @include http://*.newcompte.*/groups/*
- // @author RonSpawnson and modified by Chuck_Finley
- // @grant GM_addStyle
- // @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
- // ==/UserScript==
- /*jshint multistr: true */
- var redHalfScoreBackgroundLoc = "http://i.imgur.com/eJRCXTo.png";
- //var redAggregateScoreBackgroundLoc = "http://i.imgur.com/ZgYryxg.png"; //GREEN
- //var redAggregateScoreBackgroundLoc = "http://i.imgur.com/YQbcwL2.png"; //ORANGE
- var redAggregateScoreBackgroundLoc = "http://i.imgur.com/eJQNO3U.png"; //RED
- //var redAggregateScoreBackgroundLoc = "http://i.imgur.com/lFB87vJ.png";//BLUE
- var blueHalfScoreBackgroundLoc = "http://i.imgur.com/eJRCXTo.png";
- var blueAggregateScoreBackgroundLoc = "http://i.imgur.com/lFB87vJ.png"; //BLUE
- //var blueAggregateScoreBackgroundLoc = "http://imgur.com/O9IDRyp.png"; //BLACK
- var redAggregateScoreBgLoc = "http://i.imgur.com/LbvoXUR.png";
- var blueAggregateScoreBgLoc = "http://i.imgur.com/LbvoXUR.png";
- var boxscoreFontSize = "86px";
- var boxscoreTeamFontSize = "70px";
- var domain = ".koalabeast.com";
- //var domain = ".newcompte.fr";
- // Insert google font
- //element = document.getElementsByTagName('head');
- //newElement = "<link href='http://fonts.googleapis.com/css?family=//Play' rel='stylesheet' type='text/css'>";
- //element[0].insertAdjacentHTML('afterend', newElement);
- //Modifies group page to fit scoreboard
- GM_addStyle(
- '.header {padding-top: 0px}' +
- '.container header-main .header-top {display: none}' +
- '.header-top {display: none}' +
- '.header-title {display: none}' +
- '.group .group-exit {margin-top: 0; margin-left: 4px;}' +
- '#group { width:auto; height: 646px; overflow-y: auto;}' +
- 'body {margin-bottom: 0px;}' +
- '#header {margin-bottom: 0px;}' +
- '#red-team {width:50%;}' +
- '#blue-team {width:50%;}' +
- '#spectators {width:100%;}' +
- '#waiting {width:100%;}' +
- '.col-md-7 {width:33%;}' +
- '.col-md-5 {width:33%;}' +
- '#private-settings {position: absolute; left: 100%; width: 100%; top:-380px}'+
- '.chat-log {height: 330px !important}' +
- '.footer {display:none}' +
- '.group .player-options {display: none}' +
- '.group .player-options.open {display: inherit}'
- );
- jQuery(".group .group-exit").detach().prependTo('.group .group-settings');
- initJqueryCookiePlugin();
- createContainer();
- createTeamEntrySection();
- setupTeamEntryEventListeners();
- createTeamInversionSection();
- createBoxscoreSection();
- loadInversions();
- saveInversions();
- loadBoxscores();
- setupBoxscoreEventListeners();
- function createContainer() {
- var element = document.getElementById("group");
- var newElement = '<div id="boxscoreOutline" style="display:block;position:;left:0px;top:0px;width:1900px;border:0px solid rgba(255,255,255,0.20)"></div>';
- element.insertAdjacentHTML( 'afterend', newElement );
- element = document.getElementById("boxscoreOutline");
- newElement = '<div id="boxscoreContainer" style="margin-left:10px;margin-top:12px"></div>';
- element.insertAdjacentHTML( 'beforeend', newElement );
- }
- function createTeamEntrySection() {
- var element = document.getElementById("boxscoreContainer");
- var newElement = '<div id="teamEntry" style="margin-bottom:180px"> \
- <label for="redTeamName">Red Team: </label><input class="teamNameInput" id="redTeamName" name="redTeamName" style="margin-left:2px; color: black;"/>\
- <label for="blueTeamName"> Blue Team: </label><input class="teamNameInput" id="blueTeamName" name="blueTeamName" style="margin-top:10px; color: black;"/>\
- </div>';
- element.insertAdjacentHTML( 'beforeend', newElement );
- }
- function createTeamInversionSection() {
- var element = document.getElementById("teamEntry");
- var newElement = '<div id="teamInversionSelection" style="margin-bottom:-240px">Red team is blue in: \
- <input type="checkbox" name="teamInversionSelection" id="g1h1Inversion" value="g1h1Inversion">g1h1\
- <input type="checkbox" name="teamInversionSelection" id="g1h2Inversion" value="g1h2Inversion" checked="checked">g1h2 \
- <input type="checkbox" name="teamInversionSelection" id="g2h1Inversion" value="g2h1Inversion">g2h1 \
- <input type="checkbox" name="teamInversionSelection" id="g2h2Inversion" value="g2h2Inversion" checked="checked">g2h2 \
- <input type="checkbox" name="teamInversionSelection" id="g3h1Inversion" value="g3h1Inversion">g3h1 \
- <input type="checkbox" name="teamInversionSelection" id="g3h2Inversion" value="g3h2Inversion" checked="checked">g3h2 \</div>';
- element.insertAdjacentHTML( 'afterend', newElement );
- $("input[name='teamInversionSelection']").each(function () {
- $(this).change(function() {
- saveInversions();
- loadBoxscores();
- });
- });
- }
- function createBoxscoreSection() {
- var element = document.getElementById("boxscoreContainer");
- var newElement = '<div id="boxscore" style="margin-top:20px margin-left:320px"><table style="width:30%"> \
- <tr style="vertical-align:top"> \
- <td vertical-align:top"></td> \
- ' + generateBoxscoreInput("g1h1.RedScoreInput", "", true) + ' \
- ' + generateBoxscoreInput("g1h2.RedScoreInput", "", true) + ' \
- ' + generateBoxscoreInput("g1aggregate.RedScoreInput", "", false) + ' \
- ' + generateBoxscoreInput("g2h1.RedScoreInput", "", true) + ' \
- ' + generateBoxscoreInput("g2h2.RedScoreInput", "", true) + ' \
- ' + generateBoxscoreInput("g2aggregate.RedScoreInput", "", false) + ' \
- ' + generateBoxscoreInput("g3h1.RedScoreInput", "", true) + ' \
- ' + generateBoxscoreInput("g3h2.RedScoreInput", "", true) + ' \
- ' + generateBoxscoreInput("g3aggregate.RedScoreInput", "", false) + ' \
- </tr> \
- <tr> \
- ' + generateTeamnameEntryRed($.cookie("redTeamName"), redAggregateScoreBackgroundLoc) + ' \
- ' + generateBoxscoreEntryRed2("g1h1.RedScore", redHalfScoreBackgroundLoc, redAggregateScoreBgLoc, "") + ' \
- ' + generateBoxscoreEntryRed("g1h2.RedScore", redHalfScoreBackgroundLoc, redAggregateScoreBgLoc, "") + ' \
- ' + generateBoxscoreEntryRed("g1aggregate.RedScore", redAggregateScoreBackgroundLoc, redAggregateScoreBackgroundLoc, "") + ' \
- ' + generateBoxscoreEntryRed2("g2h1.RedScore", redHalfScoreBackgroundLoc, redAggregateScoreBgLoc, "") + ' \
- ' + generateBoxscoreEntryRed("g2h2.RedScore", redHalfScoreBackgroundLoc, redAggregateScoreBgLoc, "") + ' \
- ' + generateBoxscoreEntryRed("g2aggregate.RedScore", redAggregateScoreBackgroundLoc, redAggregateScoreBackgroundLoc, "") + ' \
- ' + generateBoxscoreEntryRed2("g3h1.RedScore", redHalfScoreBackgroundLoc, redAggregateScoreBgLoc, "") + ' \
- ' + generateBoxscoreEntryRed("g3h2.RedScore", redHalfScoreBackgroundLoc, redAggregateScoreBgLoc, "") + ' \
- ' + generateBoxscoreEntryRed("g3aggregate.RedScore", redAggregateScoreBackgroundLoc, redAggregateScoreBackgroundLoc, "") + ' \
- </tr> \
- <tr> \
- ' + generateTeamnameEntryBlue($.cookie("blueTeamName"), blueAggregateScoreBackgroundLoc) + ' \
- ' + generateBoxscoreEntryBlue2("g1h1.BlueScore", blueHalfScoreBackgroundLoc, blueAggregateScoreBgLoc, "") + ' \
- ' + generateBoxscoreEntryBlue("g1h2.BlueScore", blueHalfScoreBackgroundLoc, blueAggregateScoreBgLoc, "") + ' \
- ' + generateBoxscoreEntryBlue("g1aggregate.BlueScore", blueAggregateScoreBackgroundLoc, blueAggregateScoreBackgroundLoc, "") + ' \
- ' + generateBoxscoreEntryBlue2("g2h1.BlueScore", blueHalfScoreBackgroundLoc, blueAggregateScoreBgLoc, "") + ' \
- ' + generateBoxscoreEntryBlue("g2h2.BlueScore", blueHalfScoreBackgroundLoc, blueAggregateScoreBgLoc, "") + ' \
- ' + generateBoxscoreEntryBlue("g2aggregate.BlueScore", blueAggregateScoreBackgroundLoc, blueAggregateScoreBackgroundLoc, "") + ' \
- ' + generateBoxscoreEntryBlue2("g3h1.BlueScore", blueHalfScoreBackgroundLoc, blueAggregateScoreBgLoc, "") + ' \
- ' + generateBoxscoreEntryBlue("g3h2.BlueScore", blueHalfScoreBackgroundLoc, blueAggregateScoreBgLoc, "") + ' \
- ' + generateBoxscoreEntryBlue("g3aggregate.BlueScore", blueAggregateScoreBackgroundLoc, blueAggregateScoreBackgroundLoc, "") + ' \
- </tr> \
- <tr> \
- <td vertical-align:top"></td> \
- ' + generateBoxscoreInput("g1h1.BlueScoreInput", "", true) + ' \
- ' + generateBoxscoreInput("g1h2.BlueScoreInput", "", true) + ' \
- ' + generateBoxscoreInput("g1aggregate.BlueScoreInput", "", false) + ' \
- ' + generateBoxscoreInput("g2h1.BlueScoreInput", "", true) + ' \
- ' + generateBoxscoreInput("g2h2.BlueScoreInput", "", true) + ' \
- ' + generateBoxscoreInput("g2aggregate.BlueScoreInput", "", false) + ' \
- ' + generateBoxscoreInput("g3h1.BlueScoreInput", "", true) + ' \
- ' + generateBoxscoreInput("g3h2.BlueScoreInput", "", true) + ' \
- ' + generateBoxscoreInput("g3aggregate.BlueScoreInput", "", false) + ' \
- </tr> \
- </table></div>';
- element.insertAdjacentHTML( 'beforeend', newElement );
- }
- function generateBoxscoreEntryRed(id, imageLoc, imagebgLoc, score) {
- return '<td style="width:80px;vertical-align:top;background-color: #ff0000; background-image: url(' + imagebgLoc + ')"><div id="' + id + '" style="margin-left:0px; width:110px; height:0px; line-height:90px; background-image: url(' + imagebgLoc + ');">' + createFontElement(score, boxscoreFontSize) + '</div></td>';
- }
- function generateBoxscoreEntryBlue(id, imageLoc, imagebgLoc, score) {
- return '<td style="width:80px;vertical-align:top;background-color: #0000ff; background-image: url(' + imagebgLoc + ')"><div id="' + id + '" style="margin-left:0px; width:110px; height:0px; line-height:90px; background-image: url(' + imagebgLoc + ');">' + createFontElement(score, boxscoreFontSize) + '</div></td>';
- }
- function generateBoxscoreEntryRed2(id, imageLoc, imagebgLoc, score) {
- return '<td style="width:80px;vertical-align:top;background-color: #ff0000; background-image: url(' + imagebgLoc + ')"><div id="' + id + '" style="margin-left:0px; width:109px; height:0px; line-height:90px; background-image: url(' + imagebgLoc + ');">' + createFontElement(score, boxscoreFontSize) + '</div></td>';
- }
- function generateBoxscoreEntryBlue2(id, imageLoc, imagebgLoc, score) {
- return '<td style="width:80px;vertical-align:top;background-color: #0000ff; background-image: url(' + imagebgLoc + ')"><div id="' + id + '" style="margin-left:0px; width:109px; height:0px; line-height:90px; background-image: url(' + imagebgLoc + ');">' + createFontElement(score, boxscoreFontSize) + '</div></td>';
- }
- function generateTeamnameEntryRed(id, imageLoc) {
- return '<td style="vertical-align:top;background-color: #ff0000;background-image: url(' + imageLoc + ')"><div id="' + id + '" style="margin-left:0px; width:800px; height:90px; line-height:90px;">' + createFontElementAggr(id, boxscoreTeamFontSize) + '</div></td>';
- }
- function generateTeamnameEntryBlue(id, imageLoc) {
- return '<td style="vertical-align:top;background-color: #0000ff;background-image: url(' + imageLoc + ')"><div id="' + id + '" style="margin-left:0px; width:800px; height:90px; line-height:90px;">' + createFontElementAggr(id, boxscoreTeamFontSize) + '</div></td>';
- }
- function createFontElement(num, size) {
- return '<p style="text-align:center; font-weight:normal; color: black; margin-top:-4px; font-family:\'Play\'; font-size:' + size + '">' + num + '</p>';
- }
- function createFontElementAggr(num, size) {
- return '<p style="text-align:center; font-weight:normal; margin-top:-4px; font-family:\'Play\'; font-size:' + size + '">' + num + '</p>';
- }
- function generateBoxscoreInput(id, value, enabled) {
- var disabledSection = enabled ? "" : "disabled";
- return '<td style="width:91px; color: black; vertical-align:top"><div class="boxscoreInput" id="teamBoxscoreInputs" style="margin-left:15px; margin-top:5px; margin-bottom:5px; width:0px"><input type="text" id=' + id + ' name="' + id + '" value="' + value + '" style="width:77px;text-align:center" ' + disabledSection + '></div></td>';
- }
- function setupTeamEntryEventListeners() {
- $(".teamNameInput").change(overrideTeamName);
- }
- function overrideTeamName(obj) {
- var name = obj.target.name;
- var value = obj.target.value;
- console.log("Name is: " + name);
- console.log("Value is: " + value);
- // add new cookie
- var options = {
- domain: domain,
- path: '/'
- };
- //console.log("replacing " + nameWithoutInput + " with " + obj.target.value);
- $.cookie(name, value, options);
- }
- function setupBoxscoreEventListeners() {
- $(".boxscoreInput").change(overrideBoxscore);
- }
- function overrideBoxscore(obj) {
- // Remove "input" from id and escape period
- var nameWithoutInput = obj.target.name.replace("Input", "");
- var sections = nameWithoutInput.split(".");
- var period = sections[0];
- var teamColor = sections[1].replace("Score", "");
- var invert = $.cookie(period + "Inversion");
- if (invert == "true") {
- teamColor = invertTeamColor(teamColor);
- }
- nameWithoutInput = period + "." + teamColor + "Score";
- var name = nameWithoutInput.replace(".", "\\.");
- $("#" + name).html(createFontElement(obj.target.value, boxscoreFontSize));
- // add new cookie
- var options = {
- domain: domain,
- path: '/'
- };
- //console.log("replacing " + nameWithoutInput + " with " + obj.target.value);
- $.cookie(nameWithoutInput, obj.target.value, options);
- loadBoxscores();
- }
- function loadBoxscores() {
- for (game = 1; game < 4; game++) {
- for (half = 1; half < 3; half++) {
- var invert = $.cookie("g" + game + "h" + half + "Inversion");
- updateScore("Red", invert);
- updateScore("Blue", invert);
- }
- // calculate aggregate
- updateAggregate("Red", game);
- updateAggregate("Blue", game);
- }
- setupBoxscoreEventListeners();
- }
- function updateScore(teamColor, invert) {
- var scoreName = "g" + game + "h" + half + "." + teamColor + "Score";
- var invertedScoreName = "g" + game + "h" + half + "." + invertTeamColor(teamColor) + "Score";
- if (invert == "true") {
- var score = $.cookie(invertedScoreName);
- } else {
- var score = $.cookie(scoreName);
- }
- if (score !== undefined) {
- // escape period
- var escapedScoreName = scoreName.replace(".", "\\.");
- // update score
- $("#" + escapedScoreName).html(createFontElement(score, boxscoreFontSize));
- //console.log("Setting " + teamColor + " score to " + score);
- // update score input
- $("#" + escapedScoreName + "Input").parent().parent().replaceWith(generateBoxscoreInput(scoreName + "Input", score, true));
- }
- }
- function updateAggregate(teamColor, game) {
- console.log("***Updating aggregate for game " + game + " and teamColor: " + teamColor);
- var aggregateScoreName = "g" + game + "aggregate." + teamColor + "Score";
- var score = ""; // starts blank
- for (var half = 1; half < 3; half++) {
- // If either half scores are undefined for this game, exit
- if (($.cookie("g" + game + "h1" + "." + teamColor + "Score") === undefined) || ($.cookie("g" + game + "h2" + "." + teamColor + "Score") === undefined)) {
- continue;
- }
- var invert = $.cookie("g" + game + "h" + half + "Inversion");
- console.log("invert is: " + invert);
- var tempTeamColor = teamColor;
- if (invert == "true") {
- tempTeamColor = invertTeamColor(teamColor);
- }
- var halfScore = $.cookie("g" + game + "h" + half + "." + tempTeamColor + "Score");
- console.log("Half score for g" + game + "h" + half + "." + tempTeamColor + "Score: " + halfScore);
- if (halfScore !== undefined) {
- // If we are saving a score and the score is blank, set it to 0.
- if (score === "") {
- score = 0;
- }
- score = score + parseInt(halfScore);
- }
- }
- var escapedScoreName = aggregateScoreName.replace(".", "\\.");
- $("#" + escapedScoreName).html(createFontElementAggr(score, boxscoreFontSize));
- // persist aggregate score to cookie
- var options = {
- domain: domain,
- path: '/'
- }
- ;
- $.cookie(aggregateScoreName, score, options);
- }
- function invertTeamColor(teamColor) {
- if (teamColor == "Red") {
- return "Blue";
- } else {
- return "Red";
- }
- }
- function loadInversions() {
- for (game = 1; game < 3; game++) {
- for (half = 1; half < 3; half++) {
- var name = "g" + game + "h" + half + "Inversion";
- var invert = $.cookie(name);
- if (invert !== undefined) {
- $("#" + name).prop('checked', invert === "true"); // Check the box if invert is true, else unchecked
- }
- // console.log("name: " + name + " invert: " + invert);
- }
- }
- }
- function saveInversions() {
- // add new cookie
- var options = {
- domain: domain,
- path: '/'
- };
- $("input[name='teamInversionSelection']").each(function () {
- $.cookie(this.value, this.checked, options);
- });
- }
- //////////////////////////////////
- // JQUERY COOKIE PLUGIN FOLLOWS //
- //////////////////////////////////
- function initJqueryCookiePlugin() {
- (function (factory) {
- if (typeof define === 'function' && define.amd) {
- // AMD (Register as an anonymous module)
- define(['jquery'], factory);
- } else if (typeof exports === 'object') {
- // Node/CommonJS
- module.exports = factory(require('jquery'));
- } else {
- // Browser globals
- factory(jQuery);
- }
- }(function ($) {
- var pluses = /\+/g;
- function encode(s) {
- return config.raw ? s : encodeURIComponent(s);
- }
- function decode(s) {
- return config.raw ? s : decodeURIComponent(s);
- }
- function stringifyCookieValue(value) {
- return encode(config.json ? JSON.stringify(value) : String(value));
- }
- function parseCookieValue(s) {
- if (s.indexOf('"') === 0) {
- // This is a quoted cookie as according to RFC2068, unescape...
- s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
- }
- try {
- // Replace server-side written pluses with spaces.
- // If we can't decode the cookie, ignore it, it's unusable.
- // If we can't parse the cookie, ignore it, it's unusable.
- s = decodeURIComponent(s.replace(pluses, ' '));
- return config.json ? JSON.parse(s) : s;
- } catch(e) {}
- }
- function read(s, converter) {
- var value = config.raw ? s : parseCookieValue(s);
- return $.isFunction(converter) ? converter(value) : value;
- }
- var config = $.cookie = function (key, value, options) {
- // Write
- if (arguments.length > 1 && !$.isFunction(value)) {
- options = $.extend({}, config.defaults, options);
- if (typeof options.expires === 'number') {
- var days = options.expires, t = options.expires = new Date();
- t.setMilliseconds(t.getMilliseconds() + days * 864e+5);
- }
- return (document.cookie = [
- encode(key), '=', stringifyCookieValue(value),
- options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
- options.path ? '; path=' + options.path : '',
- options.domain ? '; domain=' + options.domain : '',
- options.secure ? '; secure' : ''
- ].join(''));
- }
- // Read
- var result = key ? undefined : {},
- // To prevent the for loop in the first place assign an empty array
- // in case there are no cookies at all. Also prevents odd result when
- // calling $.cookie().
- cookies = document.cookie ? document.cookie.split('; ') : [],
- i = 0,
- l = cookies.length;
- for (; i < l; i++) {
- var parts = cookies[i].split('='),
- name = decode(parts.shift()),
- cookie = parts.join('=');
- if (key === name) {
- // If second argument (value) is a function it's a converter...
- result = read(cookie, value);
- break;
- }
- // Prevent storing a cookie that we couldn't decode.
- if (!key && (cookie = read(cookie)) !== undefined) {
- result[name] = cookie;
- }
- }
- return result;
- };
- config.defaults = {};
- $.removeCookie = function (key, options) {
- // Must not alter options, thus extending a fresh object...
- $.cookie(key, '', $.extend({}, options, { expires: -1 }));
- return !$.cookie(key);
- };
- }));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement