Skip to content

Instantly share code, notes, and snippets.

@nabbynz
Last active May 5, 2024 05:24
Show Gist options
  • Save nabbynz/c558e36976833c7822835113e4cbf954 to your computer and use it in GitHub Desktop.
Save nabbynz/c558e36976833c7822835113e4cbf954 to your computer and use it in GitHub Desktop.
TagPro Chat Logger
// ==UserScript==
// @name Chat Logger
// @description Saves the chat history
// @version 0.0.11
// @match https://tagpro.koalabeast.com/
// @match https://tagpro.koalabeast.com/games/find*
// @match https://tagpro.koalabeast.com/game
// @match https://tagpro.koalabeast.com/game?*
// @updateURL https://gist.github.com/nabbynz/c558e36976833c7822835113e4cbf954/raw/Chat_Logger.user.js
// @downloadURL https://gist.github.com/nabbynz/c558e36976833c7822835113e4cbf954/raw/Chat_Logger.user.js
// @author nabby
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_addStyle
// ==/UserScript==
'use strict';
console.log('START: ' + GM_info.script.name + ' (v' + GM_info.script.version + ' by ' + GM_info.script.author + ')');
/* eslint-env jquery */
/* globals tagpro, tagproConfig, PIXI */
/* eslint-disable no-multi-spaces */
// Options...
const MS_TO_KEEP_LOGS = 1000 * 60 * 60 * 24; //eg: 1000*60*60*24 = 24 hours, 1000*60*60*24*7 = 7 days)
const SHOW_LAST_GAME_ON_JOINER = true;
const RED_TEXT_COLOR = '#ffb5bd';
const BLUE_TEXT_COLOR = '#cfcfff';
const SHOW_FLAIRS_FOR_JOINERS = true;
tagpro.ready(function() {
let chatLogs;
let isSaveAttempt = false;
if (location.pathname === '/game') {
let chatLog = [];
let gameEndsAt = new Date(tagpro.gameEndsAt).getTime();
let gameEndedAt;
let getScoreboardData = function() {
let data = [];
for (let playerId in tagpro.players) {
data.push({
name: tagpro.players[playerId].name,
team: tagpro.players[playerId].team,
auth: tagpro.players[playerId].auth,
self: (!tagpro.spectator && tagpro.playerId === tagpro.players[playerId].id ? true : false),
tags: tagpro.players[playerId]["s-tags"],
pops: tagpro.players[playerId]["s-pops"],
grabs: tagpro.players[playerId]["s-grabs"],
drops: tagpro.players[playerId]["s-drops"],
hold: tagpro.players[playerId]["s-hold"],
captures: tagpro.players[playerId]["s-captures"],
prevent: tagpro.players[playerId]["s-prevent"],
returns: tagpro.players[playerId]["s-returns"],
support: tagpro.players[playerId]["s-support"],
powerups: tagpro.players[playerId]["s-powerups"],
score: +tagpro.players[playerId].score,
oscore: +tagpro.players[playerId].oscore,
dscore: +tagpro.players[playerId].dscore,
points: tagpro.players[playerId].points
});
}
data.sort(function(a, b) {
return (b.score - a.score ? b.score - a.score : a.id - b.id);
});
return data;
};
let saveChatEntry = function(data) {
let name = null;
let team = null;
if (data.from > 0) {
name = tagpro.players[data.from].name;
team = tagpro.players[data.from].team;
} else {
name = data.from;
}
chatLog.push({ from:data.from, message:data.message, to:data.to, c:data.c, mod:data.mod, monitor:data.monitor, date:Date.now(), name:name, team:team, state:tagpro.state, flair:data.flair });
if (data.from === null && !tagpro.ui.sprites.saveAttempt && data.message.toString().startsWith('This is a save attempt!')) {
isSaveAttempt = true;
if (!tagpro.ui.sprites.saveAttempt) {
//setTimeout(function() {
//console.log('CL:: adding sprite:', tagpro.renderer.vpWidth);
tagpro.ui.sprites.saveAttempt = tagpro.renderer.prettyText("Save Attempt");
tagpro.ui.sprites.saveAttempt.tint = 0xFF5500;
tagpro.ui.sprites.saveAttempt.anchor.x = 1;
tagpro.ui.sprites.saveAttempt.x = tagpro.renderer.vpWidth - 6;
tagpro.ui.sprites.saveAttempt.y = 10;
//tagpro.ui.sprites.saveAttempt.alpha = 0.7;
tagpro.renderer.layers.ui.addChild(tagpro.ui.sprites.saveAttempt);
//}, 600);
}
}
if (tagpro.state === 2 && chatLogs.hasOwnProperty(tagproConfig.gameId)) { //saves post-game chat each time it appears so we don't lose anything
chatLogs[tagproConfig.gameId].chatLog = chatLog;
GM_setValue('chatLogs', chatLogs);
}
};
tagpro.socket.on('time', function(data) {
if (data.state === 1 || data.state === 5) {
gameEndsAt = new Date(tagpro.gameEndsAt).getTime();
}
});
//GM_addStyle('.fa-circle-xmark { scale:0.6; }');
GM_addStyle('.fa-plus, .fa-minus { scale:0.6; }');
tagpro.socket.on('chat', function(data) {
if (!tagproConfig.replay) {
saveChatEntry(data);
}
// this adds the flair to the front of the message when a new player joins (and changes the arrow/cross to +/-)
if (SHOW_FLAIRS_FOR_JOINERS && data.from === null) {
if (data.message.includes(' has joined the')) {
const flair = tagpro.players[data.for].flair;
const lastChat = $('#chatHistory').children().last().find('i');
if (flair) {
lastChat.css({ 'visibility':'hidden' }).after('<span class="flair ' + flair.className + '" style="background-position: -' + (flair.x * 16) + 'px -' + (flair.y * 16) + 'px; position:absolute; scale:78%; margin:-1px 0 0 -14px;"></span>');
if (!tagproConfig.replay) {
chatLog[chatLog.length - 1].flair = flair;
}
} else {
lastChat.removeClass('fa-circle-arrow-right').addClass('fa-plus');
}
} else if (data.message.includes(' has left the')) {
$('#chatHistory').children().last().find('i').removeClass('fa-circle-xmark').addClass('fa-minus');
}
}
});
if (tagpro.group.socket !== null) {
tagpro.group.socket.on('chat', function(data) {
if (!tagproConfig.replay) {
saveChatEntry(data);
}
});
}
let getTeamCounts = function() {
if (tagpro.ui.sprites && tagpro.ui.sprites.playerIndicators) {
let redTeamCount = tagpro.ui.sprites.playerIndicators.children[0].children.length || -1;
let blueTeamCount = tagpro.ui.sprites.playerIndicators.children[1].children.length || -1;
return redTeamCount >= 0 && blueTeamCount >= 0 ? ', ' + redTeamCount + 'v' + blueTeamCount : '';
} else {
return '';
}
};
let lastLastScoreRed, lastLastScoreBlue;
tagpro.socket.on('score', function(data) {
if (lastLastScoreRed >= 0 && lastLastScoreBlue >= 0) {
if (lastLastScoreRed !== data.r) {
chatLog.push({ from:null, message:'Red Caps! (' + tagpro.score.r + ':' + tagpro.score.b + getTeamCounts() + ')', to:'all', c:'#7fff00', mod:null, monitor:null, date:Date.now(), state:tagpro.state, cap:1 });
} else if (lastLastScoreBlue !== data.b) {
chatLog.push({ from:null, message:'Blue Caps! (' + tagpro.score.r + ':' + tagpro.score.b + getTeamCounts() + ')', to:'all', c:'#7fff00', mod:null, monitor:null, date:Date.now(), state:tagpro.state, cap:2 });
}
} else if (tagpro.state !== 3) {
chatLog.push({ from:null, message:'--- Join Score: ' + tagpro.score.r + ':' + tagpro.score.b + getTeamCounts() + ' ---', to:'all', c:'#7fff00', mod:null, monitor:null, date:Date.now(), state:tagpro.state });
}
lastLastScoreRed = data.r;
lastLastScoreBlue = data.b;
});
tagpro.socket.on('end', function(data) {
chatLogs = GM_getValue('chatLogs', {});
if (!chatLogs.hasOwnProperty(tagproConfig.gameId) && tagpro.ui.sprites.playerIndicators.children[0].children.length + tagpro.ui.sprites.playerIndicators.children[1].children.length > 1) {
let winnerTeamText = tagpro.score.r > tagpro.score.b ? 'Red' : 'Blue';
let winnerIconText = tagpro.score.r > tagpro.score.b ? '<span style="font-size:8px;">🔴</span>' : '<span style="font-size:8px;">🔵</span>';
gameEndedAt = Date.now();
chatLog.push({ from:null, message:winnerIconText + ' End of Game ' + winnerIconText + ' ' + winnerTeamText + ' Wins ' + tagpro.score.r + ':' + tagpro.score.b, to:'all', c:'#da67ff', mod:null, monitor:null, date:gameEndedAt });
let pos = tagproConfig.gameSocket.indexOf(':');
let server = tagproConfig.gameSocket.substring(0, pos).replace('tagpro-', '').replace('.koalabeast.com', '');
let scoreboard = getScoreboardData();
chatLogs[tagproConfig.gameId] = { date:Date.now(), chatLog:chatLog, redScore:tagpro.score.r, blueScore:tagpro.score.b, map:$('#mapInfo').text().trim(), server:server, spectator:tagpro.spectator, gameEndsAt:gameEndsAt, gameEndedAt:gameEndedAt, scoreboard:scoreboard, saveAttempt:isSaveAttempt };
if (!tagproConfig.replay) {
GM_setValue('chatLogs', chatLogs);
}
}
});
} else { //not in a game...
let trimLogs = function() {
if (Object.keys(chatLogs).length) {
let saveLog = false;
for (let gameId in chatLogs) {
if (chatLogs[gameId].date < Date.now() - MS_TO_KEEP_LOGS) {
delete chatLogs[gameId];
saveLog = true;
} else if ($('#CL_Logs').length) {
let date = new Date(chatLogs[gameId].date);
let resultIconClass = chatLogs[gameId].spectator !== false ? 'CL_Result_Spec' : '';
if (!resultIconClass) {
for (let i = 0; i < chatLogs[gameId].scoreboard.length; i++) {
if (chatLogs[gameId].scoreboard[i].self) {
let team = chatLogs[gameId].scoreboard[i].team;
let isSaveAttempt = chatLogs[gameId].saveAttempt;
if (isSaveAttempt === undefined) {
for (let j=0; j<chatLogs[gameId].chatLog.length; j++) {
if (chatLogs[gameId].chatLog[j].from === null && String(chatLogs[gameId].chatLog[j].message).startsWith('This is a save attempt!')) {
isSaveAttempt = true;
}
}
}
if (chatLogs[gameId].redScore > chatLogs[gameId].blueScore && team === 1 || chatLogs[gameId].blueScore > chatLogs[gameId].redScore && team === 2) {
resultIconClass = isSaveAttempt ? 'CL_Result_SSA' : 'CL_Result_Win';
} else {
resultIconClass = isSaveAttempt ? 'CL_Result_USA' : 'CL_Result_Loss';
}
}
}
}
$('#CL_Logs').append('<div class="CL_GameId" data-sortby="' + chatLogs[gameId].date + '" data-gameid="' + gameId + '" title="' + chatLogs[gameId].map + '"><span class="' + resultIconClass + '"></span>' + date.toDateString() + ', ' + date.toLocaleTimeString() + '<span class="CL_Delete" data-gameid="' + gameId + '" title="Delete this log">X</span></div>');
}
}
if (saveLog) {
GM_setValue('chatLogs', chatLogs);
}
}
};
let addToPage = function() {
GM_addStyle('#CL_OpenLogs { display:block; width:180px; font-size:14px; text-align:center; margin:0 auto 5px; color:#ccc; border:1px outset #555; border-radius:5px 0; padding:4px 10px; cursor:pointer; }');
GM_addStyle('#CL_OpenLogs:hover { color:#fff; }');
GM_addStyle('#CL_Container { display:flex; flex-flow:row nowrap; position:absolute; width:800px; height:400px; left:-100px; top:30px; background:#111; padding:2px; font-size:11px; box-shadow:0px 0px 20px black; z-index:1; }');
GM_addStyle('.CL_Header { text-align:center; }');
GM_addStyle('#CL_Logs { border:1px solid #555; padding:2px; position:relative; width:200px; overflow:hidden auto; }');
GM_addStyle('#CL_Logs::-webkit-scrollbar { width:2px; }');
GM_addStyle('#CL_Logs::-webkit-scrollbar-thumb { background:#b0b; }');
GM_addStyle('#CL_Logs::-webkit-scrollbar-track { background:#999; }');
GM_addStyle('.CL_GameId { color:#ccc; border-bottom:1px dotted #555; padding:1px 0; position:relative; cursor:pointer; }');
GM_addStyle('.CL_GameId:hover { color:white; }');
GM_addStyle('#CL_Log { border:1px solid #555; padding:2px; position:relative; text-align:left; width:600px; overflow:hidden auto; }');
GM_addStyle('#CL_Log::-webkit-scrollbar { width:2px; }');
GM_addStyle('#CL_Log::-webkit-scrollbar-thumb { background:#b0b; }');
GM_addStyle('#CL_Log::-webkit-scrollbar-track { background:#444; }');
GM_addStyle('.CL_Timer { display:inline-block; color:#da981f; width:35px; text-align:right; margin-right:3px; }');
GM_addStyle('.CL_Chat { color:#ccc; }');
GM_addStyle('.CL_Delete { text-align:center; font-size:8px; font-weight:bold; color:#a00; width:12px; border:1px solid #a00; border-radius:50%; position:absolute; right:0px; top:1px; cursor:pointer; }');
GM_addStyle('.CL_Delete:hover { color:#f00; border:1px solid #f00; }');
GM_addStyle('#CL_Close { text-align:center; font-size:12px; color:#999; width:17px; border:1px solid #999; border-radius:3px; position:absolute; right:7px; top:5px; cursor:pointer; }');
GM_addStyle('#CL_Close:hover { color:#fff; border:1px solid #fff; }');
GM_addStyle('.CL_Cap_Red { background:rgba(255,76,76,0.6); color:#fff; }');
GM_addStyle('.CL_Cap_Blue { background:rgba(30,144,255,0.4); color:#fff; }');
GM_addStyle('.CL_Result_Spec { background:#ffffff; display:inline-block; margin:2px 2px 2px 0; border-radius:50%; width:5px; height:5px; }'); //#7c80ff
GM_addStyle('.CL_Result_Win { background:#28ff4c; display:inline-block; margin:2px 2px 2px 0; border-radius:50%; width:5px; height:5px; }');
GM_addStyle('.CL_Result_Loss { background:#ff2828; display:inline-block; margin:2px 2px 2px 0; border-radius:50%; width:5px; height:5px; }');
GM_addStyle('.CL_Result_SSA { background:#000000; display:inline-block; margin:3px 3px 3px 1px; border-radius:50%; width:3px; height:3px; box-shadow:0px 0px 1px 2px #66ff66; }');
GM_addStyle('.CL_Result_USA { background:#000000; display:inline-block; margin:3px 3px 3px 1px; border-radius:50%; width:3px; height:3px; box-shadow:0px 0px 1px 2px #ff2828; }');
GM_addStyle('.CL_Red { color:' + RED_TEXT_COLOR + '; }');
GM_addStyle('.CL_Blue { color:' + BLUE_TEXT_COLOR + '; }');
GM_addStyle('.CL_Selected { color:chartreuse; }');
GM_addStyle('.CL_Font9 { font-size:9px; }');
GM_addStyle('.CL_Auth { color:#77ff00; }');
GM_addStyle('#CL_Scoreboard { margin:5px auto; font-size:11px; color:#bbb; width:90%; text-align:center; background:#181818; }');
GM_addStyle('#CL_Scoreboard td { border:1px solid #000; padding:2px 0 1px; white-space:nowrap; }');
GM_addStyle('#CL_Scoreboard td:nth-child(1) { font-family:monospace; }');
GM_addStyle('#CL_Scoreboard td:nth-child(3) { color:#888; }');
GM_addStyle('#CL_Scoreboard td:nth-child(4) { color:#888; }');
GM_addStyle('#CL_Scoreboard_Header { color:#fff; background:#333; }');
GM_addStyle('#CL_Scoreboard_Header td { color:#fff !important; }');
GM_addStyle('.CL_SB_Max_Red { color:white !important; background:rgba(220,0,0,0.4); }');
GM_addStyle('.CL_SB_Max_Blue { color:white !important; background:rgba(0,40,250,0.3); }');
$('#CL_Container').hide();
if (Object.keys(chatLogs).length) {
$('#CL_Logs').find('.CL_GameId').sort(function(a, b) {
return ($(b).data('sortby') - $(a).data('sortby'));
}).appendTo( $('#CL_Logs') );
$('#CL_OpenLogs').on('click', function() {
if ($('#CL_Container').is(':visible')) {
$('#CL_Container').fadeOut(50);
} else {
$('#CL_Container').fadeIn(100);
}
});
$('.CL_GameId').on('click', function() {
showChatLog(this.dataset.gameid);
});
$('#CL_Logs').on('click', '.CL_Delete', function(e) {
e.stopPropagation();
e.preventDefault();
if (chatLogs.hasOwnProperty(this.dataset.gameid)) {
if (!confirm('Delete this chat log?\n\n')) return;
delete chatLogs[this.dataset.gameid];
GM_setValue('chatLogs', chatLogs);
let $this = $(this).parent();
$this.fadeOut(600, function() { $this.remove(); });
$('#CL_Log').empty();
if (!Object.keys(chatLogs).length) {
$('#CL_Logs').append('<div>No logs available.</div>');
}
}
});
$('#CL_Close').on('click', function() {
$('#CL_Container').fadeOut(50);
});
} else {
$('#CL_Logs').append('<div>No logs available.</div>');
}
};
let showChatLog = function(gameId) {
if (Object.keys(chatLogs).length && chatLogs.hasOwnProperty(gameId)) {
let chatLog = chatLogs[gameId].chatLog;
let date = new Date(chatLogs[gameId].date);
let gameEndsAt = chatLogs[gameId].gameEndsAt;
$('#CL_Log').empty();
$('#CL_Log').append('<div class="CL_Header">' + date.toDateString() + ', ' + date.toLocaleTimeString() + '</div>');
$('#CL_Log').append('<div class="CL_Header">' + chatLogs[gameId].map + '</div>');
$('#CL_Log').append('<div class="CL_Header">Game ID: ' + gameId + ' on ' + chatLogs[gameId].server + '</div>');
$('#CL_Log').append('<div class="CL_Header">Final Score: ' + chatLogs[gameId].redScore + ':' + chatLogs[gameId].blueScore + '</div>');
$('#CL_Log').append('<div style="margin:3px 80px; border-bottom:1px solid #555;"></div>');
for (let i = 0; i < chatLog.length; i++) {
let color = '';
let timerText = '';
if (chatLog[i].to === 'team') color = chatLog[i].team === 1 ? RED_TEXT_COLOR : BLUE_TEXT_COLOR;
else if (chatLog[i].to === 'group') color = '#e7e700';
else if (chatLog[i].mod) color = '#00b900';
else if (chatLog[i].monitor) color = '#00b7a5';
if (chatLog[i].c) color = chatLog[i].c;
if (chatLog[i].state === 2 || chatLog[i].state === 3) {
timerText = '--:--';
} else if (gameEndsAt) {
let timeLeft = Math.round((gameEndsAt - chatLog[i].date) / 1000);
if (timeLeft < 0) timerText = '+' + tagpro.helpers.timeFromSeconds(Math.abs(timeLeft), true);
else timerText = tagpro.helpers.timeFromSeconds(timeLeft, true);
}
$('#CL_Log').append('<div class="CL_Chat">' +
' <span class="CL_Timer ' + (chatLog[i].cap ? (chatLog[i].cap === 1 ? 'CL_Cap_Red' : 'CL_Cap_Blue') : '') + '">' + timerText + '</span>' +
(chatLog[i].name ? ' <span class="' + (chatLog[i].team === 1 ? ' CL_Red' : ' CL_Blue') + '"' + (color ? ' style="color:' + color + ';"' : '') + '>' + chatLog[i].name + '</span>: ' : '') +
' <span' + (color ? ' style="color:' + color + ';"' : '') + '>' + chatLog[i].message + '</span>' +
(chatLog[i].flair ? ' <span class="flair ' + chatLog[i].flair.className + '" style="background-position: -' + (chatLog[i].flair.x * 16) + 'px -' + (chatLog[i].flair.y * 16) + 'px; position:absolute; scale:78%; margin:-1px 0 0 2px;" title="' + chatLog[i].flair.description + '"></span>' : '') +
'</div>');
}
let scoreboard = makeScoreboard(gameId);
$('#CL_Log').append(scoreboard);
$('.CL_GameId').removeClass('CL_Selected');
$('#CL_Logs').find('.CL_GameId[data-gameid="' + gameId + '"]').addClass('CL_Selected');
}
};
let showLastGameLog = function() {
let lastGameId;
for (let gameId in chatLogs) {
if (!lastGameId || chatLogs[gameId].date > chatLogs[lastGameId].date) {
lastGameId = gameId;
}
}
if (lastGameId) {
showChatLog(lastGameId);
}
};
let makeScoreboard = function(gameId) {
let game = chatLogs[gameId].scoreboard;
let stats = [ 'score', 'oscore', 'dscore', 'tags', 'pops', 'grabs', 'drops', 'hold', 'captures', 'prevent', 'returns', 'support', 'powerups', 'points' ];
let rStats = { score:0, oscore:0, dscore:0, tags:0, pops:0, grabs:0, drops:0, hold:0, captures:0, prevent:0, returns:0, support:0, powerups:0, points:0 };
let bStats = { score:0, oscore:0, dscore:0, tags:0, pops:0, grabs:0, drops:0, hold:0, captures:0, prevent:0, returns:0, support:0, powerups:0, points:0 };
let scoreboard = '';
scoreboard = '<div style="margin:20px 80px 10px; border-bottom:1px solid #555;"></div><table id="CL_Scoreboard"><tr id="CL_Scoreboard_Header"><td style="width:72px;"></td><td>Score</td><td>O</td><td>D</td><td>Tags</td><td>Pops</td><td>Grabs</td><td>Drops</td><td>Hold</td><td>Caps</td><td>Prev</td><td>Rets</td><td>Supp</td><td>Pups</td><td>Pts</td></tr>';
$.each(game, function(key, value) {
scoreboard += '<tr data-team="' + value.team + '"><td style="' + (value.self === true ? 'border-left: 1px solid white; ' : '') + 'color:' + (value.team === 1 ? RED_TEXT_COLOR : BLUE_TEXT_COLOR) + '">' + (value.auth ? '<span class="CL_Auth CL_Font9">✔</span>' : '') + value.name + '</td><td data-raw="'+value.score+'">'+value.score+'</td><td data-raw="'+value.oscore+'">'+value.oscore+'</td><td data-raw="'+value.dscore+'">'+value.dscore+'</td><td data-raw="'+value.tags+'">'+value.tags+'</td><td data-raw="'+value.pops+'">'+value.pops+'</td><td data-raw="'+value.grabs+'">'+value.grabs+'</td><td data-raw="'+value.drops+'">'+value.drops+'</td><td data-raw="'+value.hold+'">'+tagpro.helpers.timeFromSeconds(value.hold, true)+'</td><td data-raw="'+value.captures+'">'+value.captures+'</td><td data-raw="'+value.prevent+'">'+tagpro.helpers.timeFromSeconds(value.prevent, true)+'</td><td data-raw="'+value.returns+'">'+value.returns+'</td><td data-raw="'+value.support+'">'+value.support+'</td><td data-raw="'+value.powerups+'">'+value.powerups+'</td><td data-raw="'+value.points+'"' + (value.self === true ? 'style="border-right: 1px solid white;"' : '') + '>'+(value.points ? value.points : '-')+'</td></tr>';
$.each(stats, function(k, v) {
if (value.team === 1) {
rStats[v] += value[v];
} else {
bStats[v] += value[v];
}
});
});
scoreboard += '</table>';
setTimeout(() => {
for (let i = 2; i <= 15; i++) {
let column = $('#CL_Scoreboard tr:gt(0) td:nth-child(' + i + ')');
let prevMax = 0;
$(column).each(function(k, v) {
if ($(this).data('raw') > prevMax) {
$(column).removeClass('CL_SB_Max_Red CL_SB_Max_Blue');
$(this).addClass($(this).parent().data('team') === 1 ? 'CL_SB_Max_Red' : 'CL_SB_Max_Blue');
prevMax = $(this).data('raw');
} else if ($(this).data('raw') === prevMax) {
$(this).addClass($(this).parent().data('team') === 1 ? 'CL_SB_Max_Red' : 'CL_SB_Max_Blue');
}
});
}
$('#CL_Scoreboard').append('<tr style="background:#333"><td colspan="15" style=""></td></tr>');
$('#CL_Scoreboard').append('<tr><td style="color:' + RED_TEXT_COLOR + '; text-align:right">Red:</td><td'+(rStats.score>=bStats.score?' class="CL_SB_Max_Red"':'')+'>'+rStats.score+'</td><td'+(rStats.oscore>=bStats.oscore?' class="CL_SB_Max_Red"':'')+'>'+rStats.oscore+'</td><td'+(rStats.dscore>=bStats.dscore?' class="CL_SB_Max_Red"':'')+'>'+rStats.dscore+'</td><td'+(rStats.tags>=bStats.tags?' class="CL_SB_Max_Red"':'')+'>'+rStats.tags+'</td><td'+(rStats.pops>=bStats.pops?' class="CL_SB_Max_Red"':'')+'>'+rStats.pops+'</td><td'+(rStats.grabs>=bStats.grabs?' class="CL_SB_Max_Red"':'')+'>'+rStats.grabs+'</td><td'+(rStats.drops>=bStats.drops?' class="CL_SB_Max_Red"':'')+'>'+rStats.drops+'</td><td'+(rStats.hold>=bStats.hold?' class="CL_SB_Max_Red"':'')+'>'+tagpro.helpers.timeFromSeconds(rStats.hold, true)+'</td><td'+(rStats.captures>=bStats.captures?' class="CL_SB_Max_Red"':'')+'>'+rStats.captures+'</td><td'+(rStats.prevent>=bStats.prevent?' class="CL_SB_Max_Red"':'')+'>'+tagpro.helpers.timeFromSeconds(rStats.prevent, true)+'</td><td'+(rStats.returns>=bStats.returns?' class="CL_SB_Max_Red"':'')+'>'+rStats.returns+'</td><td'+(rStats.support>=bStats.support?' class="CL_SB_Max_Red"':'')+'>'+rStats.support+'</td><td'+(rStats.powerups>=bStats.powerups?' class="CL_SB_Max_Red"':'')+'>'+rStats.powerups+'</td><td'+(rStats.points>=bStats.points?' class="CL_SB_Max_Red"':'')+'>'+(rStats.points ? rStats.points : '-')+'</td></tr>');
$('#CL_Scoreboard').append('<tr><td style="color:' + BLUE_TEXT_COLOR + '; text-align:right">Blue:</td><td'+(bStats.score>=rStats.score?' class="CL_SB_Max_Blue"':'')+'>'+bStats.score+'</td><td'+(bStats.oscore>=rStats.oscore?' class="CL_SB_Max_Blue"':'')+'>'+bStats.oscore+'</td><td'+(bStats.dscore>=rStats.dscore?' class="CL_SB_Max_Blue"':'')+'>'+bStats.dscore+'</td><td'+(bStats.tags>=rStats.tags?' class="CL_SB_Max_Blue"':'')+'>'+bStats.tags+'</td><td'+(bStats.pops>=rStats.pops?' class="CL_SB_Max_Blue"':'')+'>'+bStats.pops+'</td><td'+(bStats.grabs>=rStats.grabs?' class="CL_SB_Max_Blue"':'')+'>'+bStats.grabs+'</td><td'+(bStats.drops>=rStats.drops?' class="CL_SB_Max_Blue"':'')+'>'+bStats.drops+'</td><td'+(bStats.hold>=rStats.hold?' class="CL_SB_Max_Blue"':'')+'>'+tagpro.helpers.timeFromSeconds(bStats.hold, true)+'</td><td'+(bStats.captures>=rStats.captures?' class="CL_SB_Max_Blue"':'')+'>'+bStats.captures+'</td><td'+(bStats.prevent>=rStats.prevent?' class="CL_SB_Max_Blue"':'')+'>'+tagpro.helpers.timeFromSeconds(bStats.prevent, true)+'</td><td'+(bStats.returns>=rStats.returns?' class="CL_SB_Max_Blue"':'')+'>'+bStats.returns+'</td><td'+(bStats.support>=rStats.support?' class="CL_SB_Max_Blue"':'')+'>'+bStats.support+'</td><td'+(bStats.powerups>=rStats.powerups?' class="CL_SB_Max_Blue"':'')+'>'+bStats.powerups+'</td><td'+(bStats.points>=rStats.points?' class="CL_SB_Max_Blue"':'')+'>'+(bStats.points ? bStats.points : '-')+'</td></tr>');
}, 100);
return scoreboard;
};
if (location.pathname === '/') {
chatLogs = GM_getValue('chatLogs', {});
if ($('.video-container').length) { //logged out
$('.video-container').before('<div id="CL_OpenLogs">Open Chat Logs [' + Object.keys(chatLogs).length + ']</div>');
$('#userscript-home').after('<div id="CL_Container"><div id="CL_Logs"></div><div id="CL_Log"></div><div id="CL_Close" title="Close">X</div></div>');
} else {
$('#home-news').before('<div id="CL_OpenLogs">Open Chat Logs [' + Object.keys(chatLogs).length + ']</div>');
$('#home-news').before('<div id="CL_Container"><div id="CL_Logs"></div><div id="CL_Log"></div><div id="CL_Close" title="Close">X</div></div>');
}
trimLogs();
addToPage();
showLastGameLog();
} else if (SHOW_LAST_GAME_ON_JOINER && location.pathname === '/games/find') {
chatLogs = GM_getValue('chatLogs', {});
trimLogs();
$('#tip-container').before('<div id="CL_Log"></div>');
if (Object.keys(chatLogs).length) {
addToPage();
showLastGameLog();
$('#CL_Log').css({ 'font-size':'12px', 'height':'240px', 'margin':'0 auto' });
} else {
$('#CL_Log').append('<div>No last game chat log available.</div>');
$('#CL_Log').css({ 'border':'1px inset #555', 'font-size':'12px', 'margin':'10px', 'padding':'10px 0' });
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment