Last active
February 18, 2016 22:13
-
-
Save nabbynz/51050e6f43791cc3c5eb to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Better Stats on Profile Page | |
| // @description Just tidies it up a bit. Can show stats as per game or hour. | |
| // @version 0.2.3 | |
| // @include http://tagpro-*.koalabeast.com/profile/* | |
| // @include http://*.newcompte.fr/profile/* | |
| // @grant GM_addStyle | |
| // @updateURL https://gist.github.com/nabbynz/51050e6f43791cc3c5eb/raw/TagPro_BetterProfilePageStats.user.js | |
| // @downloadURL https://gist.github.com/nabbynz/51050e6f43791cc3c5eb/raw/TagPro_BetterProfilePageStats.user.js | |
| // @author nabby | |
| // ==/UserScript== | |
| console.log('START: ' + GM_info.script.name + ' (v' + GM_info.script.version + ' by ' + GM_info.script.author + ')'); | |
| function toSeconds(value) { | |
| var a = value.split(':'); | |
| return ((+a[0]) * 60 * 60 + (+a[1]) * 60 + (+a[2])).toString(); | |
| } | |
| function toHHMMSS(value) { | |
| var sec_num = parseInt(value, 10); // don't forget the second param | |
| var hours = Math.floor(sec_num / 3600); | |
| var minutes = Math.floor(sec_num % 3600 / 60); | |
| var seconds = Math.floor(sec_num % 3600 % 60); | |
| if (hours < 10) hours = "0" + hours; | |
| if (minutes < 10) minutes = "0" + minutes; | |
| if (seconds < 10) seconds = "0" + seconds; | |
| return hours + ':' + minutes + ':' + seconds; | |
| } | |
| //Give the tables ids... | |
| $('table.board').eq(0).prop('id', 'Stats300').css({'cursor':'default', 'border-spacing':'1px', 'line-height':'13px', 'font-size':'100%', 'box-shadow':'0px 0px 5px white', 'text-shadow':'1px 1px 1px black'}); | |
| $('table.board').eq(1).prop('id', 'PUP300').css({'cursor':'default', 'border-spacing':'1px', 'line-height':'13px', 'font-size':'100%', 'box-shadow':'0px 0px 5px white', 'text-shadow':'1px 1px 1px black'}); | |
| $('table.board').eq(2).prop('id', 'StatsDWM').css({'cursor':'default', 'border-spacing':'1px', 'line-height':'13px', 'font-size':'100%', 'box-shadow':'0px 0px 5px white', 'text-shadow':'1px 1px 1px black'}); | |
| $('table.board').eq(3).prop('id', 'PUPDWM').css({'cursor':'default', 'border-spacing':'1px', 'line-height':'13px', 'font-size':'100%', 'box-shadow':'0px 0px 5px white', 'text-shadow':'1px 1px 1px black'}); | |
| $('table.board').eq(4).prop('id', 'Flairs').css({'cursor':'default', 'border-spacing':'1px', 'line-height':'13px', 'font-size':'13px', 'border-radius':'5px', 'box-shadow':'0px 0px 5px white', 'width':'90%', 'margin':'0 auto 20px', 'padding':'4px'}); | |
| //Cache the elements (faster)... | |
| var $Stats300 = $('#Stats300'); | |
| var $PUP300 = $('#PUP300'); | |
| var $StatsDWM = $('#StatsDWM'); | |
| var $PUPDWM = $('#PUPDWM'); | |
| var $Flairs = $('#Flairs'); | |
| //Make some headings and add some styles... | |
| $Stats300.before('<div style="font-size:20px; color:navajowhite; font-weight:bold; background:rebeccapurple; margin:30px 250px 5px; padding:0 20px; text-align:center; border-radius:10px;">Rolling 300</div>'); | |
| $PUP300.after('<div id="BS_PerX" style="float:right; margin-top:8px; font-size:12px; font-family:sans-serif; color:bisque">' + | |
| '<label' + (localStorage.getItem('BS_PerX') === 'BS_PerNormal' ? ' style="color:#0a0"' : '') + '><input type="radio" name="BS_PerX" class="BS_PerX" id="BS_PerNormal" ' + (localStorage.getItem('BS_PerX') === 'BS_PerNormal' ? 'checked"' : '') + '>Totals</label>' + | |
| '<label' + (localStorage.getItem('BS_PerX') === 'BS_PerGame' ? ' style="color:#0a0"' : '') + '><input type="radio" name="BS_PerX" class="BS_PerX" id="BS_PerGame" ' + (localStorage.getItem('BS_PerX') === 'BS_PerGame' ? 'checked' : '') + '>Per Game</label>' + | |
| '<label' + (localStorage.getItem('BS_PerX') === 'BS_PerHour' ? ' style="color:#0a0"' : '') + '><input type="radio" name="BS_PerX" class="BS_PerX" id="BS_PerHour" ' + (localStorage.getItem('BS_PerX') === 'BS_PerHour' ? 'checked' : '') + '>Per Hour</label>' + | |
| '<label' + (localStorage.getItem('BS_PerX') === 'BS_PerMinute' ? ' style="color:#0a0"' : '') + '><input type="radio" name="BS_PerX" class="BS_PerX" id="BS_PerMinute" ' + (localStorage.getItem('BS_PerX') === 'BS_PerMinute' ? 'checked' : '') + '>Per Minute</label>' + | |
| '</div>'); | |
| $StatsDWM.before('<div style="font-size:20px; color:navajowhite; font-weight:bold; background:rebeccapurple; margin:30px 250px 5px; padding:0 20px; text-align:center; border-radius:10px;">Daily / Weekly / Monthly</div>'); | |
| $Flairs.before('<div style="font-size:20px; color:navajowhite; font-weight:bold; background:rebeccapurple; margin:50px 250px 5px; padding:0 20px; text-align:center; border-radius:10px;">Flairs</div>'); | |
| $Flairs.find('tr.fade').css('opacity', '0.45'); | |
| $Flairs.find('td').css('padding', '2px 5px'); | |
| $Flairs.find('td.alt').parent('tr').addClass('alt'); | |
| $Flairs.find('td.alt').removeClass('alt'); | |
| GM_addStyle('#Flairs tr.alt { background-color:#333}'); | |
| //Save the default table data so we can modify it as required... | |
| function saveDefaultData() { | |
| var row, col, defaultValue; | |
| //Rolling 300 Table... | |
| for (row=2; row<=4; row++) { | |
| for (col=0; col<=8; col++) { | |
| defaultValue = $PUP300.find('tr:eq('+row+') > td:eq('+col+')').text(); | |
| if ((col === 4) || (col === 6)) { | |
| defaultValue = toSeconds(defaultValue); | |
| } | |
| $PUP300.find('tr:eq('+row+') > td:eq('+col+')').data('default', defaultValue); | |
| } | |
| } | |
| //DWM Table... | |
| for (row=1; row<=4; row++) { | |
| for (col=0; col<=8; col++) { | |
| defaultValue = $PUPDWM.find('tr:eq('+row+') > td:eq('+col+')').text(); | |
| if ((col === 4) || (col === 6)) { | |
| defaultValue = toSeconds(defaultValue); | |
| } | |
| $PUPDWM.find('tr:eq('+row+') > td:eq('+col+')').data('default', defaultValue); | |
| } | |
| } | |
| } | |
| //================================================================= | |
| //Rolling 300 Stats Table... | |
| //================================================================= | |
| function doR300Stats() { | |
| var row, col, WTLD=0; | |
| for (row=2; row<=4; row++) { | |
| WTLD = ( parseInt($Stats300.find('tr:eq('+row+') > td:eq(2)').text()) + parseInt($Stats300.find('tr:eq('+row+') > td:eq(3)').text()) + parseInt($Stats300.find('tr:eq('+row+') > td:eq(4)').text()) + parseInt($Stats300.find('tr:eq('+row+') > td:eq(6)').text()) ); | |
| $Stats300.find('tr:eq('+row+') > td:eq(9)').text( (WTLD > 0 ? (parseInt($Stats300.find('tr:eq('+row+') > td:eq(2)').text()) / WTLD * 100).toFixed(2) : '0.00') ); | |
| } | |
| $Stats300.find('tr:eq(2) > td:eq(9)').css('color','#0f0'); //Make the Rolling 300 Win % stand out a bit more | |
| } | |
| //================================================================= | |
| //Rolling 300 PowerUp Table... | |
| //================================================================= | |
| function doR300PUPs() { | |
| var row, col; | |
| var games; | |
| var defaultValue = ''; | |
| for (row=2; row<=4; row++) { | |
| if (localStorage.getItem('BS_PerX') === 'BS_PerGame') { | |
| games = parseInt($Stats300.find('tr:eq('+row+') > td:eq(1)').text()); | |
| } else if (localStorage.getItem('BS_PerX') === 'BS_PerHour') { | |
| games = parseFloat( toSeconds($Stats300.find('tr:eq('+row+') > td:eq(7)').text()) / 3600); | |
| } else if (localStorage.getItem('BS_PerX') === 'BS_PerMinute') { | |
| games = parseFloat( toSeconds($Stats300.find('tr:eq('+row+') > td:eq(7)').text()) / 60); | |
| } else { | |
| games = 0; | |
| } | |
| for (col=0; col<=8; col++) { | |
| defaultValue = $PUP300.find('tr:eq('+row+') > td:eq('+col+')').data('default'); | |
| if (games === 0) { | |
| $PUP300.find('tr:eq('+row+') > td:eq('+col+')').text(defaultValue).attr('title', ''); | |
| } else { | |
| $PUP300.find('tr:eq('+row+') > td:eq('+col+')').text((defaultValue / games).toFixed(2)).attr('title', 'Total: '+defaultValue); | |
| } | |
| if ((col === 4) || (col === 6)) $PUP300.find('tr:eq('+row+') > td:eq('+col+')').text( toHHMMSS($PUP300.find('tr:eq('+row+') > td:eq('+col+')').text()) ).attr('title', 'Total: '+toHHMMSS(defaultValue)); | |
| } | |
| } | |
| } | |
| //================================================================= | |
| //Daily/Weekly/Monthly Stats Table... | |
| //================================================================= | |
| function doDWMStats() { | |
| var row, col, WTLD=0; | |
| for (row=1; row<=4; row++) { | |
| WTLD = ( parseInt($StatsDWM.find('tr:eq('+row+') > td:eq(2)').text()) + parseInt($StatsDWM.find('tr:eq('+row+') > td:eq(3)').text()) + parseInt($StatsDWM.find('tr:eq('+row+') > td:eq(4)').text()) + parseInt($StatsDWM.find('tr:eq('+row+') > td:eq(6)').text()) ); | |
| $StatsDWM.find('tr:eq('+row+') > td:eq(9)').text( (WTLD > 0 ? (parseInt($StatsDWM.find('tr:eq('+row+') > td:eq(2)').text()) / WTLD * 100).toFixed(2) : '0.00') ); | |
| } | |
| } | |
| //================================================================= | |
| //Daily/Weekly/Monthly PowerUp Table... | |
| //================================================================= | |
| function doDWMPUPs() { | |
| var row, col; | |
| var games; | |
| var defaultValue = ''; | |
| for (row=1; row<=4; row++) { | |
| if (localStorage.getItem('BS_PerX') === 'BS_PerGame') { | |
| games = parseInt($StatsDWM.find('tr:eq('+row+') > td:eq(1)').text()); | |
| } else if (localStorage.getItem('BS_PerX') === 'BS_PerHour') { | |
| games = parseFloat( toSeconds($StatsDWM.find('tr:eq('+row+') > td:eq(7)').text()) / 3600); | |
| } else if (localStorage.getItem('BS_PerX') === 'BS_PerMinute') { | |
| games = parseFloat( toSeconds($StatsDWM.find('tr:eq('+row+') > td:eq(7)').text()) / 60); | |
| } else { | |
| games = 0; | |
| } | |
| for (col=0; col<=8; col++) { | |
| defaultValue = $PUPDWM.find('tr:eq('+row+') > td:eq('+col+')').data('default'); | |
| if (games === 0) { | |
| $PUPDWM.find('tr:eq('+row+') > td:eq('+col+')').text(defaultValue).attr('title', ''); | |
| } else { | |
| $PUPDWM.find('tr:eq('+row+') > td:eq('+col+')').text((defaultValue / games).toFixed(2)).attr('title', 'Total: '+defaultValue); | |
| } | |
| if ((col === 4) || (col === 6)) $PUPDWM.find('tr:eq('+row+') > td:eq('+col+')').text( toHHMMSS($PUPDWM.find('tr:eq('+row+') > td:eq('+col+')').text()) ).attr('title', 'Total: '+toHHMMSS(defaultValue)); | |
| } | |
| } | |
| } | |
| //Bind events... | |
| $('.BS_PerX').on('click', function() { | |
| localStorage.setItem('BS_PerX', this.id); | |
| $('#BS_PerX label').css('color', 'bisque'); | |
| $(this).parent('label').css('color', '#0a0'); | |
| doR300PUPs(); | |
| doDWMPUPs(); | |
| }); | |
| $('#Stats300 tr:gt(1) td, #PUP300 tr:gt(1) td, #StatsDWM tr:gt(0) td, #PUPDWM tr:gt(0) td').hover(function() { | |
| $(this).css('box-shadow', '0px 0px 8px yellow'); | |
| }, function() { | |
| $(this).css('box-shadow', ''); | |
| }); | |
| $Flairs.find('tr:gt(0)').hover(function() { | |
| $(this).css('background-color', 'darkgreen'); | |
| }, function() { | |
| $(this).css('background-color', ''); | |
| }); | |
| //Start it.... | |
| saveDefaultData(); | |
| doR300Stats(); | |
| doR300PUPs(); | |
| doDWMStats(); | |
| doDWMPUPs(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment