Last active
August 28, 2017 22:47
-
-
Save nabbynz/486d77d16d494fdfee80069ac5c7f309 to your computer and use it in GitHub Desktop.
TagPro Homepage Enhancer
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 Homepage Enhancer | |
// @description Changes the layout of your server homepage | |
// @version 0.1.4 | |
// - 0.1.4: Fix: tagpro.serverHost bug. Add Ball Spin option to the Settings menu. | |
// - 0.1.3: Added: Change Background Image for Server Homepage | |
// - 0.1.2: Added: options to remove new site updates. Added "Group Play Now" button. | |
// - 0.1.1: Updated: Leaderboard widget (added "Event" tab if data available) | |
// - 0.1.0: Changed: Maps Widget (sortable) | |
// - 0.0.4: Added: Selectable Random Flairs | |
// - 0.0.3: Added: Map previews to maps widget | |
// - 0.0.3: Added: Change animation to balls on loading screen | |
// @include http://tagpro-*.koalabeast.com* | |
// @exclude http://tagpro-maptest.koalabeast.com* | |
// @exclude http://tagpro-*.koalabeast.com:* | |
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js | |
// @require https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.3.0/Chart.min.js | |
// @updateURL https://gist.github.com/nabbynz/486d77d16d494fdfee80069ac5c7f309/raw/TagPro_Homepage_Enhancer.user.js | |
// @downloadURL https://gist.github.com/nabbynz/486d77d16d494fdfee80069ac5c7f309/raw/TagPro_Homepage_Enhancer.user.js | |
// @grant GM_setValue | |
// @grant GM_getValue | |
// @grant GM_deleteValue | |
// @grant GM_addStyle | |
// @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html | |
// @author nabby | |
// ==/UserScript== | |
console.log('START: ' + GM_info.script.name + ' (v' + GM_info.script.version + ' by ' + GM_info.script.author + ')'); | |
var WhichPageAreWeOn = function(){ | |
if (window.location.port) { //In a real game | |
return('ingame'); | |
} else if (document.URL.indexOf('/games/find') > 0) { //Joining page | |
return('joining'); | |
} else if ($('#userscript-home').length) { //Chosen server homepage | |
return('server'); | |
} else if (document.URL.indexOf('/profile/') > 0) { | |
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.indexOf('/groups') > 0) { | |
return('groups'); | |
} else if (document.URL.indexOf('/boards') > 0) { | |
return('boards'); | |
} else if (document.URL.indexOf('/maps') > 0) { | |
return('maps'); | |
} else if (document.URL.indexOf('/settings') > 0) { | |
return('settings'); | |
} | |
}; | |
var PageLoc = WhichPageAreWeOn(); | |
function rand(min, max) { | |
var r = Math.floor(Math.random() * (max - min + 1)) + min; | |
return r; | |
} | |
function hexToRGBA(hex, alpha) { | |
hex = hex.replace('#', ''); | |
var r = parseInt( hex.slice(0, 2), 16 ), | |
g = parseInt( hex.slice(2, 4), 16 ), | |
b = parseInt( hex.slice(4, 6), 16 ); | |
return "rgba(" + r + ", " + g + ", " + b + ", " + (alpha ? alpha : "1") + ")"; | |
} | |
var $uHome = $('#userscript-home'); | |
var $uTop = $('#userscript-top'); | |
var $uBottom = $('#userscript-bottom'); | |
var profileId; | |
var loggedIn = $('a[href^="/profile/"]').length; | |
if (loggedIn) profileId = $('a[href^="/profile/"]').attr('href').substr(-24); | |
var options = { | |
'HR_ShowGameControls': { display: '· Show Game Controls', submenu:'HR_Menu_Adds', type:'checkbox', value:true }, | |
'HR_ShowYoutube1': { display: '· Show Youtube Video', submenu:'HR_Menu_Adds', type:'checkbox', value:true }, | |
'HR_ShowHomeServer': { display: '· Show Home Server Stats', submenu:'HR_Menu_Adds', type:'checkbox', value:true }, | |
'HR_ShowChangeServer': { display: '· Show Change Server Link', submenu:'HR_Menu_Adds', type:'checkbox', value:true }, | |
'HR_ShowCommunityChat': { display: '· Show Community Chat', submenu:'HR_Menu_Adds', type:'checkbox', value:true }, | |
'HR_ShowRedditNews': { display: '· Show Reddit News', submenu:'HR_Menu_Adds', type:'checkbox', value:true }, | |
'HR_ShowDonationInfo': { display: '· Show Donation Info', submenu:'HR_Menu_Adds', type:'checkbox', value:true }, | |
'HR_AddCurrentServerButton': { display: 'Add Updating "Current Server Stats" Button', submenu:'HR_Menu_Adds', type:'checkbox', value:false }, | |
'HR_AddFlairNameDegreeWins': { display: 'Add "Flair, Name, & Wins Until Next Degree" Widget/Menu', submenu:'HR_Menu_Adds', type:'checkbox', value:false }, | |
'HR_AddStatsFromProfile': { display: 'Add "My Stats" Widget', submenu:'HR_Menu_Adds', type:'checkbox', value:false }, | |
'HR_ShowRotationMapsGraph': { display: 'Add "Maps" Widget', submenu:'HR_Menu_Adds', type:'checkbox', value:false }, | |
'HR_ShowDWMBoardWinners': { display: 'Add "Leaderboard" Widget', submenu:'HR_Menu_Adds', type:'checkbox', value:false }, | |
'HR_AddGroupPlayNowButton': { display: 'Add "Group Play Now" Button', submenu:'HR_Menu_Adds', type:'checkbox', value:false }, | |
'HR_AddPlayNowToOther': { display: 'Add "Play Now" Button to Other Pages (in header)', submenu:'HR_Menu_Adds', type:'checkbox', value:false }, | |
'HR_AddCurrentServerToOther': { display: 'Add "Current Server" Button to Other Pages (in header)', submenu:'HR_Menu_Adds', type:'checkbox', value:false }, | |
'HR_AddSettingsToNav': { display: 'Add "Quick Settings" Menu to Nav Bar', submenu:'HR_Menu_Adds', type:'checkbox', value:false }, | |
'HR_ShowGroupsCount': { display: 'Show Groups Count in Nav Bar', submenu:'HR_Menu_Adds', type:'checkbox', value:false }, | |
'HR_MoveProfileToNav': { display: 'Move "Profile" to Nav Bar', submenu:'HR_Menu_Adds', type:'checkbox', value:false }, | |
'HR_ShowLogoutOnNav': { display: 'Add "Logout" to Nav Bar', submenu:'HR_Menu_Adds', type:'checkbox', value:false }, | |
'HR_PlainHeader': { display: 'Plain Header (no background image)', submenu:'HR_Menu_Adds', type:'checkbox', value:false }, | |
'HR_Hide_Footer': { display: 'Hide Footer', submenu:'HR_Menu_Adds', type:'checkbox', value:false }, | |
'HR_UseBackgroundImage': { display: 'Use Background Image', submenu:'HR_Menu_Adds', type:'checkboxlink', value:false }, | |
'HR_ChangeBallsOnLoading': { display: 'Change to Balls on Loading Screen', submenu:'HR_Menu_Adds', type:'checkbox', value:false }, | |
'HR_HideMenuButton': { display: 'Hide This Menu Button', submenu:'HR_Menu_Adds', type:'checkbox', value:false }, | |
}; | |
var HR_Selections = $.extend(true, {}, options, GM_getValue('HR_Selections', options)); | |
$.each(HR_Selections, function(key, value) { | |
if (!options.hasOwnProperty(key)) { //something has been removed/changed from the options on an update | |
console.log('Removing from HR_Selections: ' + key); | |
delete HR_Selections[key]; | |
GM_setValue('HR_Selections', HR_Selections); | |
} else { | |
HR_Selections[key].display = options[key].display; | |
HR_Selections[key].submenu = options[key].submenu; | |
HR_Selections[key].type = options[key].type; | |
} | |
}); | |
if (!GM_getValue('HR_Selections')) GM_setValue('HR_Selections', HR_Selections); | |
if (HR_Selections.HR_ShowGroupsCount.value && (PageLoc !== 'joining')) { | |
var getGroups = function() { | |
if (!$('#nav-groups').find('.group-indicator').length) { //won't work if we're already in a public group | |
$.get('/groups/').done(function(data) { | |
var groups = $(data).find('#groups-list').find('.group-item'); | |
if (groups.length) { | |
var groupNames = ''; | |
$.each(groups, function(key, value) { | |
groupNames += $(value).find('div.group-name').text().trim() + "\n" + $(value).find('div:contains("Leader:"):last').text().trim() + "\n" + $(value).find('div:contains("Players:"):last').text().trim() + "\n\n"; | |
}); | |
$('#nav-groups a').text('Groups (' + groups.length + ')').attr('title', groupNames); | |
} else { | |
$('#nav-groups a').text('Groups'); | |
} | |
}); | |
} | |
}; | |
getGroups(); //call once | |
setInterval(getGroups, 60000); //then update every 60 seconds | |
} | |
if (HR_Selections.HR_Hide_Footer.value) { | |
$('footer').hide(); | |
} | |
if (HR_Selections.HR_PlainHeader.value) { | |
$('#header').css('background', '#333'); | |
} | |
if (PageLoc === 'server' && HR_Selections.HR_UseBackgroundImage.value && GM_getValue('BackgroundImageLink')) { | |
$('body').css('background', '#2b2b2b url("'+GM_getValue('BackgroundImageLink', '/images/background.jpg')+'") fixed'); | |
$('#header').css('background', 'none'); | |
$('footer.footer').css('background', 'none'); | |
} | |
if (PageLoc === 'server') { | |
if (HR_Selections.HR_AddStatsFromProfile.value) { | |
//$('#game-controls').empty(); | |
} | |
if ((HR_Selections.HR_ShowRotationMapsGraph.value) || (HR_Selections.HR_ShowDWMBoardWinners.value)) { | |
//$('.video-container').empty(); | |
//$('.video-container').css({'padding':'0', 'height':'auto'}); | |
} | |
if (HR_Selections.HR_MoveProfileToNav.value) { | |
if (loggedIn) { | |
$('#site-nav ul').append('<li'+(window.location.href.indexOf('/profile/') > 0 ? ' class="active-tab"' : '')+'><a href="'+$('.userbar').find('a[href^="/profile/"]').attr('href')+'" id="profile-btn">Profile</a></li>'); | |
} else { | |
$('#site-nav ul').append('<li'+(window.location.href.indexOf('/settings') > 0 ? ' class="active-tab"' : '')+'><a href="/settings">Settings</a></li>'); | |
if (!HR_Selections.HR_ShowLogoutOnNav.value) { | |
$('#site-nav ul').append('<li><a href="/auth/google">Login</a></li>'); | |
} | |
} | |
$('.userbar').remove(); | |
} | |
if (HR_Selections.HR_AddSettingsToNav.value && loggedIn) { | |
$('#site-nav ul').append('<li'+(window.location.href.indexOf('/settings') > 0 ? ' class="active-tab"' : '')+'><a href="javascript:void(0);" id="HR_ShowSettingsMenu"><span style="border-bottom:1px dotted;" title="Show Quick Menu">Settings</span></a></li>'); | |
} | |
if (HR_Selections.HR_ShowLogoutOnNav.value) { | |
if (loggedIn) { | |
$('#site-nav ul').append('<li><a href="/logout">Logout</a></li>'); | |
} else { | |
if (HR_Selections.HR_MoveProfileToNav.value) { | |
$('#site-nav ul').append('<li><a href="/auth/google">Login</a></li>'); | |
} | |
} | |
} | |
//Hide various elements as needed... | |
if (!HR_Selections.HR_ShowGameControls.value) $('#game-controls').hide(); | |
if (!HR_Selections.HR_ShowYoutube1.value) $('.video-container').empty().css({'padding':'0', 'height':'auto'}); //$('#home-video').hide(); | |
if (!HR_Selections.HR_ShowHomeServer.value) $('.server-stats').hide(); | |
if (!HR_Selections.HR_ShowChangeServer.value) $('.play-now').find('a[href="http://tagpro.koalabeast.com/"]').hide(); | |
if (!HR_Selections.HR_ShowCommunityChat.value) $('.chat').hide(); | |
if (!HR_Selections.HR_ShowRedditNews.value) $('.news').hide(); | |
if (!HR_Selections.HR_ShowDonationInfo.value) $('#home-donations').hide(); | |
if (HR_Selections.HR_AddGroupPlayNowButton.value) { | |
$('#play-now').after('<form method="post" action="/groups/create" id="HR_PlayPubsInGroup" style="display:inline">' + | |
' <input type="hidden" name="name" value="My Group">' + | |
' <input type="hidden" name="public" value="on">' + | |
' <a href="javascript:void(0);" id="HR_PlayPubsInGroup_Button" class="btn btn-primary" style="font-size:16px; margin-left:20px;">Group Play Now<br><span class="sub-text">Play Pubs in a Public Group</span></a>' + | |
'</form>'); | |
$('#HR_PlayPubsInGroup_Button').on('click', function() { | |
var now = new Date(); | |
now.setTime(now.getTime() + 10000); | |
document.cookie = 'groupplaynow=true' + ';path=/' + ';domain=.koalabeast.com' + ';expires=' + now.toUTCString(); //set cookie so we know we launched from this button | |
$('#HR_PlayPubsInGroup').submit(); | |
}); | |
} | |
//Refreshing Stats Server Button with Countdown... | |
if (HR_Selections.HR_AddCurrentServerButton.value) { | |
var refreshInterval = 10; | |
var count = refreshInterval - 1; | |
var refreshCount = 0; | |
//$('#home-server').empty(); | |
$('#play-now').parent().after('<a href="'+window.location.origin+'" id="HR_CurrentServerButton" class="btn btn-default">' + | |
'<div style="color:white; font-size:20px; font-weight:bold; text-transform:capitalize" title="Click to reload this page...">'+window.location.hostname.replace('tagpro-', '').replace('.koalabeast.com', '')+'</div>' + | |
'<div id="HR_CurrentServerStats" style="font-size:11px; font-weight:normal; font-style:italic"></div></a>'); | |
var countdown = setInterval(function(){ | |
if (count > 0) $('#HR_RefreshStats').html(count < 10 ? '0'+count : count); | |
count--; | |
}, 1000); | |
var getStats = function() { | |
var n = Date.now(); | |
$.getJSON(window.location.origin+"/stats?callback=").done(function(i) { | |
i.ping = Date.now() - n; | |
$("#HR_CurrentServerStats").text("Ping:"+i.ping + ", Players:"+i.players + (i.playerCapacity?"/"+i.playerCapacity:"") + (i.games?", Games:"+i.games:"")); | |
$("#HR_CurrentServerStats").append(' (<span id="HR_RefreshStats">' + (refreshInterval) + '</span>)'); | |
$('#HR_CurrentServerStats').fadeOut(100).fadeIn(100); | |
}).fail(function(i) { | |
$("#HR_CurrentServerStats").text("error getting stats"); | |
$('#HR_CurrentServerStats').fadeOut(100).fadeIn(100); | |
}); | |
}; | |
var refreshStats = function() { | |
getStats(); | |
refreshCount++; | |
count = refreshInterval - 1; | |
setTimeout(refreshStats, refreshInterval * 1000); | |
//Gradually increase the time between updates... | |
if (refreshCount > 160) { //60*60secs = after another ~60 mins interval is every 120 seconds | |
refreshInterval = 120; | |
} else if (refreshCount > 100) { //70*20secs = after another ~23 mins interval is every 60 seconds | |
refreshInterval = 60; | |
} else if (refreshCount > 30) { //30*10secs = after ~5 mins interval is every 20 seconds | |
refreshInterval = 20; | |
} | |
}; | |
setTimeout(refreshStats, 1000); | |
} | |
//Maps Widget... | |
if (HR_Selections.HR_ShowRotationMapsGraph.value) { | |
$('.video-container').after('<div id="HR_Mappys" style="margin-top:20px;"></div>'); | |
setTimeout(function() { | |
$.getJSON(window.location.origin+'/maps.json').done(function(rawData) { | |
var color1 = '#22BB22'; | |
var color2 = '#BB4444'; | |
var color3 = '#333366'; | |
$("#HR_Mappys").append('<div id="HR_Mappys_Inner">' + | |
' <ul class="tab-list" style="font:13px Arial;">' + | |
' <li id="HR_Rotation" class="active"><a>Rotation</a></li>' + | |
' <li id="HR_Retired" class=""><a>Retired</a></li>' + | |
' <select id="HR_Mappys_Sortby" style="color:#fff; font-size:12px; font-weight:bold; background:#585858; border:1px solid #777; border-radius:4px; outline:none; float:right;">' + | |
' <option value="likes" style="color:'+color1+'; font-weight:bold;" title="How many people voted "I like it"">Likes</option>' + | |
' <option value="dislikes" style="color:'+color2+'; font-weight:bold;" title="How many people voted "I dislike it"">Dislikes</option>' + | |
' <option value="neutral" style="color:'+color3+'; font-weight:bold;" title="How many people voted "I\'m Indifferent"">Neutral</option>' + | |
' <option value="score" style="color:#aaa; font-weight:bold;" title="Score = Likes / (Likes + Dislikes)">Score</option>' + | |
' <option value="averagerating" style="color:#962; font-weight:bold;" title="Average Rating = (Likes - Dislikes) / # Votes">Average Rating</option>' + | |
' <option value="totalvotes" style="color:#525; font-weight:bold;" title="How many votes have been cast for this rating">Votes</option>' + | |
' <option value="totalplays" style="color:#588; font-weight:bold;" title="How many times this map has been played">Plays</option>' + | |
' </select>' + | |
' </ul>' + | |
' </div>' + | |
' <canvas id="HR_Mappys_Graph"></canvas></div>'); // height="220px" | |
var ctx = $("#HR_Mappys_Graph").get(0).getContext("2d"); | |
var sortMapData = function() { | |
var sortby = GM_getValue('MapDataSortBy', 'likes'); | |
rawData.rotation.sort(function(a, b) { | |
if (sortby === 'likes') { | |
return ((a.totalLikes / a.totalUsers) - (b.totalLikes / b.totalUsers)); | |
} else if (sortby === 'dislikes') { | |
return ((a.totalDislikes / a.totalUsers) - (b.totalDislikes / b.totalUsers)); | |
} else if (sortby === 'neutral') { | |
return ((a.totalIndifferents / a.totalUsers) - (b.totalIndifferents / b.totalUsers)); | |
} else if (sortby === 'score') { | |
return (a.totalLikes / (a.totalLikes + a.totalDislikes)) - (b.totalLikes / (b.totalLikes + b.totalDislikes)); | |
} else if (sortby === 'averagerating') { | |
return (a.averageRating - b.averageRating); | |
} else if (sortby === 'totalvotes') { | |
return (a.totalUsers - b.totalUsers); | |
} else if (sortby === 'totalplays') { | |
return (a.totalPlays - b.totalPlays); | |
} | |
}); | |
rawData.retired.sort(function(a, b) { | |
if (sortby === 'likes') { | |
return ((a.totalLikes / a.totalUsers) - (b.totalLikes / b.totalUsers)); | |
} else if (sortby === 'dislikes') { | |
return ((a.totalDislikes / a.totalUsers) - (b.totalDislikes / b.totalUsers)); | |
} else if (sortby === 'neutral') { | |
return ((a.totalIndifferents / a.totalUsers) - (b.totalIndifferents / b.totalUsers)); | |
} else if (sortby === 'score') { | |
return (a.totalLikes / (a.totalLikes + a.totalDislikes)) - (b.totalLikes / (b.totalLikes + b.totalDislikes)); | |
} else if (sortby === 'averagerating') { | |
return (a.averageRating - b.averageRating); | |
} else if (sortby === 'totalvotes') { | |
return (a.totalUsers - b.totalUsers); | |
} else if (sortby === 'totalplays') { | |
return (a.totalPlays - b.totalPlays); | |
} | |
}); | |
var newColor = $('#HR_Mappys_Sortby').find('option[value="'+sortby+'"]').css('color'); | |
$('#HR_Mappys_Sortby').val(sortby); | |
$('#HR_Mappys_Sortby').css('color', newColor); | |
}; | |
sortMapData(); | |
var graphData = { | |
labels: $.map(rawData.rotation, function(value) { return value.name; }), | |
datasets: [{ | |
type: 'bar', | |
data: $.map(rawData.rotation, function(value) { return +((value.totalLikes / value.totalUsers) * 100).toFixed(2); }), | |
label: "Liked", | |
borderWidth:1, | |
backgroundColor: hexToRGBA(color1, '0.6'), | |
}, { | |
type: 'bar', | |
data: $.map(rawData.rotation, function(value) { return +((value.totalDislikes / value.totalUsers) * 100).toFixed(2); }), | |
label: "Disliked", | |
borderWidth:1, | |
backgroundColor: hexToRGBA(color2, '0.6'), | |
}, { | |
type: 'bar', | |
data: $.map(rawData.rotation, function(value) { return +((value.totalIndifferents / value.totalUsers) * 100).toFixed(2); }), | |
label: "Neutral", | |
borderWidth:1, | |
backgroundColor: hexToRGBA(color3, '0.6'), | |
}, { | |
type: 'line', | |
fill: false, | |
data: $.map(rawData.rotation, function(value) { return +((value.totalLikes / (value.totalUsers - value.totalIndifferents))*100).toFixed(2); }), | |
label: "Score", | |
borderWidth: 1, | |
borderColor: hexToRGBA('#ffffff', '0.4'), | |
backgroundColor: hexToRGBA('#ffffff', '1'), | |
hoverBackgroundColor: hexToRGBA('#ffffff', '1'), | |
pointRadius: 2, | |
pointHoverRadius: 4, | |
pointBorderColor: hexToRGBA('#ffffff', '1'), | |
pointHoverBorderColor: hexToRGBA('#ffffff', '1'), | |
}] | |
}; | |
setTimeout(function() { | |
if ($("#HR_Mappys_Graph").is(":visible")) { | |
var myChart = new Chart(ctx, { | |
type: 'bar', | |
data: graphData, | |
options: { | |
tooltips: { | |
mode: 'single', | |
callbacks: { | |
title: function(tooltipItem, data) { | |
var current = 'rotation'; | |
if ($('#HR_Retired').hasClass('active')) current = 'retired'; | |
return rawData[current][tooltipItem[0].index].name + ' (by ' + rawData[current][tooltipItem[0].index].author + ')'; | |
}, | |
label: function(tooltipItem, data) { | |
var current = 'rotation'; | |
if ($('#HR_Retired').hasClass('active')) current = 'retired'; | |
if (tooltipItem.datasetIndex === 3) return; | |
var tip = []; | |
tip.push('Likes: ' + (rawData[current][tooltipItem.index].totalLikes/rawData[current][tooltipItem.index].totalUsers*100).toFixed(2) + '% ('+rawData[current][tooltipItem.index].totalLikes+')'); | |
tip.push('Dislikes: ' + (rawData[current][tooltipItem.index].totalDislikes/rawData[current][tooltipItem.index].totalUsers*100).toFixed(2) + '% ('+rawData[current][tooltipItem.index].totalDislikes+')'); | |
tip.push('Neutral: ' + (rawData[current][tooltipItem.index].totalIndifferents/rawData[current][tooltipItem.index].totalUsers*100).toFixed(2) + '% ('+rawData[current][tooltipItem.index].totalIndifferents+')'); | |
tip.push(''); | |
tip.push('Total Votes: ' + rawData[current][tooltipItem.index].totalUsers); | |
tip.push('Total Plays: ' + rawData[current][tooltipItem.index].totalPlays); | |
tip.push('Score: ' + (rawData[current][tooltipItem.index].totalLikes / (rawData[current][tooltipItem.index].totalLikes + rawData[current][tooltipItem.index].totalDislikes) * 100).toFixed(1) + '%'); | |
tip.push('Average Rating: ' + (rawData[current][tooltipItem.index].averageRating*100).toFixed(2) + '%' ); | |
return tip; | |
} | |
} | |
}, | |
legend: {display:false}, | |
scales: { | |
xAxes: [{ | |
stacked: true, | |
gridLines: { display:false }, | |
ticks: { autoSkip:false, fontSize:11 } | |
}], | |
yAxes: [{ | |
stacked: true, | |
gridLines: { color:'rgba(200,200,200,0.1)' }, | |
ticks: { min:0, max:100, autoSkip:false, fontSize:11 } | |
}] | |
}, | |
responsive:true, | |
maintainAspectRatio:true, | |
onClick: function(e) { | |
$('#HR_Mappys_MapImage_Outer').remove(); | |
var activePoints = myChart.getElementsAtEvent(e); | |
if (activePoints[0]) { | |
var previewWidth = 460; | |
var barX = activePoints[0]._view.x; | |
var barWidth = activePoints[0]._view.width; | |
var graphWidth = activePoints[0]._xScale.width + activePoints[0]._xScale.left; | |
var leftMargin = 0; | |
var current = 'rotation'; | |
if ($('#HR_Retired').hasClass('active')) current = 'retired'; | |
if (barX + previewWidth > graphWidth) leftMargin = graphWidth - previewWidth - (barWidth/2); | |
else leftMargin = barX - (barWidth/2); | |
$("#HR_Mappys_Inner").append('<div id="HR_Mappys_MapImage_Outer" style="position:absolute; margin-top:-120px; margin-left:'+leftMargin+'px; width:'+previewWidth+'px; padding:6px; background:#000; border:2px solid '+color1+'; border-radius:10px;">' + | |
' <div id="HR_Mappys_MapImage_Header" style="margin-bottom:6px; font:10px Arial; text-align:center;"><span style="font-size:12px; font-weight:bold; color:'+color1+'">'+rawData[current][activePoints[0]._index].name+' by ' + rawData[current][activePoints[0]._index].author + '</span>' + | |
' <br>Score: ' + (rawData[current][activePoints[0]._index].totalLikes / (rawData[current][activePoints[0]._index].totalLikes + rawData[current][activePoints[0]._index].totalDislikes) * 100).toFixed(2) + '% (' + rawData[current][activePoints[0]._index].totalUsers + ' Votes)' + | |
' <br>' + rawData[current][activePoints[0]._index].totalLikes + ' Likes, ' + rawData[current][activePoints[0]._index].totalIndifferents + ' Neutral, ' + rawData[current][activePoints[0]._index].totalDislikes + ' Dislikes' + | |
' </div>' + | |
' <div id="HR_Mappys_MapImage" style="height:300px; background:#000 url(\'http://static.koalabeast.com/images/maps/'+rawData[current][activePoints[0]._index].key+'-small.png\') center / contain no-repeat;"></div>' + | |
'</div>'); | |
} | |
} | |
} | |
}); | |
var updateDataSets = function() { | |
var current = 'rotation'; | |
if ($('#HR_Retired').hasClass('active')) current = 'retired'; | |
myChart.data.labels = $.map(rawData[current], function(value) { return value.name; }); | |
myChart.data.datasets[0].data = $.map(rawData[current], function(value) { return +((value.totalLikes / value.totalUsers) * 100).toFixed(2); }); | |
myChart.data.datasets[1].data = $.map(rawData[current], function(value) { return +((value.totalDislikes / value.totalUsers) * 100).toFixed(2); }); | |
myChart.data.datasets[2].data = $.map(rawData[current], function(value) { return +((value.totalIndifferents / value.totalUsers) * 100).toFixed(2); }); | |
myChart.data.datasets[3].data = $.map(rawData[current], function(value) { return ((value.totalLikes / (value.totalUsers - value.totalIndifferents))*100).toFixed(2); }); | |
}; | |
$("#HR_Mappys_Inner").on('click', $("#HR_Mappys_MapImage"), function() { | |
$("#HR_Mappys_MapImage_Outer").remove(); | |
}); | |
$('#HR_Rotation').on('click', function() { | |
$('#HR_Retired').removeClass('active'); | |
$('#HR_Rotation').addClass('active'); | |
updateDataSets(); | |
myChart.update(); | |
}); | |
$('#HR_Retired').on('click', function() { | |
$('#HR_Rotation').removeClass('active'); | |
$('#HR_Retired').addClass('active'); | |
updateDataSets(); | |
myChart.update(); | |
}); | |
$('#HR_Mappys_Sortby').on('change', function() { | |
GM_setValue('MapDataSortBy', this.value); | |
sortMapData(); | |
updateDataSets(); | |
myChart.update(); | |
}); | |
} | |
}, 300); | |
}).fail(function(data) { | |
console.log('HR: Get Map Data Failure...'); | |
console.log(data); | |
}); | |
}, 500); | |
} | |
//Leaderboards Widget... | |
if (HR_Selections.HR_ShowDWMBoardWinners.value) { | |
$('.video-container').after('<div id="HR_Boards" style="margin:0 30px"></div>'); | |
setTimeout(function() { | |
$.get(window.location.origin+'/boards').done(function(data) { | |
$('#HR_Boards').append('<div id="HR_Boards_Inner" style="font:11px Arial;">' + | |
' <ul class="tab-list" style="font:13px Arial;">' + | |
' <li id="HR_LB_Day" data-target="#board-Day"><a class="HR_Tab">Daily</a></li>' + | |
' <li id="HR_LB_Week" data-target="#board-Week"><a class="HR_Tab">Weekly</a></li>' + | |
' <li id="HR_LB_Month" data-target="#board-Month"><a class="HR_Tab">Monthly</a></li>' + | |
' <li id="HR_LB_Rolling" data-target="#board-Rolling"><a class="HR_Tab">Rolling</a></li>' + | |
' <li id="HR_LB_Event" data-target="#board-Event" style="display:none"><a class="HR_Tab">Event</a></li>' + | |
' </ul>' + | |
' </div>'); | |
$('#HR_Boards_Inner .tab-list').on('click', 'li', function() { | |
$('#HR_Boards_Inner').find('li').removeClass('active'); | |
$(this).addClass('active'); | |
$('#HR_Boards_Inner').find('.leaderboard').hide(0); | |
$( $(this).data('target') ).show(0); | |
}); | |
$('#HR_Boards_Inner').append( $(data).find('#board-Day') ); | |
$('#HR_Boards_Inner').append( $(data).find('#board-Week') ); | |
$('#HR_Boards_Inner').append( $(data).find('#board-Month') ); | |
$('#HR_Boards_Inner').append( $(data).find('#board-Rolling') ); | |
if ( $(data).find('#board-Event').length ) { | |
$('#HR_Boards_Inner').append( $(data).find('#board-Event') ); | |
$('#HR_LB_Event').show(0); | |
} | |
$('#HR_Boards_Inner').find('.flair').remove(); | |
$('#HR_Boards_Inner').find('a:not(.HR_Tab)').attr('target', '_blank'); | |
$('#HR_Boards_Inner').find('table').css( { 'display':'block', 'width':'270px', 'height':'200px', 'overflow-x':'hidden', 'overflow-y':'scroll' } ); | |
$('#board-Rolling').find('.rolling-flair-list').css( { 'font-size':'11px' } ); | |
GM_addStyle('#HR_Boards_Inner table::-webkit-scrollbar { width:3px; }'); | |
GM_addStyle('#HR_Boards_Inner table::-webkit-scrollbar-thumb { background:#666; }'); | |
GM_addStyle('#HR_Boards_Inner table::-webkit-scrollbar-track { background:#ddd; }'); | |
$('#HR_LB_Day').trigger('click'); | |
}).fail(function() { | |
console.log('HR: Failed getting leaderboard data...'); | |
$('#HR_Boards').append('Could not get leaderboards data'); | |
}); | |
}, 400); | |
} | |
} | |
if (HR_Selections.HR_AddGroupPlayNowButton.value && PageLoc === 'groups') { | |
if (document.cookie.replace(/(?:(?:^|.*;\s*)groupplaynow\s*\=\s*([^;]*).*$)|^.*$/, "$1")) { | |
var now = new Date(); | |
now.setTime(now.getTime() - 60000); | |
document.cookie = 'groupplaynow=false' + ';path=/' + ';domain=.koalabeast.com' + ';expires=' + now.toUTCString(); //delete cookie | |
$('#launch-public-btn').trigger('click'); | |
} | |
} | |
//change the loading screen animation to balls... | |
if (HR_Selections.HR_ChangeBallsOnLoading.value && PageLoc === 'joining') { | |
var ballColor1 = '#d33'; //red | |
var ballColor2 = '#06d'; //blue | |
var altBall = rand(1, 4); | |
var tpBall = rand(1, 4); | |
if (Date.now() % 2 === 0) { | |
ballColor1 = '#06d'; //blue | |
ballColor2 = '#d33'; //red | |
} | |
GM_addStyle('.spinner .spinner-item { width:34px; height:34px; background-color:'+ballColor1+'; }'); | |
GM_addStyle('.spinner .spinner-item:nth-child('+tpBall+') { border:3px solid #00ff00; }'); | |
GM_addStyle('.spinner .spinner-item:nth-child('+altBall+') { background-color:'+ballColor2+'; }'); | |
} | |
//logged in options... | |
if (loggedIn && profileId) { | |
if (PageLoc === 'joining') { | |
if (HR_Selections.HR_AddFlairNameDegreeWins.value) { | |
var availableFlairs = GM_getValue('availableFlairs', []); | |
var newFlair; | |
if (!availableFlairs.length) return; | |
if (GM_getValue('HR_FlairRandom')) { //set a new random flair for the next game (on the joining page)... | |
var randomFlairs = []; | |
for (var i=0; i<availableFlairs.length; i++) { | |
if (availableFlairs[i].random) randomFlairs.push(i); | |
} | |
var ra = rand(0, randomFlairs.length-1); | |
var updateurl = window.location.origin + '/profile/selectedFlair'; | |
newFlair = availableFlairs[randomFlairs[ra]]; | |
$.ajax({method:'post', data:"flair="+newFlair.flair, dataType:'text', url:updateurl}).done(function(data){ | |
// | |
}).fail(function(data){ | |
console.log('HR: Failed POSTing new random flair on joiner', data); | |
}); | |
} else { //show the current selected flair... | |
for (var i=0; i<availableFlairs.length; i++) { | |
if (availableFlairs[i].selected) { | |
newFlair = availableFlairs[i]; | |
break; | |
} | |
} | |
} | |
$('#message').css('margin-top', '0'); | |
$('#message').before('<div id="HR_FlairCurrent" class="flair" style="display:block; margin:0 auto; width:16px;"></div><div style="font-size:11px; text-align:center;">'+newFlair.title+'</div>'); | |
$('#HR_FlairCurrent').css('background-image', 'url(/images/flair.png)'); | |
$('#HR_FlairCurrent').css('background-position', newFlair.position); | |
} | |
} else if (PageLoc === 'server') { | |
if (HR_Selections.HR_AddFlairNameDegreeWins.value || HR_Selections.HR_AddStatsFromProfile.value || HR_Selections.HR_AddSettingsToNav.value) { | |
if (HR_Selections.HR_AddFlairNameDegreeWins.value) { | |
$('.play-now').css('margin-top', '0'); | |
$('.play-now').prepend('<div id="HR_FlairNameDegreeWins" style="display:flex; justify-content:center; align-items:center; flex-wrap:wrap; border:1px solid #444; border-radius:5px; z-index:3; margin-bottom:20px;"></div>'); | |
$('#HR_FlairNameDegreeWins').append('<div id="HR_FlairCurrent" class="flair" style="width:16px; margin-right:4px; cursor:pointer;" title="Show Quick Menu"></div>'); | |
$('#HR_FlairNameDegreeWins').append('<div id="HR_WinsUntilNextDegree"></div>'); | |
} | |
if (HR_Selections.HR_AddStatsFromProfile.value) { | |
//$('#game-controls').empty(); | |
$('#game-controls').after('<div id="HR_Stats" style="margin:20px 40px;"></div>'); //video-container | |
} | |
if (HR_Selections.HR_AddSettingsToNav.value) { | |
$('#HR_ShowSettingsMenu').after('<div id="HR_Settings"></div>'); | |
$('#HR_ShowSettingsMenu').on('click', function() { | |
$('#HR_Settings').slideToggle(); | |
}); | |
} | |
setTimeout(function() { | |
$.get(window.location.origin + '/profile/' + profileId).done(function(data) { | |
var reservedName = $(data).find('#reservedName').val(); | |
var displayedName = $(data).find('#displayedName').val(); | |
//Quick Settings Menu... | |
if (HR_Selections.HR_AddSettingsToNav.value) { | |
var disableParticles = document.cookie.replace(/(?:(?:^|.*;\s*)disableParticles\s*\=\s*([^;]*).*$)|^.*$/, "$1"); | |
var forceCanvasRenderer = document.cookie.replace(/(?:(?:^|.*;\s*)forceCanvasRenderer\s*\=\s*([^;]*).*$)|^.*$/, "$1"); | |
var disableViewportScaling = document.cookie.replace(/(?:(?:^|.*;\s*)disableViewportScaling\s*\=\s*([^;]*).*$)|^.*$/, "$1"); | |
var disableBallSpin = document.cookie.replace(/(?:(?:^|.*;\s*)disableBallSpin\s*\=\s*([^;]*).*$)|^.*$/, "$1"); | |
$('#HR_Settings').append( $(data).find('#settings') ); | |
if (disableParticles === 'false') $('#HR_Settings').find('input[name="disableParticles"]').prop('checked', true); | |
if (forceCanvasRenderer === 'false') $('#HR_Settings').find('input[name="forceCanvasRenderer"]').prop('checked', true); | |
if (disableViewportScaling === 'false') $('#HR_Settings').find('input[name="disableViewportScaling"]').prop('checked', true); | |
if (disableBallSpin === 'false') $('#HR_Settings').find('input[name="disableBallSpin"]').prop('checked', true); | |
//$('#HR_Settings').css('font', '11px Arial'); | |
GM_addStyle('#settings { margin:0; }'); | |
GM_addStyle('#HR_Settings { position:absolute; display:none; margin:0; padding:5px; width:400px; font:11px Arial; background:#456; border:1px solid white; border-radius:5px; z-index:1000; }'); | |
GM_addStyle('#HR_Settings .form-horizontal .checkbox { min-height:0; margin:0; padding-top:0; }'); | |
GM_addStyle('#HR_Settings input[type="checkbox"] { position:relative; }'); | |
GM_addStyle('#HR_Settings .form-control { height:auto; padding:5px; font:11px Arial; }'); | |
GM_addStyle('#HR_Settings .form-horizontal .form-group { margin-bottom:10px; }'); | |
$('#HR_Settings h3').remove(); | |
$('#settings').find('a[href^="/textures"]').parent().removeClass('form-link'); | |
$('#settings').find('a[href^="/textures"]').remove(); //removes the textures link | |
$('#settings').find('a[href^="/profile/accounts"]').parent('div').parent('div').remove(); //removes the "Link Kongregate Account" link | |
$('#settings').find('#showEmail').parent('div').parent('div').remove(); //remove the email link | |
$('#settings').find('a[href^="/profile/next"]').parent('div').parent('div').remove(); //remove the opt in to next link | |
$('#saveSettings').before('<div id="HR_SaveSettingsSuccess" class="btn" style="width:110px"></div>'); //style="display:inline-block; right:10px; padding:2px 20px; text-align:center; font:16px Arial; border-radius:3px;" | |
$('#HR_SaveSettingsSuccess').hide(); | |
$('#HR_Settings').find('.js-cookie').on('click', function() { | |
var now = new Date(); | |
now.setTime(now.getTime() + 31536e3); | |
document.cookie = this.name + '=' + !this.checked + ';path=/' + ';domain=.koalabeast.com' + ';expires=' + now.toUTCString(); | |
}); | |
$('#saveSettings').on('click', function(e) { | |
e.preventDefault(); | |
var inputs = $('#settings input, #settings select'); | |
var settings = ''; | |
var value = ''; | |
$('#saveSettings').hide(0); | |
$('#HR_SaveSettingsSuccess').css('color','#0b0').css('background','#fff').html('Saving...').show(0); | |
$.each(inputs, function(i, v){ | |
settings += v.name + '=' + (v.type === 'checkbox' ? v.checked : v.value) + '&'; | |
}); | |
settings = settings.substr(0, settings.length-1); | |
if (tagpro.serverHost === null) tagpro.serverHost = document.URL.replace('http://', '').replace(/:(.*)/, ''); | |
if (tagpro.serverHost.length && settings.length) { | |
var updateurl = window.location.origin + '/profile/update'; | |
$.ajax({method:'post', data:settings, dataType:'text', url:updateurl}).done(function(data) { | |
if ($.parseJSON(data).success === true) { | |
$('#HR_SaveSettingsSuccess').hide(0).css('color','#fff').css('background','#0b0').html('✓ Saved'); | |
$('#HR_SaveSettingsSuccess').fadeIn(300).delay(600).fadeIn(0, function() { | |
var shownName = $.parseJSON(data).displayName ? $.parseJSON(data).displayName : $.parseJSON(data).reservedName; | |
$('#HR_displayedName').text(shownName); | |
$('#HR_Settings').fadeOut(200, function() { | |
$('#HR_SaveSettingsSuccess').hide(0); | |
$('#saveSettings').show(0); | |
}); | |
}); | |
console.log( "HR: Profile Settings Data WAS Saved :)"); | |
} else { | |
$('#HR_SaveSettingsSuccess').hide(0).css('color','#f00').css('background','#333').html('✗ Failed!'); | |
$('#HR_SaveSettingsSuccess').fadeIn(300).delay(1200).fadeIn(0, function(){ | |
$('#HR_SaveSettingsSuccess').hide(0); | |
$('#saveSettings').show(0); | |
}); | |
console.log( "HR: Profile Settings Data NOT Saved!"); | |
} | |
}).fail(function() { | |
$('#HR_SaveSettingsSuccess').hide(0).css('color','#f00').html('✗ Failed!'); | |
$('#HR_SaveSettingsSuccess').fadeIn(300).delay(1200).fadeIn(0, function(){ | |
$('#HR_SaveSettingsSuccess').hide(0); | |
$('#saveSettings').show(0); | |
}); | |
console.log( "HR: Profile Settings Data NOT Saved!"); | |
}); | |
} | |
}); | |
} | |
//My Stats Widget... | |
if (HR_Selections.HR_AddStatsFromProfile.value) { | |
$('#HR_Stats').append( $(data).find('.profile-stats').attr('id', 'HR_Stats_Inner') ); | |
$('#HR_Stats_Inner').css( { 'font':'12px Arial', 'width':'100%' }); | |
$('#HR_Stats_Inner ul.tab-list').css( { 'font':'13px Arial', 'margin-bottom':'0', 'border-bottom':'none' }); | |
//$('#HR_Stats_Inner .tab-list li a').css( { 'color':'#777' }); | |
$('#HR_Stats_Inner').find('li').on('click', function() { | |
$('#HR_Stats_Inner').find('.active').removeClass('active'); | |
$(this).addClass('active'); | |
$( $(this).data('target') ).addClass('active'); | |
}); | |
} | |
//Current Flair / Quick Flair Menu / Displayed Name / Wins Until Next Degree... | |
if (HR_Selections.HR_AddFlairNameDegreeWins.value) { | |
var accountAge = $(data).find('.profile-detail').find('td:contains("Account Age")').next('td').text().trim(); | |
var lastGame = $(data).find('.profile-detail').find('td:contains("Last Game")').next('td').text().trim(); | |
var degree = $(data).find('.profile-detail').find('td:contains("Degrees")').next('td').text(); | |
var nextDegreeIn = 'next degree ' + $(data).find('.profile-detail').find('td:contains("Next Degree")').next('td').text().trim(); | |
var rawDateJoined = parseInt(profileId.substring(0, 8), 16) * 1000; | |
var daysUntilNextBirthday = 365 - (((Date.now() - rawDateJoined) / 1000 / 60 / 60 / 24) % 365).toFixed(0); | |
var yearJoined = new Date(rawDateJoined).getUTCFullYear(); | |
var dateJoined = new Date(rawDateJoined).toDateString(); | |
var timeJoined = new Date(rawDateJoined).toLocaleTimeString(); | |
var unknownStart = new Date(2014,0,8,15,54,51,0), unknownEnd = new Date(2014,0,11,14,35,7,0); | |
var i; | |
if (daysUntilNextBirthday === 0) daysUntilNextBirthday = 'Today!!!'; | |
else if (daysUntilNextBirthday === 1) daysUntilNextBirthday = '1 day away (tomorrow!)'; | |
else if (daysUntilNextBirthday < 10) daysUntilNextBirthday = 'Ooh only '+daysUntilNextBirthday+' days away now'; | |
else daysUntilNextBirthday = daysUntilNextBirthday+' days away'; | |
$('#HR_WinsUntilNextDegree').html('<span style="font-size:18px; text-shadow:2px 1px 2px #000000; font-weight:bold"><span id="HR_displayedName">' + (displayedName ? displayedName : reservedName) + '</span><span>: ' + degree + '</span></span>' + ' <span style="font-size:12px; font-style:italic;">(' + nextDegreeIn + ')</span>'); | |
$('#HR_WinsUntilNextDegree').attr('title', (displayedName ? 'Reserved Name: '+reservedName+'\n' : '') + 'Last Game: '+lastGame + '\nAccount Age: '+accountAge + ((rawDateJoined < unknownStart.getTime() || rawDateJoined >= unknownEnd.getTime()) ? '\nDate Joined: '+dateJoined + ' (' + timeJoined + ')' : '') + '\nNext Birthday: '+daysUntilNextBirthday); | |
var updateurl = window.location.origin + '/profile/selectedFlair'; | |
var availableFlairsTable = $(data).find('#owned-flair').find('li').toArray(); | |
var availableFlairs = []; | |
var getFlairIndexPosition = function(flair) { | |
for (var i=0; i<availableFlairs.length; i++) { | |
if (availableFlairs[i].flair === flair) { | |
return i; | |
} | |
} | |
}; | |
var isFlairInRandomSelections = function(flair) { | |
var flairs = GM_getValue('availableFlairs', []); | |
for (var i=0; i<flairs.length; i++) { | |
if (flairs[i].flair === flair) { | |
if (flairs[i].random) return true; | |
else return false; | |
} | |
} | |
}; | |
//GM_deleteValue('availableFlairs') //for testing | |
$.each(availableFlairsTable, function(key, value) { | |
var flair = $(value).data('flair'); | |
if (flair) { | |
var description = $(value).find('div.flair-description').text().trim(); | |
var header = $(value).find('div.flair-header').text().trim(); | |
var count = $(value).find('div.flair-count').text().replace('count:', '').trim(); | |
var position = $(value).find('span.flair').css('background-position'); | |
var title = header + (count ? ' ['+count+']' : '') + "<br>" + description + ''; | |
var selected = ($(value).hasClass('selected') ? true : false); | |
var random = (isFlairInRandomSelections(flair) ? true : false); | |
availableFlairs.push( { flair:flair, description:description, header:header, count:count, position:position, title:title, selected:selected, random:random } ); | |
} | |
}); | |
GM_setValue('availableFlairs', availableFlairs); | |
var selectedFlair; | |
if (GM_getValue('HR_FlairRandom')) { | |
var randomFlairs = []; | |
for (i=0; i<availableFlairs.length; i++) { | |
if (availableFlairs[i].random) randomFlairs.push(i); | |
} | |
if (!randomFlairs.length) { | |
for (var i=0; i<availableFlairs.length; i++) { | |
availableFlairs[i].random = true; | |
randomFlairs.push(i); | |
} | |
GM_setValue('availableFlairs', availableFlairs); | |
} | |
var ra = rand(0, randomFlairs.length-1); | |
selectedFlair = availableFlairs[randomFlairs[ra]]; | |
$.ajax({method:'post', data:"flair="+selectedFlair.flair, dataType:'text', url:updateurl}); | |
$('#HR_FlairTable').find('input').prop('checked', false); | |
$('#HR_FlairRandom').prop('checked', true); | |
} else { | |
for (i=0; i<availableFlairs.length; i++) { | |
if (availableFlairs[i].selected) { | |
selectedFlair = availableFlairs[i]; | |
break; | |
} | |
} | |
} | |
if (selectedFlair.flair) { | |
$('#HR_FlairCurrent').css('background-image', 'url(/images/flair.png)'); | |
$('#HR_FlairCurrent').css('background-position', selectedFlair.position); | |
$('#HR_FlairCurrent').attr('title', selectedFlair.title.replace('<br>', '\n')); | |
$('#HR_FlairCurrent').delay(800).fadeIn(2000); | |
} else { | |
$('#HR_FlairCurrent').css('background-image', ''); | |
$('#HR_FlairCurrent').css('background', 'rgba(150,150,200,0.3)'); | |
$('#HR_FlairCurrent').attr('title', 'No Flair Selected'); | |
} | |
$('#HR_FlairCurrent').after('<div id="HR_FlairMenu" style="position:absolute; align-self:flex-start; margin:40px auto; padding:5px; width:325px; height:400px; background:#1C5F86; font:11px Arial; border-radius:8px; box-shadow:0px 0px 14px #aaa; z-index:6000; display:none">' + | |
'<table id="HR_FlairTable" style="display:block; border-collapse:collapse; width:100%; height:390px; overflow-y:scroll; "></table></div>'); | |
$('#HR_FlairTable').append('<tr title="A new flair will be chosen randomly for every new game"><td class="HR_FT_0"></td><td class="HR_FT_1" style="color:yellow">Random</td><td class="HR_FT_0">' + (availableFlairsTable.length-1) + '</td><td class="HR_FT_0"><input type="radio" id="HR_FlairRandom"' + (GM_getValue('HR_FlairRandom') ? 'checked' : '') + '></td><td class="HR_FT_0"><input type="checkbox" id="HR_RandomFlairsSetAll" title="Select/Unselect All"></td></tr>'); | |
$.each(availableFlairs, function(key, value) { | |
$('#HR_FlairTable').append('<tr title="'+value.description+'">' + | |
'<td class="HR_FT_0">'+(value.flair ? '<div style="width:16px; height:16px; background-image:url(\'/images/flair.png\'); background-position:'+value.position+'"></div>' : '')+'</td>' + | |
'<td class="HR_FT_1">'+value.header+'</td>' + | |
'<td class="HR_FT_0">'+value.count+'</td>' + | |
'<td class="HR_FT_0"><input type="radio" name="HR_AvailableFlairs" value="'+value.flair+'" data-hr_flair="'+value.flair+'"'+(!GM_getValue('HR_FlairRandom') && (value.flair === selectedFlair.flair) ? ' checked' : '')+'></td>' + | |
'<td class="HR_FT_0"><input type="checkbox" name="HR_RandomFlairsSet" value="'+value.flair+'" data-hr_flair="'+value.flair+'" title="Include this flair in random set?"'+(isFlairInRandomSelections(value.flair) ? ' checked' : '')+'></td>' + | |
'</tr>'); | |
}); | |
if (!GM_getValue('HR_FlairRandom')) { | |
$('#HR_RandomFlairsSetAll').hide(0); | |
$('#HR_FlairTable').find('input[name="HR_RandomFlairsSet"]').hide(0); | |
} | |
GM_addStyle('#HR_FlairTable tr { color:#ffffff; background:#13415B; cursor:pointer }'); | |
GM_addStyle('#HR_FlairTable tr:hover { background:#223344 }'); | |
GM_addStyle('.HR_FT_0 { width:40px; padding:1px 5px 0 5px; text-align:center; }'); | |
GM_addStyle('.HR_FT_1 { width:200px; padding:1px 5px 0 5px; text-align:left; }'); | |
GM_addStyle('#HR_FlairTable::-webkit-scrollbar { width:3px; }'); | |
GM_addStyle('#HR_FlairTable::-webkit-scrollbar-thumb { background:darkorange; }'); | |
GM_addStyle('#HR_FlairTable::-webkit-scrollbar-track { background:#ddd; }'); | |
$('#HR_RandomFlairsSetAll').on('click', function() { | |
$('#HR_FlairTable').find('input[name="HR_RandomFlairsSet"]').prop('checked', $(this).is(':checked')); | |
for (var i=0; i<availableFlairs.length; i++) { | |
availableFlairs[i].random = $(this).is(':checked'); | |
} | |
GM_setValue('availableFlairs', availableFlairs); | |
}); | |
$('#HR_FlairTable').find('input[name="HR_RandomFlairsSet"]').on('click', function() { | |
var i = getFlairIndexPosition($(this).data('hr_flair')); | |
availableFlairs[i].random = $(this).is(':checked'); | |
GM_setValue('availableFlairs', availableFlairs); | |
}); | |
$('#HR_FlairCurrent').on('click', function() { | |
$('#HR_FlairMenu').fadeToggle(300); | |
}); | |
$('#HR_FlairTable').find('input[type="radio"]').on('click', function() { | |
selectedFlair = $(this); | |
$('#HR_SetFlairSuccess').remove(); | |
if (selectedFlair) { | |
if ($(selectedFlair).attr('id') === 'HR_FlairRandom') { | |
selectedFlair.prop('checked', true); | |
GM_setValue('HR_FlairRandom', true); | |
$('#HR_RandomFlairsSetAll').fadeIn(800); | |
$('#HR_FlairTable').find('input[name="HR_RandomFlairsSet"]').fadeIn(800); | |
$('#HR_FlairTable').find('input[name=HR_AvailableFlairs]:checked').prop('checked', false); | |
} else { //normal flair | |
var flair = selectedFlair.data('hr_flair'); | |
selectedFlair.prop('checked', true); | |
$('#HR_FlairRandom').prop('checked', false); | |
for (var i=0; i<availableFlairs.length; i++) { | |
if (availableFlairs[i].selected) availableFlairs[i].selected = false; | |
if (availableFlairs[i].flair === flair) availableFlairs[i].selected = true; | |
} | |
GM_setValue('availableFlairs', availableFlairs); | |
GM_deleteValue('HR_FlairRandom'); | |
$('#HR_RandomFlairsSetAll').fadeOut(800); | |
$('#HR_FlairTable').find('input[name="HR_RandomFlairsSet"]').fadeOut(800); | |
var title = $(selectedFlair).parent().prev().prev().text() + ($(selectedFlair).parent().prev().text() ? ' [' + $(selectedFlair).parent().prev().text() + ']' : ''); | |
$.ajax({method:'post', data:"flair="+selectedFlair.val(), dataType:'text', url:updateurl}).done(function(data) { | |
if ($.parseJSON(data).success === true) { | |
if (flair) { | |
$('#HR_FlairCurrent').css('background', ''); | |
$('#HR_FlairCurrent').css('background-position', $(selectedFlair).parent().prev().prev().prev().children().css('background-position')); | |
$('#HR_FlairCurrent').attr('title', title); | |
} else { | |
$('#HR_FlairCurrent').css('background-image', ''); | |
$('#HR_FlairCurrent').css('background', 'rgba(150,150,200,0.3)'); | |
$('#HR_FlairCurrent').attr('title', 'No Flair Selected'); | |
} | |
$(selectedFlair).parent().prev().prev().append('<span id="HR_SetFlairSuccess" style="display:none; color:#0f0"> ✓</span>'); | |
$('#HR_SetFlairSuccess').fadeIn(100).delay(400).fadeOut(100, function() { $('#HR_SetFlairSuccess').remove(); $('#HR_FlairMenu').fadeOut(200); }); | |
} else { | |
$(selectedFlair).parent().prev().prev().append('<span id="HR_SetFlairSuccess" style="display:none; color:#f00"> ✗</span>'); | |
$('#HR_SetFlairSuccess').fadeIn(100).delay(400).fadeOut(1000, function() { $('#HR_SetFlairSuccess').remove(); }); | |
} | |
}); | |
} | |
} | |
}); | |
} | |
//Change name of group for "Group Play Now"... | |
if (HR_Selections.HR_AddGroupPlayNowButton.value) { | |
$('#HR_PlayPubsInGroup').find('input[name="name"]').val( (displayedName ? displayedName : reservedName) + '\'s Group' ); | |
} | |
}).fail(function() { | |
console.log('HR: Failed to get profile data. profileId: ' + profileId); | |
}); | |
}, 300); | |
} | |
} | |
} | |
if (PageLoc === 'server') { | |
//Create the menu button... | |
$('body').append('<div id="HR_Menu_Button" style="position:fixed; line-height:1.1; bottom:70px; right:10px; background:#fff; color:#0b0; opacity:'+(HR_Selections.HR_HideMenuButton.value ? '0' : '0.25')+'; padding:0 8px; font-size:25px; text-align:center; border-radius:25px; cursor:pointer; z-index:1000" title="Homepage Rearranger">⇢</div>'); | |
$('#HR_Menu_Button').after('<div id="HR_Menu" style="position:fixed; bottom:0px; right:0px; background:sienna; color:#1e063d; padding:20px 20px 10px; font-size:11px; border:2px solid cornsilk; border-radius:6px; overflow:hidden; z-index:1000; display:none"></div>'); | |
//Build the menu... | |
$('#HR_Menu').append('<div id="HR_Menu_Container" style="display:flex"></div>'); | |
$('#HR_Menu_Container').append('<div id="HR_Menu_Adds" style="position:relative; background:burlywood; border-radius:3px; margin:0; padding:8px"></div>'); | |
$.each(HR_Selections, function(key, value) { | |
if (value.type === 'checkbox') { | |
$('#'+HR_Selections[key].submenu).append('<li style="list-style:none"><label><input type="checkbox" id="'+key+'" class="HR_option"'+ (HR_Selections[key].value ? ' checked' : '') + '> ' + HR_Selections[key].display + '</label></li>'); | |
} else if (value.type === 'checkboxlink') { | |
$('#'+HR_Selections[key].submenu).append('<li style="list-style:none"><input type="checkbox" id="'+key+'" class="HR_option"'+ (HR_Selections[key].value ? ' checked' : '') + '> <a href="javascript:void(0);" class="HR_CheckBoxLink" data-key="'+key+'" style="color:#1e063d" title="Click to enter a link...">' + HR_Selections[key].display + '</a></li>'); | |
} | |
}); | |
$('#HR_Menu').append('<div id="HR_Reset" title="Reset all values to defaults">Reset All</div>'); | |
$('#HR_Menu').append('<div id="HR_ReloadPage" title="Reload this page now">Reload Page</div>'); | |
GM_addStyle('#HR_Reset { display:inline-block; margin:10px; padding:3px; font-size:11px; color:#fff; background:#aa0000; opacity:0.5; border-radius:4px; cursor:pointer; float:left }'); | |
GM_addStyle('#HR_Reset:hover { opacity:1 }'); | |
GM_addStyle('#HR_ReloadPage { display:inline-block; margin:10px; padding:3px; font-size:11px; color:#fff; background:#ff7700; opacity:0.5; border-radius:4px; cursor:pointer; float:right }'); | |
GM_addStyle('#HR_ReloadPage:hover { opacity:1 }'); | |
GM_addStyle('#HR_Menu li { margin-bottom:3px; }'); | |
GM_addStyle('#HR_Menu input { height:11px; width:11px; margin:1px 0 0; color:black; }'); | |
GM_addStyle('#HR_Menu label { margin-bottom:0px; font-weight:normal; }'); | |
GM_addStyle('a.HR_CheckBoxLink:hover { border-bottom:1px dotted #333; }'); | |
GM_addStyle('#HR_CurrentServerButton { display:flex; margin:0 auto; padding:5px; width:200px; justify-content:center; align-items:center; flex-flow:column wrap; }'); | |
//hide all popup menus if 'escape' is pressed... | |
$(document).on('keydown', function(e) { | |
if (e.keyCode == 27) { | |
$('#HR_FlairMenu').hide(0); | |
$('#TPTPR_Container').hide(0); | |
$('#HR_Settings').hide(0); | |
} | |
}); | |
$('#HR_Menu').find('.HR_option').on('click', function() { | |
HR_Selections[this.id].value = $(this).is(':checked'); | |
GM_setValue('HR_Selections', HR_Selections); | |
if (this.id === 'HR_ShowGameControls') { | |
if ($(this).is(':checked')) $('#game-controls').fadeIn(300); | |
else $('#game-controls').fadeOut(300); | |
} else if (this.id === 'HR_ShowYoutube1') { | |
//if ($(this).is(':checked')) $('#home-video').fadeIn(300); | |
//else $('#home-video').fadeOut(300); | |
} else if (this.id === 'HR_ShowHomeServer') { | |
if ($(this).is(':checked')) $('.server-stats').fadeIn(300); | |
else $('.server-stats').fadeOut(300); | |
} else if (this.id === 'HR_ShowChangeServer') { | |
if ($(this).is(':checked')) $('.play-now').find('a[href="http://tagpro.koalabeast.com/"]').fadeIn(); | |
else $('.play-now').find('a[href="http://tagpro.koalabeast.com/"]').fadeOut(300); | |
} else if (this.id === 'HR_ShowCommunityChat') { | |
if ($(this).is(':checked')) $('.chat').fadeIn(300); | |
else $('.chat').fadeOut(300); | |
} else if (this.id === 'HR_ShowRedditNews') { | |
if ($(this).is(':checked')) $('.news').fadeIn(300); | |
else $('.news').fadeOut(300); | |
} else if (this.id === 'HR_ShowDonationInfo') { | |
if ($(this).is(':checked')) $('#home-donations').fadeIn(300); | |
else $('#home-donations').fadeOut(300); | |
} else if (this.id === 'HR_HideMenuButton') { | |
if ($(this).is(':checked')) { | |
$('#HR_Menu_Button').css('opacity', '0'); | |
} else { | |
$('#HR_Menu_Button').css('opacity', '0.25'); | |
} | |
} else if (this.id === 'HR_Hide_Footer') { | |
if ($(this).is(':checked')) { | |
$('footer').fadeOut(300); | |
} else { | |
$('footer').fadeIn(300); | |
} | |
} else if (this.id === 'HR_UseBackgroundImage') { | |
if ($(this).is(':checked')) { | |
$('body').css('background', '#2b2b2b url("'+GM_getValue('BackgroundImageLink', '')+'") fixed'); | |
$('#header').css('background', 'none'); | |
$('footer.footer').css('background', 'none'); | |
} else { | |
$('body').css('background', '#2b2b2b'); | |
$('#header').css('background', '#2b2b2b'); | |
$('footer.footer').css('background', '#2b2b2b'); | |
} | |
} | |
}); | |
$('#HR_Menu_Container').on('click', '.HR_CheckBoxLink', function() { | |
if (this.dataset.key === 'HR_UseBackgroundImage' && $('#HR_UseBackgroundImage').is(':checked')) { | |
var link = prompt('Enter link for image, for example...\n\n http://i.imgur.com/l5cbX3r.jpg\n https://i.redd.it/myhs3kehcfgy.png\n', GM_getValue('BackgroundImageLink', '')); | |
if (link) { | |
GM_setValue('BackgroundImageLink', link); | |
$('body').css('background', '#2b2b2b url("'+link+'") fixed'); | |
$('#header').css('background', 'none'); | |
$('footer.footer').css('background', 'none'); | |
} | |
} | |
}); | |
$('#HR_Reset').on('click', function() { | |
var response = confirm("All current positions will be lost and this page will reload.\n\nOK to continue?"); | |
if (response) { | |
resetAll(); | |
window.location.reload(); | |
} | |
}); | |
$('#HR_ReloadPage').on('click', function() { | |
window.location.reload(); | |
}); | |
//================================================================= | |
$('#HR_Menu_Button').on('click', function() { | |
$('#HR_Menu').fadeTo(200, 1); | |
}); | |
$('#HR_Menu_Button').mouseenter(function() { | |
$('#HR_Menu_Button').fadeTo(200, 1); | |
}); | |
$('#HR_Menu_Button').mouseleave(function() { | |
$('#HR_Menu_Button').fadeTo(200, (HR_Selections.HR_HideMenuButton.value ? 0 : 0.25)); | |
}); | |
$("#HR_Menu").mouseleave(function() { | |
$('#HR_Menu').fadeOut(100); | |
}); | |
} else if (HR_Selections.HR_AddPlayNowToOther.value || HR_Selections.HR_AddCurrentServerToOther.value) { | |
$('.userbar').append('<div id="HR_NewButtons" style="display:inline-block; margin-right:20px; vertical-align:top;"></div><div id="HR_TPButtons" style="display:inline-block; vertical-align:top;"></div>'); | |
$('#HR_TPButtons').append( $('#profile-btn') ); | |
$('#HR_TPButtons').append( $('#login-btn') ); | |
$('#HR_TPButtons').append( $('#settings-btn') ); | |
if (HR_Selections.HR_AddCurrentServerToOther.value) { | |
$('.server-stats').hide(); //remove the default one | |
$('#HR_NewButtons').append('<a href="'+window.location.origin+'" class="btn btn-default" style="font:16px Arial; text-transform:capitalize" title="Home">'+window.location.hostname.replace('.koalabeast.com','').replace('tagpro-','')+'<br><span id="HR_CurrentServerButtonStats" style="font-size:11px; font-style:italic"></span>'); | |
if (PageLoc === 'joining') { | |
refreshJoiningStats('#HR_CurrentServerButtonStats', 2000); | |
} else { | |
refreshJoiningStats('#HR_CurrentServerButtonStats', 10000); | |
} | |
} | |
if (HR_Selections.HR_AddPlayNowToOther.value && ((PageLoc !== 'groups') && (PageLoc !== 'joining'))) { | |
$('#HR_NewButtons').prepend('<a href="/games/find" id="HR_PlayNow" class="btn btn-primary" style="">Play Now</a>'); //$('#header').find('.userbar') | |
} | |
} | |
var intervalHandle; | |
function refreshJoiningStats(target, interval) { | |
clearInterval(intervalHandle); | |
var n = Date.now(); | |
$.ajax({timeout:1e4, dataType:"json", url:window.location.origin+'/stats?callback=', success:function(i) { | |
i.ping = Date.now() - n; | |
$(target).text("Ping:"+i.ping + ", Players:"+i.players + (i.playerCapacity?"/"+i.playerCapacity:"") + (i.games?", Games:"+i.games:"")); | |
}, error:function(i){ | |
$(target).text("Error getting server stats"); | |
}}); | |
$(target).fadeOut(100).fadeIn(100); | |
intervalHandle = setInterval(function() { | |
refreshJoiningStats(target, interval); | |
}, interval); | |
} | |
function resetAll() { | |
GM_deleteValue('HR_Selections'); | |
GM_deleteValue('availableFlairs'); | |
GM_deleteValue('HR_FlairRandom'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment