Last active
August 25, 2017 23:53
-
-
Save nabbynz/08c056e5e259ae296e457a88d2044ca5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Daily Win % Timeline | |
// @description Shows your win/loss timeline & stats, but resets the data everyday. | |
// @version 0.5.0 | |
// - 0.5.0: Added KD/Offense/Defense/Team Stat Bars and Medals to popup scoreboard | |
// - 0.4.1: Fixed bug (tagpro.serverHost is always null now) | |
// - 0.4.0: Added menu | |
// - 0.3.0: Added ability to change number of days the data will reset (so can be weekly now too) | |
// - Changed to table view | |
// - Added DCs (experimental) | |
// - Added Win % when playing as Red or Blue | |
// - Made compatible with new TagPro site design | |
// @include http://tagpro-*.koalabeast.com* | |
// @exclude http://tagpro-maptest.koalabeast.com* | |
// @updateURL https://gist.github.com/nabbynz/08c056e5e259ae296e457a88d2044ca5/raw/Daily_WinLoss_Timeline.user.js | |
// @downloadURL https://gist.github.com/nabbynz/08c056e5e259ae296e457a88d2044ca5/raw/Daily_WinLoss_Timeline.user.js | |
// @grant GM_setValue | |
// @grant GM_getValue | |
// @grant GM_deleteValue | |
// @grant GM_addStyle | |
// @author nabby | |
// ==/UserScript== | |
console.log('START: ' + GM_info.script.name + ' (v' + GM_info.script.version + ' by ' + GM_info.script.author + ')'); | |
var $uHome = $('#userscript-home'); | |
var $uTop = $('#userscript-top'); | |
var $uBottom = $('#userscript-bottom'); | |
var DWP_NumberDays = GM_getValue('DWP_NumberDays', 1); | |
var DWP_ResetHour = GM_getValue('DWP_ResetHour', 5); | |
var DWP_ShowTimeline = GM_getValue('DWP_ShowTimeline', true); | |
var DWP_ShowMainStats = GM_getValue('DWP_ShowMainStats', true); | |
var DWP_ShowMapStats = GM_getValue('DWP_ShowMapStats', true); | |
var DWP_MinPlays = GM_getValue('DWP_MinPlays', 3); | |
var DWP_ShowAverageStats = GM_getValue('DWP_ShowAverageStats', true); | |
var DWP_ShowNext = GM_getValue('DWP_ShowNext', true); | |
var resultColor = ''; | |
var resultBackground = ''; | |
var resultBackgroundHeader = ''; | |
var options = { //defaults | |
'Win_Color': { display:' Color for a "Win"', type:'manual', value:'#22DD22', title:''}, | |
'Loss_Color': { display:' Color for a "Loss"', type:'manual', value:'#EE2020', title:''}, | |
'DC_Color': { display:' Color for a "DC (Loss)"', type:'manual', value:'#FFFF00', title:''}, | |
'SSA_Color': { display:' Color for a "Successful Save Attempt (Win)"', type:'manual', value:'#166C16', title:''}, | |
'FSA_Color': { display:' Color for a "Unsuccessful Save Attempt"', type:'manual', value:'#157798', title:''}, | |
'Tie_Color': { display:' Color for a "Tie (Loss)"', type:'manual', value:'#ff9900', title:''}, | |
'Unknown_Color': { display:' Color for a "Unknown"', type:'manual', value:'#888888', title:''}, //just in case! | |
//These are updated by the script... | |
'DWPSavedGames': { type:'script', display:'', value:[] }, | |
}; | |
var DWP_Selections; | |
var PageLoc = WhichPageAreWeOn(); | |
function getUsefulText(value, what){ | |
if (what == 'gamemode') { | |
if (value === 1) { | |
return 'CTF'; | |
} else if (value === 2) { | |
return 'Neutral Flag'; | |
} else { | |
return ''; | |
} | |
} else if (what == 'outcome') { | |
if (value === '10') { //value must be passed as a string ('outcome'+'saved') | |
return 'Win'; | |
} else if (value === '20') { | |
return 'Loss'; | |
} else if (value === '30') { | |
return 'DC'; | |
} else if (value === '41') { | |
return 'Unsuccessful Save Attempt'; | |
} else if (value === '12') { | |
return 'Successful Save Attempt'; | |
} else if (value === '50') { | |
return 'Tie'; | |
} | |
} | |
} | |
function setNewReset() { | |
var nowTime = new Date(); | |
var resetTime; | |
if ((DWP_NumberDays === 1) && (nowTime.getHours() < DWP_ResetHour)) { | |
resetTime = new Date(Date.now()); | |
} else { | |
resetTime = new Date(Date.now() + 60*60*24*DWP_NumberDays*1000); | |
} | |
resetTime.setHours(DWP_ResetHour, 0, 0); | |
GM_setValue('reset', Date.parse(resetTime)); | |
} | |
if (!GM_getValue('reset')) setNewReset(); | |
function checkReset() { | |
var resetDate = GM_getValue('reset', Date.now()); | |
if (Date.now() > resetDate) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
var statistic = { | |
min: function(array) { | |
return Math.min.apply(null, array); | |
}, | |
max: function(array) { | |
return Math.max.apply(null, array); | |
}, | |
sum: function(array) { | |
let num = 0; | |
for (let i=0, l=array.length; i<l; i++) num += array[i]; | |
return num; | |
}, | |
normalize: function(array) { | |
let array2 = []; | |
let min = statistic.min(array); | |
let max = statistic.max(array); | |
for (let i=0, l=array.length; i<l; i++) { | |
array2.push( (array[i] - min) / ((max - min) || 1) ); | |
} | |
return array2; | |
} | |
}; | |
var makeTotalStats = function(playersData) { | |
var i; | |
var stats = [ 'score', 'tags', 'pops', 'grabs', 'drops', 'hold', 'captures', 'prevent', 'returns', 'support', 'powerups', 'points', 'kd', 'score2' ]; | |
var tStats = { | |
score: { red:0, blue:0, total:0, weight:0, data:[] }, | |
tags: { red:0, blue:0, total:0, weight:0, data:[] }, | |
pops: { red:0, blue:0, total:0, weight:0, data:[] }, | |
grabs: { red:0, blue:0, total:0, weight:0, data:[] }, | |
drops: { red:0, blue:0, total:0, weight:0, data:[] }, | |
hold: { red:0, blue:0, total:0, weight:45, data:[] }, | |
captures: { red:0, blue:0, total:0, weight:40, data:[] }, | |
prevent: { red:0, blue:0, total:0, weight:40, data:[] }, | |
returns: { red:0, blue:0, total:0, weight:45, data:[] }, | |
support: { red:0, blue:0, total:0, weight:0, data:[] }, | |
powerups: { red:0, blue:0, total:0, weight:0, data:[] }, | |
points: { red:0, blue:0, total:0, weight:0, data:[] }, | |
kd: { red:0, blue:0, total:0, weight:15, data:[] }, | |
score2: { red:0, blue:0, total:0, weight:15, data:[] } | |
}; | |
for (i=0; i<playersData.length; i++) { | |
let player = playersData[i]; | |
if (!player.kd) player.kd = player.tags / (player.pops || 1); | |
if (!player.score2) player.score2 = player.captures / (player.grabs || 1); | |
for (var j=0; j<stats.length; j++) { | |
let stat = stats[j]; | |
tStats[stat].data.push(player[stat]); | |
if (playersData[i].team === 1) { | |
tStats[stat].red += player[stat]; | |
} else { | |
tStats[stat].blue += player[stat]; | |
} | |
tStats[stat].total += player[stat]; | |
if (player.self) tStats[stat].self = player[stat]; | |
} | |
} | |
let tStats_keys = Object.keys(tStats); | |
for (i=0; i<tStats_keys.length; i++) { | |
if (tStats[tStats_keys[i]].weight) { | |
tStats[tStats_keys[i]].normal = statistic.normalize(tStats[tStats_keys[i]].data); | |
tStats[tStats_keys[i]].normalTotal = statistic.sum(tStats[tStats_keys[i]].normal); | |
} | |
} | |
tStats.offense = { red:0, blue:0, total:0, weight:0, top:[], data:[] }; | |
tStats.defense = { red:0, blue:0, total:0, weight:0, top:[], data:[] }; | |
for (i=0; i<playersData.length; i++) { | |
let value = playersData[i]; | |
value.o = tStats.captures.normal[i]/(tStats.captures.normalTotal||0.0000001)*tStats.captures.weight + tStats.hold.normal[i]/(tStats.hold.normalTotal||0.0000001)*tStats.hold.weight + tStats.score2.normal[i]/(tStats.score2.normalTotal||0.0000001)*tStats.score2.weight; | |
value.d = tStats.prevent.normal[i]/(tStats.prevent.normalTotal||0.0000001)*tStats.prevent.weight + tStats.returns.normal[i]/(tStats.returns.normalTotal||0.0000001)*tStats.returns.weight + tStats.kd.normal[i]/(tStats.kd.normalTotal||0.0000001)*tStats.kd.weight; | |
tStats.offense.data.push(value.o); | |
tStats.defense.data.push(value.d); | |
tStats.offense.top.push({ name:value.name, value:value.o, team:value.team, self:value.self }); | |
tStats.defense.top.push({ name:value.name, value:value.d, team:value.team, self:value.self }); | |
if (value.team === 1) { | |
tStats.offense.red += value.o; | |
tStats.defense.red += value.d; | |
} else { | |
tStats.offense.blue += value.o; | |
tStats.defense.blue += value.d; | |
} | |
tStats.offense.total += value.o; | |
tStats.defense.total += value.d; | |
if (value.self) { | |
tStats.offense.self = value.o; | |
tStats.defense.self = value.d; | |
} | |
} | |
tStats.offense.top.sort(function(a, b) { | |
return (a.value < b.value ? 1 : a.value > b.value ? -1 : 0); | |
}); | |
tStats.defense.top.sort(function(a, b) { | |
return (a.value < b.value ? 1 : a.value > b.value ? -1 : 0); | |
}); | |
return tStats; | |
}; | |
function loadData() { | |
var data = $.extend(true, [], DWP_Selections.DWPSavedGames.value); | |
if (data.length > 0) { | |
var nowTime = new Date(); | |
var resetTime = new Date(); | |
resetTime.setHours(DWP_ResetHour, 0, 0); | |
var firstTime = new Date(parseInt(Date.parse(data[0].played))); | |
var difference = Date.parse(nowTime) - Date.parse(data[0].played); | |
nowTime = nowTime.toISOString(); | |
resetTime = resetTime.toISOString(); | |
firstTime = firstTime.toISOString(); | |
$('#DWP').append('<div id="DWP_NextReset" style="color:lightgreen; font-size:13px;"></div>'); | |
var resetData = checkReset(); | |
if (resetData) { | |
GM_setValue('ResetData', true); | |
$('#DWP_NextReset').append('<div style="color:deeppink; font-size:13px;">Data will reset when you next complete a game.</div>'); | |
} else { | |
var resetDate = GM_getValue('reset'); | |
GM_setValue('ResetData', false); | |
$('#DWP_NextReset').append('<div style="color:lightgreen; font-size:13px;">Next Reset: '+new Date(resetDate).toDateString()+' @ '+new Date(resetDate).toLocaleTimeString()+'</div>'); | |
if (DWP_NumberDays > 1) { | |
var diff = (resetDate - Date.now()) / 1000; | |
var toGo; | |
if (diff > 86400) { | |
toGo = Math.ceil(diff/60/60/24); | |
$('#DWP_NextReset').append('<div style="color:lightgreen; font-size:11px; font-style:italic;"> [' + (toGo === 1 ? 'tomorrow' : toGo + ' days to go') + ']</div>'); | |
} | |
} | |
} | |
if (GM_getValue('lastGameCheckDC', false)) { | |
var game = GM_getValue('lastGameCheckDC'); | |
if (game.hasOwnProperty('played')) { | |
var wasAFK = false; | |
if (document.URL.includes('err=afk')) { //probs afk'd the last game | |
wasAFK = true; | |
} | |
data.push( { outcome:3, played:new Date(game.played).toISOString(), mapName:game.mapName, mapAuthor:game.mapAuthor, gameMode:game.gameMode, serverName:game.serverName, afk:wasAFK } ); | |
DWP_Selections.DWPSavedGames.value = data; | |
GM_setValue('DWP_Selections', DWP_Selections); | |
} | |
} | |
for (var key=0, l=data.length; key<l; key++) { | |
data[key].gameNumber = key+1; //(data.length - key); | |
} | |
GM_setValue('allData', data); | |
GM_deleteValue('lastGameCheckDC'); | |
if ($('#DWP').length) { | |
showData(); | |
} | |
} else { | |
$('#DWP_Messages').append('No data for Daily Win % Timeline - go play some games!'); | |
$('#DWP').fadeIn(600); | |
} | |
} | |
function setTimelineCellHeights(Cell_Width) { | |
Cell_Width = Cell_Width || 1; | |
GM_addStyle('.dwp_win { display:inline-block; position:relative; height:10px; width:'+Cell_Width+'px; border-radius:2px; cursor:pointer; font-size:10px; text-shadow:none; color:#111; margin-left:1px; background:linear-gradient('+DWP_Selections.Win_Color.value+', #191); }'); | |
GM_addStyle('.dwp_loss { display:inline-block; position:relative; height:10px; width:'+Cell_Width+'px; border-radius:2px; cursor:pointer; font-size:10px; text-shadow:none; color:#111; margin-left:1px; background:linear-gradient('+DWP_Selections.Loss_Color.value+', #a22); }'); | |
GM_addStyle('.dwp_dc { display:inline-block; position:relative; height:10px; width:'+Cell_Width+'px; border-radius:2px; cursor:pointer; font-size:10px; text-shadow:none; color:#111; margin-left:1px; background:linear-gradient('+DWP_Selections.DC_Color.value+', #a80); }'); | |
GM_addStyle('.dwp_ssa { display:inline-block; position:relative; height:10px; width:'+Cell_Width+'px; border-radius:2px; cursor:pointer; font-size:10px; text-shadow:none; color:#111; margin-left:1px; background:linear-gradient(white, '+DWP_Selections.SSA_Color.value+'); }'); | |
GM_addStyle('.dwp_fsa { display:inline-block; position:relative; height:10px; width:'+Cell_Width+'px; border-radius:2px; cursor:pointer; font-size:10px; text-shadow:none; color:#111; margin-left:1px; background:linear-gradient('+DWP_Selections.FSA_Color.value+', white); }'); | |
GM_addStyle('.dwp_tie { display:inline-block; position:relative; height:10px; width:'+Cell_Width+'px; border-radius:2px; cursor:pointer; font-size:10px; text-shadow:none; color:#111; margin-left:1px; background:linear-gradient(#f90, #d60); }'); | |
GM_addStyle('.dwp_unknown { display:inline-block; position:relative; height:10px; width:'+Cell_Width+'px; border-radius:2px; cursor:pointer; font-size:10px; text-shadow:none; color:#111; margin-left:1px; background:'+DWP_Selections.Unknown_Color.value+'; }'); | |
} | |
var makeBar = function(title, elementName, redStat, blueStat) { | |
$('#'+elementName).append('<div id="'+elementName+'_'+title+'" class="'+elementName+'_Outer"></div>'); | |
$('#'+elementName+'_'+title).append('<div class="'+elementName+'_Title">'+title+'</div>'); | |
if (redStat > 0 || blueStat > 0) { | |
if (redStat > 0) $('#'+elementName+'_'+title+'').append('<div class="'+elementName+'_Red" style="width:'+redStat.toFixed(3)+'%; ">'+redStat.toFixed(1)+'%</div>'); | |
if (blueStat > 0) $('#'+elementName+'_'+title+'').append('<div class="'+elementName+'_Blue" style="width:'+blueStat.toFixed(3)+'%;">'+blueStat.toFixed(1)+'%</div>'); | |
$('#'+elementName+'_'+title+'').append('<div class="'+elementName+'_Mid">⟡</div>'); | |
} else { | |
$('#'+elementName+'_'+title+'').append('<div style="width:100%; text-align:center; font-size:10px;">-</div>'); // border:1px dashed rgba(255,255,255,0.2); | |
} | |
}; | |
function makeEOGMessage(result, team, redScore, blueScore, spectator) { | |
let eogMessage = ''; | |
if (!result) { | |
if (redScore === blueScore) result = 'tie'; | |
else if ((redScore > blueScore && team === 1) || (blueScore > redScore && team === 2)) result = 'win'; | |
else result = 'loss'; | |
} | |
if (result === 'win') { | |
if (team === 1) eogMessage = 'Score ' + redScore + ':' + blueScore + (spectator ? ' | Red Won (Spec)' : ' | We (Red) Won!'); | |
else eogMessage = 'Score ' + redScore + ':' + blueScore + (spectator ? ' | Blue Won (Spec)' : ' | We (Blue) Won!'); | |
} else if (result === 'loss') { | |
if (team === 1) eogMessage = 'Score ' + redScore + ':' + blueScore + (spectator ? ' | Red Lost (Spec)' : ' | We (Red) Lost :('); | |
else eogMessage = 'Score ' + redScore + ':' + blueScore + (spectator ? ' | Blue Lost (Spec)' : ' | We (Blue) Lost :('); | |
} else if (result === 'tie') { | |
if (team === 1) eogMessage = 'Score ' + redScore + ':' + blueScore + (spectator ? ' | Tie! (Spec)' : ' | Tie! We were on Red'); | |
else eogMessage = 'Score ' + redScore + ':' + blueScore + (spectator ? ' | Tie! (Spec)' : ' | Tie! We were on Blue'); | |
} | |
return eogMessage; | |
} | |
function setColors(result) { | |
if (!result) { | |
let game = GM_getValue('gameData'); | |
result = game.spectator ? 'spectator' : game.result; | |
} | |
let scoreboardTransparency = 1; | |
if (result === 'spectator') { | |
resultColor = '#ddd'; | |
resultBackground = 'linear-gradient(135deg, rgba(34, 34, 34, '+scoreboardTransparency+') 17%, rgba(102, 102, 102, '+scoreboardTransparency+') 36%, rgba(17, 17, 17, '+scoreboardTransparency+') 87%)'; | |
resultBackgroundHeader = 'linear-gradient(135deg, rgba(51, 51, 51, '+scoreboardTransparency+') 0%, rgba(68, 68, 68, '+scoreboardTransparency+') 30%, rgba(51, 51, 51, '+scoreboardTransparency+') 50%, rgba(102, 102, 102, '+scoreboardTransparency+') 80%, rgba(34, 34, 34, '+scoreboardTransparency+') 100%)'; | |
} else if (result === 'win') { | |
resultColor = '#0b0'; | |
resultBackground = 'linear-gradient(135deg, rgba(0, 34, 0, '+scoreboardTransparency+') 17%, rgba(51, 119, 51, '+scoreboardTransparency+') 36%, rgba(0, 17, 0, '+scoreboardTransparency+') 87%)'; | |
resultBackgroundHeader = 'linear-gradient(135deg, rgba(0, 51, 0, '+scoreboardTransparency+') 0%, rgba(17, 85, 17, '+scoreboardTransparency+') 30%, rgba(0, 51, 0, '+scoreboardTransparency+') 50%, rgba(34, 102, 34, '+scoreboardTransparency+') 80%, rgba(0, 34, 0, '+scoreboardTransparency+') 100%)'; | |
} else if (result === 'loss') { | |
resultColor = '#c00'; | |
resultBackground = 'linear-gradient(135deg, rgba(34, 0, 0, '+scoreboardTransparency+') 17%, rgba(119, 51, 51, '+scoreboardTransparency+') 36%, rgba(17, 0, 0, '+scoreboardTransparency+') 87%)'; | |
resultBackgroundHeader = 'linear-gradient(135deg, rgba(51, 0, 0, '+scoreboardTransparency+') 0%, rgba(85, 17, 17, '+scoreboardTransparency+') 30%, rgba(51, 0, 0, '+scoreboardTransparency+') 50%, rgba(102, 34, 34, '+scoreboardTransparency+') 80%, rgba(34, 0, 0, '+scoreboardTransparency+') 100%)'; | |
} else if (result === 'tie') { | |
resultColor = '#fc0'; | |
resultBackground = 'linear-gradient(135deg, rgba(51, 51, 0, '+scoreboardTransparency+') 17%, rgba(119, 119, 51, '+scoreboardTransparency+') 36%, rgba(34, 34, 0, '+scoreboardTransparency+') 87%)'; | |
resultBackgroundHeader = 'linear-gradient(135deg, rgba(51, 51, 0, '+scoreboardTransparency+') 0%, rgba(85, 85, 17, '+scoreboardTransparency+') 30%, rgba(51, 51, 0, '+scoreboardTransparency+') 50%, rgba(102, 102, 34, '+scoreboardTransparency+') 80%, rgba(34, 34, 0, '+scoreboardTransparency+') 100%)'; | |
} | |
} | |
function showGameInfo(gameNumber, top, left) { | |
if (!top || top === undefined || top === void 0) top = 0; | |
if (!left || left === undefined || left === void 0) left = 0; | |
var data = GM_getValue('allData', []); | |
var game = data[data.length - gameNumber - 1]; | |
var text = '<div style="width:500px; margin:-20px auto 0; padding:5px 0; background:linear-gradient(rgba(0,0,0,1),rgba(0,0,0,0.1)); border:1px outset #bbb; border-radius:10px;">'; | |
if (game.outcome === 1) { | |
setColors('win'); | |
if (game.saved === 2) { | |
text += '<div style="font-weight:bold; color:'+DWP_Selections.Win_Color.value+'">Game #' + game.gameNumber + ': Win - Successful Save Attempt! (' + game.redScore + ':' + game.blueScore + ')</div>'; | |
} else { | |
text += '<div style="font-weight:bold; color:'+DWP_Selections.Win_Color.value+'">Game #' + game.gameNumber + ': Win (' + game.redScore + ':' + game.blueScore + ')</div>'; | |
} | |
} else if (game.outcome === 2) { | |
setColors('loss'); | |
text += '<div style="font-weight:bold; color:'+DWP_Selections.Loss_Color.value+'">Game #' + game.gameNumber + ': Loss (' + game.redScore + ':' + game.blueScore + ')</div>'; | |
} else if (game.outcome === 3) { | |
setColors('spectator'); | |
text += '<div style="font-weight:bold; color:'+DWP_Selections.DC_Color.value+'">Game #' + game.gameNumber + ': DC' + (game.afk ? '/AFK' : '') + ' (Loss)</div>' + | |
'<div style="font-weight:bold">' + game.mapName + ' by ' + game.mapAuthor + ' (' + getUsefulText(game.gameMode, 'gamemode') + ')</div>' + | |
'<div>' + new Date(parseInt(Date.parse(game.played))).toLocaleTimeString() + ' (' + new Date(parseInt(Date.parse(game.played))).toDateString() + (game.serverName ? ') on ' + game.serverName : ')') + '</div>'; | |
$('#DWP_GameInfo').html(text).css({top:top, left:left}); | |
$('#DWP_GameInfo').show(0); | |
return; | |
} else if (game.outcome === 4) { //Save Attempt | |
if (game.saved === 1) { //Unsuccessful | |
setColors('loss'); | |
text += '<div style="font-weight:bold; color:'+DWP_Selections.FSA_Color.value+'">Game #' + game.gameNumber + ': Unsuccessful Save Attempt (' + game.redScore + ':' + game.blueScore + ')</div>'; | |
} else { | |
setColors('win'); | |
} | |
} else if (game.outcome === 5) { //Tie | |
setColors('tie'); | |
text += '<div style="font-weight:bold; color:'+DWP_Selections.Tie_Color.value+'">Game #' + game.gameNumber + ': Tie/Loss (' + game.redScore + ':' + game.blueScore + ')</div>'; | |
} else { //Unknown | |
text += '<div>Unknown Result!</div>'; | |
} | |
var playedFor = (game.timePlayed / game.fullGameLength * 100).toFixed(2); | |
if (playedFor > 100) playedFor = 100; | |
text += '<div style="font-weight:bold">' + game.mapName + ' by ' + game.mapAuthor + ' (' + getUsefulText(game.gameMode, 'gamemode') + ')</div>' + | |
'<div>' + new Date(parseInt(Date.parse(game.played))).toLocaleTimeString() + ' (' + new Date(parseInt(Date.parse(game.played))).toDateString() + (game.serverName ? ') on ' + game.serverName : ')') + '</div>' + | |
'<div style="font-style:italic">You played for ' + secondsToHMS(game.timePlayed) + ' ('+ playedFor + '%)</div>'; | |
text += '</div>'; | |
let tStats = makeTotalStats(game.playersData); | |
var medalColor1 = 'linear-gradient(35deg, #ff0, #f70)'; | |
var medalColor2 = 'linear-gradient(35deg, #777, #eee)'; | |
var medalColor3 = 'linear-gradient(35deg, #c13f08, #af824b)'; | |
var getRank = function(stat) { | |
if (tStats.hasOwnProperty(stat)) { | |
if (tStats[stat].hasOwnProperty('rank') && tStats[stat].rank) { | |
return tStats[stat].rank; | |
} else if (tStats[stat].hasOwnProperty('data')) { | |
let sorted = tStats[stat].data.slice(); | |
sorted.sort(function(a, b) { | |
return b - a; | |
}); | |
if (stat === 'pops') sorted.reverse(); //pops are a negative stat (lower is better) | |
let rank = sorted.indexOf(tStats[stat].self) + 1; | |
tStats[stat].rank = rank; | |
return rank; | |
} | |
} | |
}; | |
var getMedalColor = function(pos) { | |
if (pos === 1) return medalColor1; | |
else if (pos === 2) return medalColor2; | |
else if (pos === 3) return medalColor3; | |
else return 'rgba(0,0,0, 0.1)'; | |
}; | |
text += '<table id="DWP_GameInfoScoreboard" style="margin:5px 0"><tr id="DWP_GameInfoScoreboard_Header"><td></td><td>Sc</td><td>Ta</td><td>Po</td><td>Gr</td><td>Dr</td><td>Ho</td><td>Ca</td><td>Pr</td><td>Re</td><td>Su</td><td>PU</td><td>Pt</td><td class="DWP_KDCol">KD</td><td>O</td><td>D</td><tr>'; | |
$.each(game.playersData, function(key, value) { | |
let a = value.o || 0.0000001; | |
let b = value.d || 0.0000001; | |
text += '<tr class="DWP_PlayerRow'+(value.self === true ? ' DWP_GameInfo_HighlightSelf' : '')+'">' + | |
'<td class="'+(value.team === 1 ? 'DWP_RedTeamColor' : 'DWP_BlueTeamColor')+'">'+(value.auth ? '<span style="color:lime">✔</span>' : '')+value.name+'</td>' + | |
'<td data-raw="'+value.score+'">'+value.score+'</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+'">'+secondsToHMS(value.hold)+'</td>' + | |
'<td data-raw="'+value.captures+'">'+value.captures+'</td>' + | |
'<td data-raw="'+value.prevent+'">'+secondsToHMS(value.prevent)+'</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>' + //(value.powerups/game.potentialPowerups*100).toFixed(0)+'% | |
'<td data-raw="'+value.points+'">'+(value.points ? value.points : '-')+'</td>' + | |
'<td data-raw="'+value.kd+'" class="DWP_KDCol">'+ value.kd.toFixed(2) +'</td>' + | |
'<td data-raw="'+a+'">'+ a.toFixed(1) +'</td>' + | |
'<td data-raw="'+b+'">'+ b.toFixed(1) +'</td>' + | |
'<tr>'; | |
}); | |
text += '<tr id="TPSR_TR_Divider"><td colspan="16"><hr style="margin:1px; border-top:1px solid #ddd;"></td></tr>'; | |
text += '<tr style="background:linear-gradient(#522, #f55);"><td style="text-align:right">Red Total:</td><td'+(tStats.score.red>tStats.score.blue?' class="DWP_Max_Red"':'')+'>'+tStats.score.red+'</td><td'+(tStats.tags.red>tStats.tags.blue?' class="DWP_Max_Red"':'')+'>'+tStats.tags.red+'</td><td'+(tStats.pops.red>tStats.pops.blue?' class="DWP_Max_Red"':'')+'>'+tStats.pops.red+'</td><td'+(tStats.grabs.red>tStats.grabs.blue?' class="DWP_Max_Red"':'')+'>'+tStats.grabs.red+'</td><td'+(tStats.drops.red>tStats.drops.blue?' class="DWP_Max_Red"':'')+'>'+tStats.drops.red+'</td><td'+(tStats.hold.red>tStats.hold.blue?' class="DWP_Max_Red"':'')+'>'+secondsToHMS(tStats.hold.red)+'</td><td'+(tStats.captures.red>tStats.captures.blue?' class="DWP_Max_Red"':'')+'>'+tStats.captures.red+'</td><td'+(tStats.prevent.red>tStats.prevent.blue?' class="DWP_Max_Red"':'')+'>'+secondsToHMS(tStats.prevent.red)+'</td><td'+(tStats.returns.red>tStats.returns.blue?' class="DWP_Max_Red"':'')+'>'+tStats.returns.red+'</td><td'+(tStats.support.red>tStats.support.blue?' class="DWP_Max_Red"':'')+'>'+tStats.support.red+'</td><td'+(tStats.powerups.red>tStats.powerups.blue?' class="DWP_Max_Red"':'')+'>'+tStats.powerups.red+'</td><td'+(tStats.points.red>tStats.points.blue?' class="DWP_Max_Red"':'')+'>'+(tStats.points.red ? tStats.points.red : '-')+'</td>'; | |
text += '<td class="DWP_KDCol"'+(tStats.kd.red>tStats.kd.blue?' TPSR_Max_Red':'')+'">'+(tStats.pops.red ? (tStats.kd.red).toFixed(2) : tStats.tags.red.toFixed(2))+'</td><td'+(tStats.offense.red>tStats.offense.blue?' class="TPSR_Max_Red"':'')+'>'+(tStats.offense.red).toFixed(1)+'</td>' + '<td'+(tStats.defense.red>tStats.defense.blue?' class="TPSR_Max_Red"':'')+'>'+(tStats.defense.red).toFixed(1)+'</td></tr>'; | |
text += '<tr style="background:linear-gradient(#66c, #225);"><td style="text-align:right">Blue Total:</td><td'+(tStats.score.blue>tStats.score.red?' class="DWP_Max_Blue"':'')+'>'+tStats.score.blue+'</td><td'+(tStats.tags.blue>tStats.tags.red?' class="DWP_Max_Blue"':'')+'>'+tStats.tags.blue+'</td><td'+(tStats.pops.blue>tStats.pops.red?' class="DWP_Max_Blue"':'')+'>'+tStats.pops.blue+'</td><td'+(tStats.grabs.blue>tStats.grabs.red?' class="DWP_Max_Blue"':'')+'>'+tStats.grabs.blue+'</td><td'+(tStats.drops.blue>tStats.drops.red?' class="DWP_Max_Blue"':'')+'>'+tStats.drops.blue+'</td><td'+(tStats.hold.blue>tStats.hold.red?' class="DWP_Max_Blue"':'')+'>'+secondsToHMS(tStats.hold.blue)+'</td><td'+(tStats.captures.blue>tStats.captures.red?' class="DWP_Max_Blue"':'')+'>'+tStats.captures.blue+'</td><td'+(tStats.prevent.blue>tStats.prevent.red?' class="DWP_Max_Blue"':'')+'>'+secondsToHMS(tStats.prevent.blue)+'</td><td'+(tStats.returns.blue>tStats.returns.red?' class="DWP_Max_Blue"':'')+'>'+tStats.returns.blue+'</td><td'+(tStats.support.blue>tStats.support.red?' class="DWP_Max_Blue"':'')+'>'+tStats.support.blue+'</td><td'+(tStats.powerups.blue>tStats.powerups.red?' class="DWP_Max_Blue"':'')+'>'+tStats.powerups.blue+'</td><td'+(tStats.points.blue>tStats.points.red?' class="DWP_Max_Blue"':'')+'>'+(tStats.points.blue ? tStats.points.blue : '-')+'</td>'; | |
text += '<td class="DWP_KDCol"'+(tStats.kd.blue>tStats.kd.red?' TPSR_Max_Blue':'')+'">'+(tStats.pops.blue ? (tStats.kd.blue).toFixed(2) : tStats.tags.blue.toFixed(2))+'</td><td'+(tStats.offense.blue>tStats.offense.red?' class="TPSR_Max_Blue"':'')+'>'+(tStats.offense.blue).toFixed(1)+'</td><td'+(tStats.defense.blue>tStats.defense.red?' class="TPSR_Max_Blue"':'')+'>'+(tStats.defense.blue).toFixed(1)+'</td></tr>'; | |
text += '</table>'; | |
setTimeout(function() { | |
var $table = $('#DWP_GameInfoScoreboard'), $column, prevMax; | |
for (var i=2; i<=16; i++) { | |
$column = $('#DWP_GameInfoScoreboard tr:gt(0) td:nth-child('+i+')'); | |
prevMax = 0; | |
$($column).each(function(k, v) { | |
if ($(this).data('raw') > prevMax) { | |
$($column).removeClass('DWP_Max'); | |
$(this).addClass('DWP_Max'); | |
prevMax = $(this).data('raw'); | |
} else if ($(this).data('raw') === prevMax) { | |
$(this).addClass('DWP_Max'); | |
} | |
}); | |
} | |
}, 50); | |
text += '<div id="DWP_Bottom_Container"><div id="DWP_Medals_Container"></div><div id="DWP_Bars"></div></div>'; | |
text += '<div id="DWP_EOG_Message">' + makeEOGMessage(game.result, game.team, game.redScore, game.blueScore, game.spectator) + '</div>'; | |
$('#DWP_GameInfo').css({'background':resultBackground}).html(text).css({top:top, left:left}); | |
$('#DWP_GameInfo').show(0); | |
//Bars... | |
makeBar('Offense', 'DWP_Bars', (tStats.offense.red/tStats.offense.total*100), (tStats.offense.blue/tStats.offense.total*100)); | |
makeBar('Defense', 'DWP_Bars', (tStats.defense.red/tStats.defense.total*100), (tStats.defense.blue/tStats.defense.total*100)); | |
makeBar('Hold', 'DWP_Bars', (tStats.hold.red/tStats.hold.total*100), (tStats.hold.blue/tStats.hold.total*100)); | |
makeBar('Prevent', 'DWP_Bars', (tStats.prevent.red/tStats.prevent.total*100), (tStats.prevent.blue/tStats.prevent.total*100)); | |
makeBar('Returns', 'DWP_Bars', (tStats.returns.red/tStats.returns.total*100), (tStats.returns.blue/tStats.returns.total*100)); | |
makeBar('Power-Ups', 'DWP_Bars', (tStats.powerups.red/tStats.powerups.total*100), (tStats.powerups.blue/tStats.powerups.total*100)); | |
makeBar('KD', 'DWP_Bars', (tStats.kd.red/tStats.kd.total*100), (tStats.kd.blue/tStats.kd.total*100)); | |
//Medals... | |
let tStats_keys = Object.keys(tStats); | |
let statsToShowFrom = [ 'tags', 'pops', 'grabs', 'hold', 'prevent', 'returns', 'support', 'powerups', 'kd', 'offense', 'defense' ]; | |
let pos = getRank('score'); | |
let color = getMedalColor(pos); | |
$('#DWP_Medals_Container').empty().show(); | |
if (pos) { | |
$('#DWP_Medals_Container').append('<div style="font-size:42px; box-shadow:0px 0px 10px 1px white; border:1px outset #999; border-radius:50%; width:90px; height:90px; padding-bottom:6px; display:flex; align-items:center; justify-content:center; background:'+color+';">'+ordinalSuffix(pos)+'</div>'); | |
$('#DWP_Medals_Container').append('<div id="DWP_Medals"></div>'); | |
var statsToShow = []; | |
for (i=0; i<tStats_keys.length; i++) { | |
if (statsToShowFrom.indexOf(tStats_keys[i]) > -1) { | |
pos = getRank(tStats_keys[i]); | |
if (pos && pos <= 3) { | |
statsToShow.push({ stat:tStats_keys[i], pos:pos }); | |
} | |
} | |
} | |
statsToShow.sort(function(a, b) { | |
return (a.pos > b.pos ? 1 : a.pos < b.pos ? -1 : 0); | |
}); | |
for (i=0; i<5 && i<statsToShow.length; i++) { | |
color = getMedalColor(statsToShow[i].pos); | |
let statName = statsToShow[i].stat; | |
if (statName === 'kd') statName = 'K/D'; | |
$('#DWP_Medals').append('<div class="DWP_Medals_Stats"><div class="DWP_Medals_Stat" style="background:'+color+';">'+ordinalSuffix(statsToShow[i].pos)+'</div><div style="text-transform:capitalize;">'+statName+'</div></div>'); | |
} | |
//$('#TPSR_BottomLeft').css({ 'border':'1px dashed #fff', 'border-radius':'5px', 'padding':'5px 0', 'margin':'0 5px 0 0px' }); | |
} | |
} | |
/************************************************************************************/ | |
// Main Timeline & Streaks... | |
/************************************************************************************/ | |
function showData() { | |
var timeline_MaxWidth = 760; | |
var cellWidth = 20; //This value will adjust (smaller) according to MaxGames & Timeline_MaxWidth. Default=10 | |
var i, j; | |
var asbp = 0, thisGamePos = 0; | |
var maps = {}; | |
var data = GM_getValue('allData', []); | |
var totals = {'all': { win:0, loss:0, dc:0, ssa:0, fsa:0, tie:0, timePlayed:0, asbp:0 }, | |
'ctf': { win:0, loss:0, dc:0, ssa:0, fsa:0, tie:0, timePlayed:0, asbp:0 }, | |
'nf': { win:0, loss:0, dc:0, ssa:0, fsa:0, tie:0, timePlayed:0, asbp:0 }, | |
'red': { win:0, loss:0, dc:0, ssa:0, fsa:0, tie:0, timePlayed:0, asbp:0 }, | |
'blue': { win:0, loss:0, dc:0, ssa:0, fsa:0, tie:0, timePlayed:0, asbp:0 }, | |
'mystats': { tags:0, pops:0, grabs:0, drops:0, hold:0, captures:0, prevent:0, returns:0, support:0, powerups:0, timePlayed:0 }, | |
'allstats': { tags:0, pops:0, grabs:0, drops:0, hold:0, captures:0, prevent:0, returns:0, support:0, powerups:0, timePlayed:0, count:0 }, | |
'streaks': { win:0, loss:0, temp_win:0, temp_loss:0, last_win:0, last_loss:0 } | |
}; | |
if ( ($('#DWP').width() < timeline_MaxWidth) && ($('#DWP').width() > 500) ) timeline_MaxWidth = $('#DWP').width(); | |
var newCellWidth = Math.floor((timeline_MaxWidth - 26) / data.length); | |
if (newCellWidth < cellWidth) cellWidth = newCellWidth - 1; | |
if (cellWidth <= 0) cellWidth = 1; | |
var totalPotentialPowerups = 0; | |
var NF_Marker = '<div title="Neutral Flag Game" style="position:absolute; width:'+(cellWidth/2)+'px; margin:0 '+(cellWidth/4)+'px; height:1px; bottom:-2px; background:#ccc"></div>'; | |
$.each(data, function(key, value) { | |
if (value.outcome !== 3) { | |
thisGamePos = ''; | |
totalPotentialPowerups += value.potentialPowerups; | |
$.each(totals.mystats, function(key1, value1) { | |
totals.mystats[key1] += value[key1]; | |
if (key1 === 'timePlayed') { | |
totals.all.timePlayed += value[key1]; | |
if (value.gameMode === 1) totals.ctf.timePlayed += value[key1]; | |
else totals.nf.timePlayed += value[key1]; | |
if (value.team === 1) totals.red.timePlayed += value[key1]; | |
else totals.blue.timePlayed += value[key1]; | |
} | |
}); | |
maps[value.mapName] || ( maps[value.mapName] = { | |
author: value.mapAuthor, | |
count: 0, | |
win: 0, | |
fsa: 0, | |
winp: 0, | |
timePlayed: 0, | |
asbp: 0, | |
red: { count:0, win:0, timePlayed:0, asbp:0 }, | |
blue: { count:0, win:0, timePlayed:0, asbp:0 }, | |
} ); | |
maps[value.mapName].count++; | |
maps[value.mapName].timePlayed += value.timePlayed; | |
maps[value.mapName][value.team === 1 ? 'red' : 'blue'].count++; | |
maps[value.mapName][value.team === 1 ? 'red' : 'blue'].timePlayed += value.timePlayed; | |
$.each(value.playersData, function(key1, value1) { | |
if (value1.self) { | |
if (cellWidth >= 10) thisGamePos = key1+1; | |
asbp += key1+1; | |
totals.all.asbp += key1+1; | |
totals[value.gameMode === 1 ? 'ctf' : 'nf'].asbp += key1+1; | |
totals[value.team === 1 ? 'red' : 'blue'].asbp += key1+1; | |
maps[value.mapName].asbp += key1+1; | |
maps[value.mapName][value.team === 1 ? 'red' : 'blue'].asbp += key1+1; | |
} | |
if (value1.tags + value1.pops + value1.grabs + (value1.captures*10) + value1.prevent + value1.support > 10) { //exclude lowly players (probably very late joiners) | |
totals.allstats.tags += value1.tags; | |
totals.allstats.pops += value1.pops; | |
totals.allstats.grabs += value1.grabs; | |
totals.allstats.drops += value1.drops; | |
totals.allstats.hold += value1.hold; | |
totals.allstats.captures += value1.captures; | |
totals.allstats.prevent += value1.prevent; | |
totals.allstats.returns += value1.returns; | |
totals.allstats.support += value1.support; | |
totals.allstats.powerups += value1.powerups; | |
totals.allstats.score += value1.score; | |
totals.allstats.points += value1.points; | |
totals.allstats.count++; | |
} | |
}); | |
} else { | |
if (cellWidth >= 10) thisGamePos = '×'; | |
} | |
switch (value.outcome) { | |
case 1: //win | |
if (value.saved === 2) { | |
totals.all.ssa++; | |
totals[value.team===1?'red':'blue'].ssa++; | |
if (value.gameMode === 1) { | |
totals.ctf.ssa++; | |
} else if (value.gameMode === 2) { | |
totals.nf.ssa++; | |
} | |
$DWP_Timeline.append('<div class="dwp_ssa dwp_game" data-gamenumber="' + (data.length-key) + '">'+thisGamePos+(value.gameMode === 2 ? NF_Marker : '')+'</div>'); | |
} else { | |
totals.all.win++; | |
totals[value.team===1?'red':'blue'].win++; | |
if (value.gameMode === 1) { | |
totals.ctf.win++; | |
} else if (value.gameMode === 2) { | |
totals.nf.win++; | |
} | |
$DWP_Timeline.append('<div class="dwp_win dwp_game" data-gamenumber="' + (data.length-key) + '">'+thisGamePos+(value.gameMode === 2 ? NF_Marker : '')+'</div>'); | |
} | |
maps[value.mapName].win++; | |
maps[value.mapName][value.team === 1 ? 'red' : 'blue'].win++; | |
//streak... | |
i=key; | |
while ( (i > 0) && ((data[i-1].outcome === 4)&&(data[i-1].saved === 1)) ) { //unsuccessful saves shouldn't break a streak! | |
i--; | |
} | |
if ( (totals.streaks.temp_win === 0) || ((i > 0) && ((data[i-1].outcome === 1)) ) ) totals.streaks.temp_win++; | |
if (totals.streaks.temp_win > totals.streaks.win) totals.streaks.win = totals.streaks.temp_win; | |
totals.streaks.temp_loss = 0; | |
if (totals.streaks.temp_win > 0) totals.streaks.last_win = totals.streaks.temp_win; | |
break; | |
case 2: //loss | |
totals.all.loss++; | |
totals[value.team===1?'red':'blue'].loss++; | |
if (value.gameMode === 1) { | |
totals.ctf.loss++; | |
} else if (value.gameMode === 2) { | |
totals.nf.loss++; | |
} | |
$DWP_Timeline.append('<div class="dwp_loss dwp_game" data-gamenumber="' + (data.length-key) + '">'+thisGamePos+(value.gameMode === 2 ? NF_Marker : '')+'</div>'); | |
//streak... | |
i=key; | |
while ( (i > 0) && ((data[i-1].outcome === 4)&&(data[i-1].saved === 1)) ) { | |
i--; | |
} | |
if ( (totals.streaks.temp_loss === 0) || ((i > 0) && ((data[i-1].outcome === 2) || (data[i-1].outcome === 3) || (data[i-1].outcome === 5)) ) ) totals.streaks.temp_loss++; | |
if (totals.streaks.temp_loss > totals.streaks.loss) totals.streaks.loss = totals.streaks.temp_loss; | |
totals.streaks.temp_win = 0; | |
if (totals.streaks.temp_loss > 0) totals.streaks.last_loss = totals.streaks.temp_loss; | |
break; | |
case 3: //dc | |
totals.all.dc++; | |
totals[value.team===1?'red':'blue'].dc++; | |
if (value.gameMode === 1) { | |
totals.ctf.dc++; | |
} else if (value.gameMode === 2) { | |
totals.nf.dc++; | |
} | |
$DWP_Timeline.append('<div class="dwp_dc dwp_game" data-gamenumber="' + (data.length-key) + '">'+thisGamePos+(value.gameMode === 2 ? NF_Marker : '')+'</div>'); | |
//streak... | |
i=key; | |
while ( (i > 0) && ((data[i-1].outcome === 4)&&(data[i-1].saved === 1)) ) { | |
i--; | |
} | |
if ( (totals.streaks.temp_loss === 0) || ((i > 0) && ((data[i-1].outcome === 2) || (data[i-1].outcome === 3) || (data[i-1].outcome === 5)) ) ) totals.streaks.temp_loss++; | |
if (totals.streaks.temp_loss > totals.streaks.loss) totals.streaks.loss = totals.streaks.temp_loss; | |
totals.streaks.temp_win = 0; | |
if (totals.streaks.temp_loss > 0) totals.streaks.last_loss = totals.streaks.temp_loss; | |
break; | |
case 4: //save attempt | |
if (value.saved === 1) { //failed save attempt... | |
totals.all.fsa++; | |
totals[value.team===1?'red':'blue'].fsa++; | |
maps[value.mapName].fsa++; | |
if (value.gameMode === 1) { | |
totals.ctf.fsa++; | |
} else if (value.gameMode === 2) { | |
totals.nf.fsa++; | |
} | |
$DWP_Timeline.append('<div class="dwp_fsa dwp_game" data-gamenumber="' + (data.length-key) + '">'+thisGamePos+(value.gameMode === 2 ? NF_Marker : '')+'</div>'); | |
} | |
break; | |
case 5: //tie | |
totals.all.tie++; | |
totals[value.team===1?'red':'blue'].tie++; | |
if (value.gameMode === 1) { | |
totals.ctf.tie++; | |
} else if (value.gameMode === 2) { | |
totals.nf.tie++; | |
} | |
$DWP_Timeline.append('<div class="dwp_tie dwp_game" data-gamenumber="' + (data.length-key) + '">'+thisGamePos+(value.gameMode === 2 ? NF_Marker : '')+'</div>'); | |
//streak... | |
i=key; | |
while ( (i > 0) && ((data[i-1].outcome === 4)&&(data[i-1].saved === 1)) ) { | |
i--; | |
} | |
if ( (totals.streaks.temp_loss === 0) || ((i > 0) && ((data[i-1].outcome === 2) || (data[i-1].outcome === 3) || (data[i-1].outcome === 5)) ) ) totals.streaks.temp_loss++; | |
if (totals.streaks.temp_loss > totals.streaks.loss) totals.streaks.loss = totals.streaks.temp_loss; | |
totals.streaks.temp_win = 0; | |
if (totals.streaks.temp_loss > 0) totals.streaks.last_loss = totals.streaks.temp_loss; | |
break; | |
default: //just in case! | |
$DWP_Timeline.append('<div class="dwp_unknown" data-gamenumber="' + (data.length-key) + '">'+thisGamePos+(value.gameMode === 2 ? NF_Marker : '')+'</div>'); | |
break; | |
} | |
}); | |
setTimelineCellHeights(cellWidth); | |
//Win % Stats... | |
var mostPlayedMap, mostPlayedMapCount=0, mostPlayedMapCountWin=0, mostPlayedMapCountFSA=0; | |
var currentWinPC = ((totals.all.win+totals.all.ssa) / (totals.all.win+totals.all.ssa + totals.all.loss+totals.all.dc+totals.all.tie) * 100).toFixed(2); | |
var totalGames = data.length; | |
var totalCTF = (totals.ctf.win+totals.ctf.ssa + totals.ctf.loss+totals.ctf.dc+totals.ctf.tie); | |
var totalNF = (totals.nf.win+totals.nf.ssa + totals.nf.loss+totals.nf.dc+totals.nf.tie); | |
var CTFWinPC = (totalCTF === 0 ? 0 : + ((totals.ctf.win+totals.ctf.ssa) / totalCTF * 100)); | |
var CTFWinPC_Text = (totalCTF === 0 ? '-' : + CTFWinPC.toFixed(2) + '%'); | |
var NFWinPC = (totalNF === 0 ? 0 : + ((totals.nf.win+totals.nf.ssa) / totalNF * 100)); | |
var NFWinPC_Text = (totalNF === 0 ? '-' : + NFWinPC.toFixed(2) + '%'); | |
var totalRed = (totals.red.win+totals.red.ssa + totals.red.loss+totals.red.dc+totals.red.tie); | |
var totalBlue = (totals.blue.win+totals.blue.ssa + totals.blue.loss+totals.blue.dc+totals.blue.tie); | |
var RedWinPC = (totalRed === 0 ? 0 : + ((totals.red.win+totals.red.ssa) / totalRed * 100)); | |
var RedWinPC_Text = (totalRed === 0 ? '-' : + RedWinPC.toFixed(2) + '%'); | |
var BlueWinPC = (totalBlue === 0 ? 0 : ((totals.blue.win+totals.blue.ssa) / totalBlue * 100)); | |
var BlueWinPC_Text = (totalBlue === 0 ? '-' : BlueWinPC.toFixed(2) + '%'); | |
$.each(maps, function(key, value) { | |
if (value.count >= mostPlayedMapCount) { | |
mostPlayedMapCount = value.count; | |
mostPlayedMap = key; | |
} | |
}); | |
$.each(data, function(key, value) { | |
if (value.mapName === mostPlayedMap) { | |
if (data[key].outcome === 1) { | |
mostPlayedMapCountWin++; | |
} else { | |
if (data[key].outcome === 4 && data[key].saved) { | |
mostPlayedMapCountFSA++; | |
} | |
} | |
} | |
}); | |
$('#DWP_Messages').append('<table id="DWP_Win"><tr><th></th><th style="border-right:1px solid #999">All</th><th>CTF</th><th>NF</th><th>Red</th><th>Blue</th></tr></table>'); | |
$('#DWP_Win').append('<tr><th class="DWP_Row_Header"># Games:</th><td>'+data.length+'</td><td>'+(totalCTF+totals.ctf.fsa)+' ('+((totalCTF+totals.ctf.fsa) / data.length * 100).toFixed(1)+'%)</td><td>'+(totalNF+totals.nf.fsa)+' ('+((totalNF+totals.nf.fsa) / data.length * 100).toFixed(1)+'%)</td><td>'+(totalRed+totals.red.fsa)+' ('+((totalRed+totals.red.fsa) / data.length * 100).toFixed(1)+'%)</td><td>'+(totalBlue+totals.blue.fsa)+' ('+((totalBlue+totals.blue.fsa) / data.length * 100).toFixed(1)+'%)</td></tr>'); | |
$('#DWP_Win').append('<tr><th class="DWP_Row_Header">Win %:</th><td style="color:#3b3">'+currentWinPC+'%</td><td'+(CTFWinPC > NFWinPC ? ' class="DWP_Highlight"' : '')+'>'+CTFWinPC_Text+'</td><td'+(NFWinPC > CTFWinPC ? ' class="DWP_Highlight"' : '')+'>'+NFWinPC_Text+'</td><td'+(RedWinPC > BlueWinPC ? ' class="DWP_Highlight"' : '')+'>'+RedWinPC_Text+'</td><td'+(BlueWinPC > RedWinPC ? ' class="DWP_Highlight"' : '')+'>'+BlueWinPC_Text+'</td></tr>'); | |
$('#DWP_Win').append('<tr><th class="DWP_Row_Header" title="Average Game Length">Ave Time:</th><td title="Total: '+secondsToHMS(totals.mystats.timePlayed)+'">'+secondsToHMS(totals.mystats.timePlayed / data.length)+'</td><td title="Total: '+secondsToHMS(totals.ctf.timePlayed)+'">'+(totalCTF === 0 ? '-' : secondsToHMS(totals.ctf.timePlayed / totalCTF))+'</td><td title="Total: '+secondsToHMS(totals.nf.timePlayed)+'">'+(totalNF === 0 ? '-' : secondsToHMS(totals.nf.timePlayed / totalNF))+'</td><td title="Total: '+secondsToHMS(totals.red.timePlayed)+'">'+(totalRed === 0 ? '-' : secondsToHMS(totals.red.timePlayed / totalRed))+'</td><td title="Total: '+secondsToHMS(totals.blue.timePlayed)+'">'+(totalBlue === 0 ? '-' : secondsToHMS(totals.blue.timePlayed / totalBlue))+'</td></tr>'); | |
$('#DWP_Win').append('<tr><th class="DWP_Row_Header" title="Average Scoreboard Position">ASBP:</th><td>'+(totals.all.asbp / data.length).toFixed(1)+'</td><td>'+(totalCTF === 0 ? '-' : (totals.ctf.asbp / totalCTF).toFixed(1))+'</td><td>'+(totalNF === 0 ? '-' : (totals.nf.asbp / totalNF).toFixed(1))+'</td><td>'+(totalRed === 0 ? '-' : (totals.red.asbp / totalRed).toFixed(1))+'</td><td>'+(totalBlue === 0 ? '-' : (totals.blue.asbp / totalBlue).toFixed(1))+'</td></tr>'); | |
//$('#DWP_Messages').append('<div id="DWP_MPM" style="color:#999">Most Played Map: ' + mostPlayedMap + ' by ' + maps[mostPlayedMap].author + ' (' + mostPlayedMapCount + '/' + (totalCTF+totalNF) + ' games @ ' + ((mostPlayedMapCountWin/(mostPlayedMapCount-mostPlayedMapCountFSA))*100).toFixed(2) + '% Win)</div>'); | |
if (DWP_ShowMapStats && mostPlayedMapCount >= DWP_MinPlays) { | |
var mapsSorted = []; | |
for (var map in maps) { | |
if (maps.hasOwnProperty(map) && (maps[map].count >= DWP_MinPlays)) { | |
mapsSorted.push( { name:map, author:maps[map].author, count:maps[map].count, winp:(maps[map].win) / (maps[map].count-maps[map].fsa) * 100, win:maps[map].win, fsa:maps[map].fsa, timePlayed:maps[map].timePlayed, asbp:maps[map].asbp, | |
red:{count:maps[map].red.count, win:maps[map].red.win, timePlayed:maps[map].red.timePlayed, asbp:maps[map].red.asbp}, | |
blue:{count:maps[map].blue.count, win:maps[map].blue.win, timePlayed:maps[map].blue.timePlayed, asbp:maps[map].blue.asbp} } ); | |
} | |
} | |
mapsSorted.sort(function(a, b) { | |
return (b.count - a.count ? b.count - a.count : b.winp - a.winp); //a.name.localeCompare(b.name) | |
}); | |
$('#DWP_Messages').append('<table id="DWP_Maps">' + | |
' <thead style="display:block; overflow-x:hidden; overflow-y:hidden">' + | |
' <tr><th class="DWP_Maps_Large" style="border-left:1px solid #999"></th><th colspan="4" style="border-right:1px solid #999">All</th><th colspan="4" style="border-right:1px solid #999">Red</th><th colspan="4" style="border-right:1px solid #999">Blue</th></tr>' + | |
' <tr><th class="DWP_Maps_Large"></th>' + | |
' <th class="DWP_Maps_Small">#</th><th class="DWP_Maps_Medium">W%</th><th class="DWP_Maps_Medium">Time</th><th class="DWP_Maps_Medium">ASBP</th>' + | |
' <th class="DWP_Maps_Small">#</th><th class="DWP_Maps_Medium">W%</th><th class="DWP_Maps_Medium">Time</th><th class="DWP_Maps_Medium">ASBP</th>' + | |
' <th class="DWP_Maps_Small">#</th><th class="DWP_Maps_Medium">W%</th><th class="DWP_Maps_Medium">Time</th><th class="DWP_Maps_Medium">ASBP</th>' + | |
' </tr>' + | |
' </thead>' + | |
' <tbody style="display:block; max-height:120px; overflow-x:hidden; overflow-y:auto"></tbody>' + | |
'</table>'); | |
$.each(mapsSorted, function(key, value) { | |
$('#DWP_Maps').append('<tr><th class="DWP_Row_Header DWP_Maps_Large">'+value.name+':</th>' + | |
'<td class="DWP_Maps_Small">'+value.count+'</td><td class="DWP_Maps_Medium">'+value.winp.toFixed(1)+'%</td><td class="DWP_Maps_Medium">'+secondsToHMS(value.timePlayed/value.count)+'</td><td class="DWP_Maps_Medium">'+(value.asbp/value.count).toFixed(1)+'</td>' + | |
'<td class="DWP_Maps_Small">'+value.red.count+'</td><td class="DWP_Maps_Medium">'+(value.red.count ? (value.red.win/value.red.count*100).toFixed(1)+'%' : '-')+'</td><td class="DWP_Maps_Medium">'+(value.red.count ? secondsToHMS(value.red.timePlayed/value.red.count) : '-')+'</td><td class="DWP_Maps_Medium">'+(value.red.count ? (value.red.asbp/value.red.count).toFixed(1) : '-')+'</td>' + | |
'<td class="DWP_Maps_Small">'+value.blue.count+'</td><td class="DWP_Maps_Medium">'+(value.blue.count ? (value.blue.win/value.blue.count*100).toFixed(1)+'%' : '-')+'</td><td class="DWP_Maps_Medium">'+(value.blue.count ? secondsToHMS(value.blue.timePlayed/value.blue.count) : '-')+'</td><td class="DWP_Maps_Medium">'+(value.blue.count ? (value.blue.asbp/value.blue.count).toFixed(1) : '-')+'</td></tr>'); | |
}); | |
} | |
GM_addStyle('.DWP_Maps_Small { min-width:25px; max-width:25px; }'); | |
GM_addStyle('.DWP_Maps_Medium { min-width:45px; max-width:45px; }'); | |
GM_addStyle('.DWP_Maps_Large { min-width:80px; max-width:80px; overflow:hidden; }'); | |
GM_addStyle('#DWP_Maps_Outer { margin:0 auto; overflow-x:hidden; overflow-y:auto; }'); | |
GM_addStyle('#DWP_Maps tbody::-webkit-scrollbar { width:2px }'); | |
GM_addStyle('#DWP_Maps tbody::-webkit-scrollbar-thumb { background:dodgerblue; border-radius:2px; }'); | |
GM_addStyle('#DWP_Maps tbody::-webkit-scrollbar-track { background:#ddd; border-radius:2px; }'); | |
//Scoreboard Stats... | |
$('#DWP_Messages').append('<table id="DWP_Stats">' + | |
'<tr><th></th></tr>' + | |
'<tr><th class="DWP_Row_Header">Per Game:</th></tr>' + | |
'<tr><th class="DWP_Row_Header" title="Average of all scoreboard stats, from all players, across all games played">S/B Ave:</th></tr>' + | |
'<tr><th class="DWP_Row_Header">Per Hour:</th></tr>' + | |
'<tr><th class="DWP_Row_Header">Total:</th></tr>' + | |
'</table>'); | |
var s1, s2, color; | |
$.each(totals.mystats, function(key, value) { | |
if (key !== 'timePlayed') { | |
$('#DWP_Stats').find('tr:eq(0)').append('<th>'+capitaliseFirstLetter(key)+'</th>'); | |
s1 = value/data.length; | |
s2 = totals.allstats[key] / totals.allstats.count; | |
if ((key === 'pops') || (key === 'drops')) { | |
if (s1 > s2) color = '#e33'; | |
else color = '#3b3'; | |
} else { | |
if (s1 < s2) color = '#e33'; | |
else color = '#3b3'; | |
} | |
if ((key === 'hold') || (key === 'prevent')) { | |
$('#DWP_Stats').find('tr:eq(1)').append('<td style="color:'+color+'">'+secondsToHMS(s1)+'</td>'); | |
$('#DWP_Stats').find('tr:eq(2)').append('<td>'+secondsToHMS(s2)+'</td>'); | |
$('#DWP_Stats').find('tr:eq(3)').append('<td>'+secondsToHMS(value/totals.mystats.timePlayed*3600)+'</td>'); | |
$('#DWP_Stats').find('tr:eq(4)').append('<td>'+secondsToHMS(value)+'</td>'); | |
} else { | |
$('#DWP_Stats').find('tr:eq(1)').append('<td style="color:'+color+'">'+(s1).toFixed(2)+'</td>'); | |
$('#DWP_Stats').find('tr:eq(2)').append('<td>'+(s2).toFixed(2)+'</td>'); | |
$('#DWP_Stats').find('tr:eq(3)').append('<td>'+(value/totals.mystats.timePlayed*3600).toFixed(2)+'</td>'); | |
$('#DWP_Stats').find('tr:eq(4)').append('<td>'+value+'</td>'); | |
} | |
} else { | |
$('#DWP_Stats').find('tr:eq(0)').append('<th>Time</th>'); | |
$('#DWP_Stats').find('tr:eq(1)').append('<td>'+secondsToHMS(value/data.length)+'</td>'); | |
$('#DWP_Stats').find('tr:eq(2)').append('<td>-</td>'); | |
$('#DWP_Stats').find('tr:eq(3)').append('<td>-</td>'); | |
$('#DWP_Stats').find('tr:eq(4)').append('<td>'+secondsToHMS(value)+'</td>'); | |
$('#DWP_Stats').find('tr:eq(0)').append('<th>C/G</th>'); | |
s1 = totals.mystats.captures / totals.mystats.grabs; | |
s2 = totals.allstats.captures / totals.allstats.grabs; | |
if (s1 < s2) color = '#e33'; | |
else color = '#3b3'; | |
$('#DWP_Stats').find('tr:eq(1)').append('<td style="color:'+color+'">'+(s1).toFixed(3)+'</td>'); | |
$('#DWP_Stats').find('tr:eq(2)').append('<td>'+(s2).toFixed(3)+'</td>'); | |
$('#DWP_Stats').find('tr:eq(3)').append('<td>-</td>'); | |
$('#DWP_Stats').find('tr:eq(4)').append('<td>-</td>'); | |
$('#DWP_Stats').find('tr:eq(0)').append('<th>K/D</th>'); | |
s1 = totals.mystats.tags / totals.mystats.pops; | |
s2 = totals.allstats.tags / totals.allstats.pops; | |
if (s1 < s2) color = '#e33'; | |
else color = '#3b3'; | |
$('#DWP_Stats').find('tr:eq(1)').append('<td style="color:'+color+'">'+(s1).toFixed(3)+'</td>'); | |
$('#DWP_Stats').find('tr:eq(2)').append('<td>'+(s2).toFixed(3)+'</td>'); | |
$('#DWP_Stats').find('tr:eq(3)').append('<td>-</td>'); | |
$('#DWP_Stats').find('tr:eq(4)').append('<td>-</td>'); | |
} | |
}); | |
$('#DWP_Timeline').find('.dwp_game').hoverIntent(function() { | |
$('#DWP_Timeline').prepend( $('#DWP_GameInfo') ); | |
showGameInfo($(this).data('gamenumber')-1, $(this).position().top+30, $(this).position().left-200); | |
}, function() { | |
$('#DWP_GameInfo').hide(0); | |
}); | |
$('#DWP').fadeIn(600); | |
} | |
tagpro.ready(function() { | |
if (PageLoc === 'ingame') { //in a game | |
var joinTime; | |
var gameData = {}; | |
var mapName='', mapAuthor='', mapType=''; | |
var pupsCount = 0; | |
var result = 0; | |
var saveAttempt = false; | |
var groupPause = false; | |
var friendlyGrabTime = 0; | |
var enemyGrabTime = 0; | |
var grabCheckFlagsDelay = 120; | |
var redHolder = 0; | |
var blueHolder = 0; | |
var thisGame = {}; | |
var whoHasFlags = function() { | |
redHolder=0; | |
blueHolder=0; | |
for (var playerId in tagpro.players) { | |
if (tagpro.players[playerId].flag === 1) { | |
blueHolder = Number(playerId); | |
} else if (tagpro.players[playerId].flag === 2) { | |
redHolder = Number(playerId); | |
} else if (tagpro.players[playerId].flag === 3) { | |
if (tagpro.players[playerId].team === 1) { | |
redHolder = Number(playerId); | |
} else { | |
blueHolder = Number(playerId); | |
} | |
} | |
} | |
}; | |
if ((tagpro.group.socket) && (tagpro.group.socket.connected)) { | |
groupPause = true; | |
} | |
tagpro.socket.on('spectator', function(spectator) { | |
if (!spectator) { | |
joinTime = Date.now(); | |
thisGame.played = joinTime; | |
setTimeout(function() { | |
if (GM_getValue('DWP_UseDisconnects', true) && tagpro.state === 1) GM_setValue('lastGameCheckDC', thisGame); | |
}, 10000); | |
} | |
}); | |
tagpro.socket.on('time', function(message) { | |
if (tagpro.state === 3) { //before the actual start | |
joinTime = Date.now(); | |
} else if (tagpro.state === 1) { //game has started | |
if (joinTime) { | |
joinTime = Date.parse(tagpro.gameEndsAt) - 720000; | |
} else { | |
joinTime = Date.now(); | |
} | |
setTimeout(function() { | |
if (!tagpro.spectator) { | |
thisGame.played = joinTime; | |
setTimeout(function() { //only count as a DC if we DC'd after 10 secs from start/join | |
if (GM_getValue('DWP_UseDisconnects', true) && tagpro.state === 1) GM_setValue('lastGameCheckDC', thisGame); | |
}, 10000); | |
} | |
}, 100); | |
} | |
}); | |
tagpro.socket.on('map', function(data) { | |
mapName = data.info.name; | |
mapAuthor = data.info.author; | |
setTimeout(function() { | |
for (var i=0; i<tagpro.map.length; i++) { //find the flags which will tell us if it's a CTF or NF map... | |
for (var j=0; j<tagpro.map[i].length; j++) { | |
if (tagpro.map[i][j] == 16 || (tagpro.map[i][j] == 16.1)) { //yellow flag found | |
mapType = 2; | |
} else if ((tagpro.map[i][j] == 3) || (tagpro.map[i][j] == 3.1) || (tagpro.map[i][j] == 4) || (tagpro.map[i][j] == 4.1)) { //red or blue flag found | |
mapType = 1; | |
} else if ((tagpro.map[i][j] == 6) || (tagpro.map[i][j] == 6.1) || (tagpro.map[i][j] == 6.2) || (tagpro.map[i][j] == 6.3) || (tagpro.map[i][j] == 6.4)) { //counts the pups so we can work out potential pups later | |
pupsCount++; | |
} | |
} | |
} | |
thisGame.mapName = mapName; | |
thisGame.mapAuthor = mapAuthor; | |
thisGame.gameMode = mapType; | |
if (tagpro.serverHost === null) tagpro.serverHost = document.URL.replace('http://', '').replace(/:(.*)/, ''); | |
if (tagpro.serverHost.startsWith('tagpro-')) { | |
thisGame.serverName = capitaliseFirstLetter(tagpro.serverHost.replace('tagpro-', '').replace('.koalabeast.com', '')); | |
} else { | |
thisGame.serverName = document.URL.replace('http://', '').replace(/:(.*)/, ''); | |
} | |
/* | |
if (!tagpro.spectator) { | |
setTimeout(function() { | |
GM_setValue('lastGameCheckDC', thisGame); | |
}, 10000); | |
} | |
*/ | |
}, 100); | |
}); | |
tagpro.socket.on('chat', function(data) { | |
if (data.from === null) { //system message | |
if (data.message.includes('This is a save attempt!')) { | |
saveAttempt = true; | |
} | |
} | |
}); | |
tagpro.socket.on('end', function(data) { | |
GM_deleteValue('lastGameCheckDC'); | |
if (!tagpro.spectator && !groupPause) { //(!tagpro.settings.stats) && | |
if (!mapType) return false; | |
var fullTime = Date.parse(tagpro.gameEndsAt); //expected end of game time after 12 mins | |
var endTime = Date.now(); //actual end of game time | |
var startTime = fullTime - 12 * 60 * 1000; //start of game time | |
var fullGameLength = (endTime-startTime)/1000; //how long the whole game lasted (with or without us) | |
var playedGameLength = (endTime-joinTime)/1000; //how long we played for | |
var playerCount = 0; | |
for (var playerId in tagpro.players) { | |
playerCount++; | |
} | |
if ( (joinTime+30000 < endTime) && (playerCount >= 4) && (playerCount <= 8) ) { //check we didn't join in the last 30 seconds of the game, and there was between 4-8 players | |
if (GM_getValue('ResetData', false)) { | |
DWP_Selections.DWPSavedGames.value = []; | |
GM_setValue('DWP_Selections', DWP_Selections); | |
GM_setValue('ResetData', false); | |
setNewReset(); | |
} | |
gameData.mapName = mapName; | |
gameData.mapAuthor = mapAuthor; | |
gameData.gameMode = mapType; | |
gameData.playerCount = playerCount; | |
if (tagpro.serverHost === null) tagpro.serverHost = document.URL.replace('http://', '').replace(/:(.*)/, ''); | |
if (tagpro.serverHost.startsWith('tagpro-')) { | |
gameData.serverName = capitaliseFirstLetter(tagpro.serverHost.replace('tagpro-', '').replace('.koalabeast.com', '')); | |
} else { | |
gameData.serverName = document.URL.replace('http://', '').replace(/:(.*)/, ''); | |
} | |
gameData.played = new Date(joinTime).toISOString(); | |
gameData.timePlayed = playedGameLength; | |
gameData.fullGameLength = fullGameLength; | |
gameData.team = tagpro.players[tagpro.playerId].team; | |
gameData.redScore = tagpro.score.r; | |
gameData.blueScore = tagpro.score.b; | |
gameData.saved = 0; | |
if (data.winner === 'tie') { | |
gameData.outcome = 5; //tie | |
} else if ( ((data.winner === 'red') && (tagpro.players[tagpro.playerId].team === 1)) || ((data.winner === 'blue') && (tagpro.players[tagpro.playerId].team === 2)) ) { | |
gameData.outcome = 1; //win | |
if (saveAttempt) { | |
gameData.saved = 2; //successful save attempt | |
} | |
} else if ( ((data.winner === 'red') && (tagpro.players[tagpro.playerId].team === 2)) || ((data.winner === 'blue') && (tagpro.players[tagpro.playerId].team === 1)) ) { | |
if (saveAttempt) { | |
gameData.outcome = 4; //unsuccessful save attempt | |
gameData.saved = 1; | |
} else { | |
gameData.outcome = 2; //loss | |
} | |
} else { //probably an event, which we won't record... | |
return false; | |
} | |
gameData.tags = tagpro.players[tagpro.playerId]["s-tags"]; | |
gameData.pops = tagpro.players[tagpro.playerId]["s-pops"]; | |
gameData.grabs = tagpro.players[tagpro.playerId]["s-grabs"]; | |
gameData.drops = tagpro.players[tagpro.playerId]["s-drops"]; | |
gameData.hold = tagpro.players[tagpro.playerId]["s-hold"]; | |
gameData.captures = tagpro.players[tagpro.playerId]["s-captures"]; | |
gameData.prevent = tagpro.players[tagpro.playerId]["s-prevent"]; | |
gameData.returns = tagpro.players[tagpro.playerId]["s-returns"]; | |
gameData.support = tagpro.players[tagpro.playerId]["s-support"]; | |
gameData.powerups = tagpro.players[tagpro.playerId]["s-powerups"]; | |
gameData.score = tagpro.players[tagpro.playerId].score; | |
gameData.points = tagpro.players[tagpro.playerId].points; | |
gameData.potentialPowerups = pupsCount * Math.floor(fullGameLength / 60); //is this right??? | |
//save scoreboard... | |
gameData.playersData = []; | |
for (playerId in tagpro.players) { | |
gameData.playersData.push({ | |
name:tagpro.players[playerId].name, | |
self:(tagpro.playerId === tagpro.players[playerId].id ? true : false), | |
id:tagpro.players[playerId].id, | |
team:tagpro.players[playerId].team, | |
auth:tagpro.players[playerId].auth, | |
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, | |
points:tagpro.players[playerId].points | |
}); | |
} | |
gameData.playersData.sort(function(a, b) { | |
return (b.score - a.score ? b.score - a.score : a.id - b.id); | |
}); | |
DWP_Selections.DWPSavedGames.value.push(gameData); | |
GM_setValue('DWP_Selections', DWP_Selections); | |
} | |
} | |
}); | |
} | |
}); | |
//Get things ready and start the script... | |
DWP_Selections = $.extend(true, {}, options, GM_getValue('DWP_Selections', options)); | |
GM_setValue('DWP_Selections', DWP_Selections); | |
$.each(DWP_Selections, function(key, value) { | |
DWP_Selections[key].type = options[key].type; | |
}); | |
//Setup the main div location depending on which page we are on... | |
var DWP_Div = '<div id="DWP" style="position:relative; display:flex; justify-content:center; align-items:center; flex-flow:column wrap; width:700px; margin:20px auto 0 auto; padding:10px; font-size:11px; color:#fff; text-align:center; text-shadow:2px 1px 2px #000000; border-radius:8px; box-shadow:#fff 0px 0px 10px; background:rgb(40,40,40); white-space:nowrap;"></div>'; | |
//Chosen server page... | |
if (PageLoc === 'server') { | |
$uHome.find('.row').append(DWP_Div); | |
$('#DWP').hide(); | |
$uHome.removeClass('hidden'); | |
//Joining page... | |
} else if (PageLoc === 'joining') { | |
$uBottom.find('.row').append(DWP_Div); | |
$('#DWP').hide(); | |
$uBottom.removeClass('hidden'); | |
} | |
if ($('#DWP').length) { | |
$('#DWP').append('<div id="DWP_InnerContainer"></div>'); | |
$('#DWP_InnerContainer').append('<div id="DWP_Timeline" style="margin:10px 0"></div>'); | |
$('#DWP_InnerContainer').append('<div id="DWP_Messages" style="font-style:italic"></div>'); | |
$('#DWP_InnerContainer').append('<div id="DWP_GameInfo" style="position:absolute; display:none; min-width:740px; padding:5px 15px; text-align:center; font-size:11px; background:#050544; color:#eee; border-radius:5px; box-shadow:0px 0px 10px; z-index:100"></div>'); | |
if (PageLoc === 'server') { | |
var optionsMenu = '<div id="DWP_OptionsMenu" style="position:absolute; display:flex; flex-direction:column; align-items:center; align-self:flex-start; font-size:11px; font-weight:normal; color:#111; text-shadow:none; background:bisque; margin:16px 0 0; top:2px; right:0px; padding:10px 20px; border:1px solid #000; border-radius:7px;">' + | |
'<div style="padding-bottom:5px; font-weight:bold;">Daily Win % Timeline</div>' + | |
' <label title="Data will be reset after this many days (1=daily, 7=weekly)"># Days:<input type="number" id="DWP_NumberDays" value="'+GM_getValue('DWP_NumberDays', 1)+'" min="1" max="365" style="width:40px;"></label>' + | |
' <label title="Data will be reset at this hour (5=5AM, 17=5PM, etc)">Reset Hour:<input type="number" id="DWP_ResetHour" value="'+GM_getValue('DWP_ResetHour', 5)+'" min="0" max="23" style="width:40px;"></label>' + | |
' <hr>' + | |
' <label>Show Timeline:<input type="checkbox" id="DWP_ShowTimeline" data-target="#DWP_Timeline" '+(GM_getValue('DWP_ShowTimeline', true) ? ' checked' : '')+'></label>' + | |
' <label>Show Main Stats:<input type="checkbox" id="DWP_ShowMainStats" data-target="#DWP_Win"'+(GM_getValue('DWP_ShowMainStats', true) ? ' checked' : '')+'></label>' + | |
' <label>Show Map Stats:<input type="checkbox" id="DWP_ShowMapStats" data-target="#DWP_Maps"'+(GM_getValue('DWP_ShowMapStats', true) ? ' checked' : '')+'></label>' + | |
' <label title="Shows stats per map. Set to \'1\' to show all maps">Min Map Plays:<input type="number" id="DWP_MinPlays" value="'+GM_getValue('DWP_MinPlays', 3)+'" min="1" max="20" style="width:40px;"></label>' + | |
' <label>Show Average Stats:<input type="checkbox" id="DWP_ShowAverageStats" data-target="#DWP_Stats"'+(GM_getValue('DWP_ShowAverageStats', true) ? ' checked' : '')+'></label>' + | |
' <label>Show Next Reset Time:<input type="checkbox" id="DWP_ShowNext" data-target="#DWP_NextReset"'+(GM_getValue('DWP_ShowNext', true) ? ' checked' : '')+'></label>' + | |
' <hr>' + | |
' <label title="Attempts to detect and record your disconnects">Use Disconnects?<input type="checkbox" id="DWP_UseDisconnects" '+(GM_getValue('DWP_UseDisconnects', true) ? ' checked' : '')+'></label>' + | |
' <div id="DWP_Reset" style="color:black; background:rgba(255,100,100,0.5); border:1px solid red; border-radius:4px; margin-top:10px; padding:0 2px; font-size:10px; font-weight:bold; cursor:pointer;">RESET NOW</div>' + | |
'</div>'; | |
$('#DWP').append('<div id="DWP_OptionsButton" style="position:absolute; top:2px; right:2px; display:inline-block; font:12px Arial; text-align:center; text-shadow:none; height:17px; width:17px; border:1px solid bisque; border-radius:50%; cursor:pointer" title="Options">⁞</div>'); | |
$('#DWP').append(optionsMenu); | |
$('#DWP_OptionsMenu').hide(0); | |
var doHideShow = function() { | |
$('#DWP_OptionsMenu').find('input[type="checkbox"]').each(function() { | |
var target = $('#'+this.id).data('target'); | |
if (this.checked) { | |
$(target).fadeIn(400); | |
if (this.id === 'DWP_ShowMapStats') $('#DWP_MinPlays').parent().fadeIn(400); | |
} else { | |
$(target).fadeOut(200); | |
if (this.id === 'DWP_ShowMapStats') $('#DWP_MinPlays').parent().fadeOut(200); | |
} | |
}); | |
}; | |
$('#DWP_OptionsButton').on('click', function() { | |
$('#DWP_OptionsMenu').fadeToggle(200); | |
}); | |
$('#DWP_OptionsMenu').on('change', 'input', function() { | |
GM_setValue(this.id, (this.type === 'checkbox' ? this.checked : this.value)); | |
DWP_NumberDays = GM_getValue('DWP_NumberDays', 1); | |
DWP_ResetHour = GM_getValue('DWP_ResetHour', 5); | |
DWP_ShowTimeline = GM_getValue('DWP_ShowTimeline', true); | |
DWP_ShowMainStats = GM_getValue('DWP_ShowMainStats', true); | |
DWP_ShowMapStats = GM_getValue('DWP_ShowMapStats', true); | |
DWP_MinPlays = GM_getValue('DWP_MinPlays', 3); | |
DWP_ShowAverageStats = GM_getValue('DWP_ShowAverageStats', true); | |
DWP_ShowNext = GM_getValue('DWP_ShowNext', true); | |
if ( (this.id === 'DWP_NumberDays') || (this.id === 'DWP_ResetHour') || (this.id === 'DWP_MinPlays') ) { | |
if (this.id !== 'DWP_MinPlays') { | |
GM_deleteValue('reset'); | |
setNewReset(); | |
} | |
$('#DWP_Timeline').empty(); | |
$('#DWP_Messages').empty(); | |
$('#DWP_NextReset').remove(); | |
loadData(); | |
} | |
doHideShow(); | |
}).on('mouseleave', function() { | |
$('#DWP_OptionsMenu').fadeOut(200); | |
}); | |
$('#DWP_Reset').on('click', function() { | |
if (!confirm('All current game data will be deleted.\n\nOK to continue?\n\n')) return; | |
DWP_Selections.DWPSavedGames.value = []; | |
GM_setValue('DWP_Selections', DWP_Selections); | |
GM_setValue('ResetData', false); | |
GM_deleteValue('reset'); | |
$('#DWP_Timeline').empty(); | |
$('#DWP_Messages').empty(); | |
$('#DWP_NextReset').remove(); | |
loadData(); | |
doHideShow(); | |
}); | |
} | |
} | |
var $DWP_Timeline = $('#DWP_Timeline'); | |
if ( $('#DWP').length ) { | |
setTimeout(function() { | |
loadData(); | |
if (PageLoc === 'server') doHideShow(); | |
GM_addStyle('#DWP_GameInfoScoreboard { color:#eee; width:100%; text-align:center; border-collapse:collapse; border-spacing:1px; cursor:default; }'); | |
GM_addStyle('#DWP_GameInfoScoreboard_Header { color:#fff; background:linear-gradient(rgba(0,0,0,0.3), rgba(0,0,0,0.05)); font-weight:bold; }'); | |
GM_addStyle("#DWP_GameInfoScoreboard tr.DWP_GameInfo_HighlightSelf { background:rgba(255,255,255,0.2); }"); | |
GM_addStyle('#DWP_GameInfoScoreboard td { padding:1px 3px; border-top:1px solid #888; border-bottom:1px solid #888; }'); | |
GM_addStyle('.DWP_RedTeamColor { color:#F8B0B8; font-weight:normal }'); | |
GM_addStyle('.DWP_BlueTeamColor { color:#C9C9F8; font-weight:normal }'); | |
GM_addStyle('.DWP_Max { color:gold; text-shadow:1px 1px 1px black, 0 0 8px #FF5722, 0 0 8px #FFEB3B }'); | |
GM_addStyle('.DWP_Max_Red { color:gold; text-shadow:1px 1px 1px black, 0 0 3px white; }'); | |
GM_addStyle('.DWP_Max_Blue { color:gold; text-shadow:1px 1px 1px black, 0 0 3px white; }'); | |
GM_addStyle('.DWP_KDCol { border-left:1px solid #888; }'); | |
GM_addStyle('#DWP_Win { table-layout:fixed; width:440px; margin:10px auto; font-size:11px; color:#bbb; text-align:center; font-style:normal; border-collapse:collapse; border-spacing:1px; cursor:default; }'); | |
GM_addStyle('#DWP_Win th { border:1px solid #555; color:#ddd; background:#333; }'); | |
GM_addStyle('#DWP_Win td { border:1px solid #555; }'); | |
GM_addStyle('#DWP_Win td:nth-child(2), #DWP_Win td:nth-child(4), #DWP_Win td:nth-child(6), #DWP_Win th:nth-child(2), #DWP_Win th:nth-child(4), #DWP_Win th:nth-child(6) { border-right:1px solid #999; }'); | |
GM_addStyle('#DWP_Win th:nth-child(1) { border-left:1px solid #999 !important; }'); | |
GM_addStyle('#DWP_Maps { margin:10px auto; font-size:10px; color:#bbb; text-align:center; font-style:normal; border-collapse:collapse; border-spacing:1px; cursor:default; }'); | |
GM_addStyle('#DWP_Maps th { border:1px solid #555; color:#ddd; background:#333; padding:0 2px; width:30px; }'); | |
GM_addStyle('#DWP_Maps td { border:1px solid #555; padding:0 2px; }'); | |
GM_addStyle('#DWP_Maps td:nth-child(5), #DWP_Maps td:nth-child(9), #DWP_Maps td:nth-child(13), #DWP_Maps th:nth-child(5), #DWP_Maps th:nth-child(9), #DWP_Maps th:nth-child(13) { border-right:1px solid #999; }'); | |
GM_addStyle('#DWP_Maps th:nth-child(1) { border-left:1px solid #999 !important; }'); | |
GM_addStyle('#DWP_Stats { margin:10px auto; font-size:10px; color:#bbb; text-align:center; font-style:normal; border-collapse:collapse; border-spacing:1px; cursor:default; }'); | |
GM_addStyle('#DWP_Stats th { border:1px solid #555; color:#ddd; background:#333; font-weight:normal; width:40px; }'); | |
GM_addStyle('#DWP_Stats td { border:1px solid #555; }'); | |
GM_addStyle('.DWP_Row_Header { text-align:right; }'); | |
GM_addStyle('.DWP_Highlight { color:#fe9; }'); | |
GM_addStyle('#DWP_OptionsMenu label { margin:1px 0 0; color:black; font-size:11px; text-align:center; font-weight:normal; }'); | |
GM_addStyle('#DWP_OptionsMenu input { margin:0; padding:0; height:17px; color:black; font:11px Arial; }'); | |
GM_addStyle('#DWP_OptionsMenu input[type="checkbox"] { margin:1px 2px; width:11px; height:11px; }'); | |
GM_addStyle('#DWP_OptionsMenu hr { width:100%; margin:5px 0; border-top:1px solid #aaa; } '); | |
GM_addStyle('#DWP_Bottom_Container { display:flex; margin:10px 0; }'); | |
GM_addStyle('#DWP_Medals_Container { padding:10px 5px 5px; display:flex; margin:0 5px; flex-flow:row wrap; align-items:center; justify-content:center; background:rgba(0,0,0,0.2); border:1px dashed #777; border-radius:6px; font-size:15px; width:380px; }'); | |
GM_addStyle('#DWP_Medals { display:flex; margin:10px 0 0; flex-flow:row wrap; align-items:center; justify-content:center; font-size:15px; width:100%; }'); | |
GM_addStyle('.DWP_Medals_Stats { display:flex; width:72px; flex-flow:column; justify-content:center; align-items:center; }'); | |
GM_addStyle('.DWP_Medals_Stat { box-shadow:0px 0px 10px -2px white; color:black; font-style:italic; text-shadow:1px 1px 5px #555; border:1px outset #999; border-radius:50%; width:40px; height:40px; padding:0 2px 2px 0; display:flex; align-items:center; justify-content:center; }'); | |
GM_addStyle('#DWP_Bars { width:320px; margin:0px 5px; padding:5px 20px; border:1px dashed #777; border-radius:6px; background:rgba(0,0,0,0.2); }'); | |
GM_addStyle('.DWP_Bars_Outer { position:relative; height:23px; }'); | |
GM_addStyle('.DWP_Bars_Title { margin:0px 0 -1px; font-size:11px; }'); | |
GM_addStyle('.DWP_Bars_Mid { position:absolute; width:100%; opacity:0.8; font-size:10px; margin:-1px 0 0; color:#000; text-shadow:none; }'); | |
GM_addStyle('.DWP_Bars_Red { display:inline-block; position:absolute; left:0; text-align:left; padding-left:2px; font-size:9px; background:linear-gradient(to right, #f33, #f99 120px); border-right:1px solid white; border-radius:2px 0 0 2px; overflow:hidden; }'); | |
GM_addStyle('.DWP_Bars_Blue { display:inline-block; position:absolute; right:0; text-align:right; padding-right:2px; font-size:9px; background:linear-gradient(to left, #33f, #99f 120px); border-radius:0 2px 2px 0; overflow:hidden; }'); | |
GM_addStyle('#DWP_EOG_Message { font-size:12px; border:1px inset #bbb; background:linear-gradient(rgba(150,150,150,0.5),rgba(0,0,0,0.9)); width:400px; margin:0px auto -15px; height:20px; border-radius:6px; }'); | |
}, 1200); | |
} | |
//helper functions... | |
function secondsToHMS(d) { | |
d = Number(d); | |
var h = Math.floor(d / 3600); | |
var m = Math.floor(d % 3600 / 60); | |
var s = Math.floor(d % 3600 % 60); | |
return ((h > 0 ? h + ":" : "") + (m > 0 ? (h > 0 && m < 10 ? "0" : "") + m + ":" : "0:") + (s < 10 ? "0" : "") + s); | |
} | |
function capitaliseFirstLetter(string) { | |
return string.charAt(0).toUpperCase() + string.slice(1); | |
} | |
function WhichPageAreWeOn() { | |
if (window.location.port) { //In a real game | |
return('ingame'); | |
} else if (document.URL.includes('/games/find')) { //Joining page | |
return('joining'); | |
} else if ($('#userscript-home').length) { //Chosen server homepage | |
return('server'); | |
} else if (document.URL.includes('/profile/')) { | |
if ($('#saveSettings').length) { | |
return('profile'); //Profile page and logged in | |
} else { | |
return('profileNotOurs'); //Profile page, but not our one (or we're logged out) | |
} | |
} else if (document.URL.includes('/groups')) { | |
return('groups'); | |
} else if (document.URL.includes('/boards')) { | |
return('boards'); | |
} else if (document.URL.includes('/maps')) { | |
return('maps'); | |
} else if (document.URL.includes('/settings')) { | |
return('settings'); | |
} | |
} | |
function ordinalSuffix(i) { | |
var j = i % 10; | |
var k = i % 100; | |
if (j == 1 && k != 11) return i + "st"; | |
if (j == 2 && k != 12) return i + "nd"; | |
if (j == 3 && k != 13) return i + "rd"; | |
return i + "th"; | |
} | |
/*! | |
* hoverIntent v1.8.0 // 2014.06.29 // jQuery v1.9.1+ | |
* http://cherne.net/brian/resources/jquery.hoverIntent.html | |
* | |
* You may use hoverIntent under the terms of the MIT license. Basically that | |
* means you are free to use hoverIntent as long as this header is left intact. | |
* Copyright 2007, 2014 Brian Cherne | |
*/ | |
(function($){$.fn.hoverIntent=function(handlerIn,handlerOut,selector){var cfg={interval:100,sensitivity:6,timeout:0};if(typeof handlerIn==="object"){cfg=$.extend(cfg,handlerIn)}else{if($.isFunction(handlerOut)){cfg=$.extend(cfg,{over:handlerIn,out:handlerOut,selector:selector})}else{cfg=$.extend(cfg,{over:handlerIn,out:handlerIn,selector:handlerOut})}}var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if(Math.sqrt((pX-cX)*(pX-cX)+(pY-cY)*(pY-cY))<cfg.sensitivity){$(ob).off("mousemove.hoverIntent",track);ob.hoverIntent_s=true;return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=false;return cfg.out.apply(ob,[ev])};var handleHover=function(e){var ev=$.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t)}if(e.type==="mouseenter"){pX=ev.pageX;pY=ev.pageY;$(ob).on("mousemove.hoverIntent",track);if(!ob.hoverIntent_s){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}}else{$(ob).off("mousemove.hoverIntent",track);if(ob.hoverIntent_s){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob)},cfg.timeout)}}};return this.on({"mouseenter.hoverIntent":handleHover,"mouseleave.hoverIntent":handleHover},cfg.selector)}})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment