Skip to content

Instantly share code, notes, and snippets.

@nabbynz
Last active April 4, 2017 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nabbynz/913d6feb9d9ebbec10b83a5f8d52b25a to your computer and use it in GitHub Desktop.
Save nabbynz/913d6feb9d9ebbec10b83a5f8d52b25a to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Homepage Redesigner
// @description Modifies your TagPro Homepage to allow dragging & resizing various elements.
// @version 0.0.13
// - v0.0.13: Added Ball Spin to Settings. Added background image option for server home.
// - v0.0.12: Added options to remove new site updates. Added "Group Play Now" button.
// @include http://tagpro-*.koalabeast.com*
// @exclude http://tagpro-maptest.koalabeast.com*
// @exclude http://tagpro-*.koalabeast.com:*
// @connect koalabeast.com
// @connect newcompte.fr
// @connect jukejuice.com
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js
// @require http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.3.0/Chart.min.js
// @require https://cdn.socket.io/socket.io-1.4.5.js
// @resource jqUI_CSS http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.min.css
// @updateURL https://gist.github.com/nabbynz/913d6feb9d9ebbec10b83a5f8d52b25a/raw/TagPro_Homepage_Redesigner.user.js
// @downloadURL https://gist.github.com/nabbynz/913d6feb9d9ebbec10b83a5f8d52b25a/raw/TagPro_Homepage_Redesigner.user.js
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_deleteValue
// @grant GM_getResourceText
// @grant GM_addStyle
// @grant GM_xmlhttpRequest
// @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
// @author nabby
// @run-at document-start
// ==/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.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');
} else if (document.URL.includes('/textures')) {
return('textures');
}
};
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 gone = false;
var hidebodyCount = 0;
function hidebody() {
hidebodyCount++;
PageLoc = WhichPageAreWeOn();
if (!gone) {
if (!$('#HR_Loading').length) $('html').append('<div id="HR_Loading" style="display:flex; position:absolute; justify-content:center; flex-flow:column wrap; text-align:center; color:cadetblue; top:30%; left:0; right:0"><div>Loading / Re-arranging</div><div style="margin-top:20px; font-style:italic">Please wait...</div></div>');
if (document.body && document.hasFocus()) {
$('body').hide(0);
setTimeout(function() {
if (!gone) {
gone = true;
go();
}
}, 1000);
} else {
setTimeout(function() {
if (!gone) hidebody();
}, 10);
}
}
}
if (PageLoc !== 'joining') hidebody();
$(window).load(function() {
var PageLocCount = 0;
if ((PageLoc === undefined) || (PageLoc === 'undefined')) alert('2: PageLoc undefined in window.load() - this should never appear!!!');
while (PageLoc === undefined && PageLocCount < 500) {
PageLocCount++;
setTimeout(function() {
PageLoc = WhichPageAreWeOn();
}, 10);
}
if (!gone) {
gone = true;
go();
}
});
function go() {
$('#HR_Loading').remove();
$('body').show(0);
$('body').css('overflow', 'visible'); //not sure why this sometimes happens
var modifyHome = true;
var $uHome = $('#userscript-home');
var $uTop = $('#userscript-top');
var $uBottom = $('#userscript-bottom');
var $PlayNowButton = $('#play-now');
var profileId;
var loggedIn = $('a[href^="/profile/"]').length;
if (loggedIn) profileId = $('a[href^="/profile/"]').attr('href').substr(-24);
var options = {'HR_ShowGameControls': { display: '&middot; Show Game Controls', submenu:'HR_Menu_Options', type:'checkbox', value:true },
'HR_ShowYoutube1': { display: '&middot; Show Youtube Video', submenu:'HR_Menu_Options', type:'checkbox', value:true },
'HR_ShowHomeServer': { display: '&middot; Show Home Server', submenu:'HR_Menu_Options', type:'checkbox', value:true },
'HR_ShowChangeServer': { display: '&middot; Show Change Server Link', submenu:'HR_Menu_Options', type:'checkbox', value:true },
'HR_ShowCommunityChat': { display: '&middot; Show Community Chat', submenu:'HR_Menu_Options', type:'checkbox', value:true },
'HR_ShowRedditNews': { display: '&middot; Show Reddit News', submenu:'HR_Menu_Options', type:'checkbox', value:true },
'HR_ShowDonationInfo': { display: '&middot; Show Donation Info', submenu:'HR_Menu_Options', type:'checkbox', value:true },
'HR_MovablePlayNow': { display: 'Make &quot;Play Now&quot; Button Movable', submenu:'HR_Menu_Options', type:'checkbox', value:false },
'HR_Modify_Header': { display: 'Make Header Movable*', submenu:'HR_Menu_Options', type:'checkbox', value:false },
'HR_HeaderBackgroundImage': { display: 'Show Background Image in Header', submenu:'HR_Menu_Options', type:'checkbox', value:true },
'HR_EnableDragging': { display: 'Enable Dragging', submenu:'HR_Menu_Options', type:'checkbox', value:true },
'HR_EnableResizing': { display: 'Enable Resizing', submenu:'HR_Menu_Options', type:'checkbox', value:true },
'HR_Hide_Footer': { display: 'Hide Footer', submenu:'HR_Menu_Options', type:'checkbox', value:false },
'HR_HideMenuButton': { display: 'Hide This Menu Button', submenu:'HR_Menu_Options', type:'checkbox', value:false },
'HR_AddCurrentServerButton': { display: 'Add Updating &quot;Current Server Stats&quot; Button*', submenu:'HR_Menu_Adds', type:'checkbox', value:false },
'HR_AddFlairNameDegreeWins': { display: 'Add &quot;Flair, Name, & Wins Until Next Degree&quot; Widget*', submenu:'HR_Menu_Adds', type:'checkbox', value:false },
'HR_AddStatsFromProfile': { display: 'Add &quot;My Stats&quot; Widget*', submenu:'HR_Menu_Adds', type:'checkbox', value:false },
'HR_ShowRotationMapsGraph': { display: 'Add &quot;Maps&quot; Widget*', submenu:'HR_Menu_Adds', type:'checkbox', value:false },
'HR_ShowDWMBoardWinners': { display: 'Add &quot;Leaderboard&quot; Widget*', submenu:'HR_Menu_Adds', type:'checkbox', value:false },
'HR_ShowAllServerStats': { display: 'Add &quot;All Server Stats&quot; Widget*', submenu:'HR_Menu_Adds', type:'checkbox', value:false },
'HR_AddGroupPlayNowButton': { display: 'Add &quot;Group Play Now&quot; Button', submenu:'HR_Menu_Adds', type:'checkbox', value:false },
'HR_AddPlayNowToOther': { display: 'Add &quot;Play Now&quot; Button to Other Pages (in header)', submenu:'HR_Menu_Adds', type:'checkbox', value:false },
'HR_AddCurrentServerToOther': { display: 'Add &quot;Current Server&quot; Button to Other Pages (in header)', 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 &quot;Profile&quot; to Nav Bar*', submenu:'HR_Menu_Adds', type:'checkbox', value:false },
'HR_AddSettingsToNav': { display: 'Add &quot;Quick Settings&quot; Menu to Nav Bar*', submenu:'HR_Menu_Adds', type:'checkbox', value:false },
'HR_ShowLogoutOnNav': { display: 'Add &quot;Logout&quot; to Nav Bar*', submenu:'HR_Menu_Adds', type:'checkbox', value:false },
'HR_ChangeBallsOnLoading': { display: 'Change to Balls on Loading Screen', submenu:'HR_Menu_Adds', type:'checkbox', value:false },
'HR_Theme_None': { display: 'No Theme*', submenu:'HR_Menu_Themes', type:'radio', value:false },
'HR_Theme_Blue': { display: 'Blue', submenu:'HR_Menu_Themes', type:'radio', value:false },
'HR_Theme_Red': { display: 'Red', submenu:'HR_Menu_Themes', type:'radio', value:false },
'HR_Theme_Green': { display: 'Green', submenu:'HR_Menu_Themes', type:'radio', value:false },
'HR_Theme_Silver': { display: 'Silver', submenu:'HR_Menu_Themes', type:'radio', value:false },
'HR_UseBackgroundImage': { display: 'Background', submenu:'HR_Menu_Themes', type:'checkboxlink', 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);
var themes = {'HR_Theme_None': { primary:'#cddc39', secondary:'#c0ca33', default:'#353535', background1:'#2b2b2b', background2:'#333333', background3:'#555555', 'logo':'/images/logo.png' },
'HR_Theme_Blue': { primary:'#1e90ff', secondary:'#87ceeb', default:'#111155', background1:'#222222', background2:'#333333', background3:'#4a4a4a', 'logo':'http://i.imgur.com/enMGRMN.png' },
'HR_Theme_Red': { primary:'#cc3333', secondary:'#ff5555', default:'#551111', background1:'#222222', background2:'#333333', background3:'#4a4a4a', 'logo':'http://i.imgur.com/O4uUPLD.png' },
'HR_Theme_Green': { primary:'#228822', secondary:'#22bb22', default:'#224422', background1:'#222222', background2:'#333333', background3:'#4a4a4a', 'logo':'http://i.imgur.com/G9p3r4c.png' },
'HR_Theme_Silver': { primary:'#666666', secondary:'#444444', default:'#222222', background1:'#999999', background2:'#aaaaaa', background3:'#cccccc', 'logo':'http://i.imgur.com/O4uUPLD.png' },
};
$('#site-nav ul').find('a[href="/"]').text('Home');
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 (PageLoc === 'server') {
if (HR_Selections.HR_MoveProfileToNav.value) {
if (loggedIn) {
$('#site-nav ul').append('<li'+(window.location.href.includes('/profile/') ? ' 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.includes('/settings') ? ' class="active-tab"' : '')+'><a href="/settings">Settings</a></li>');
}
$('.userbar').remove();
}
if (HR_Selections.HR_AddSettingsToNav.value && loggedIn) {
$('#site-nav ul').append('<li'+(window.location.href.includes('/settings') ? ' 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>');
}
}
}
//All Server Stats...
if (HR_Selections.HR_ShowAllServerStats.value) {
//comment to hide in table...
var serverURLs = {
'Diameter' : { name:'Diameter', url:'tagpro-diameter.koalabeast.com', color:'yellow', location:'Sydney', GMT:'10', checked:true },
'Centra' : { name:'Centra', url:'tagpro-centra.koalabeast.com', color:'crimson' , location:'Fremont', GMT:'-7', checked:true },
'Radius' : { name:'Radius', url:'tagpro-radius.koalabeast.com', color:'mediumorchid', location:'Newark', GMT:'-4', checked:true },
'Origin' : { name:'Origin', url:'tagpro-origin.koalabeast.com', color:'lime', location:'Detroit', GMT:'-4', checked:true },
'Pi' : { name:'Pi', url:'tagpro-pi.koalabeast.com', color:'goldenrod', location:'Atlanta', GMT:'-4', checked:true },
'Sphere' : { name:'Sphere', url:'tagpro-sphere.koalabeast.com', color:'tomato', location:'Texas', GMT:'-5', checked:true },
'Chord' : { name:'Chord', url:'tagpro-chord.koalabeast.com', color:'cyan', location:'Paris', GMT:'2', checked:true },
'Orbit' : { name:'Orbit', url:'tagpro-orbit.koalabeast.com', color:'dodgerblue', location:'London', GMT:'1', checked:true },
//'Tangent' : { name:'Tangent', url:'tangent.jukejuice.com', color:'#aaa', location:'', GMT:'', checked:false },
//'MapTest' : { name:'MapTest', url:'tagpro-maptest.koalabeast.com', color:'#aaa', location:'', GMT:'', checked:false },
//'NC_Oceanic' : { name:'NC_Oceanic', url:'oceanic.newcompte.fr', color:'#aaa', location:'Sydney', GMT:'10', checked:false },
//'NC_MapTest2' : { name:'NC_MapTest2', url:'maptest2.newcompte.fr', color:'#aaa', location:'', GMT:'', checked:false },
//'NC_MapTest3' : { name:'NC_MapTest3', url:'maptest3.newcompte.fr', color:'#aaa', location:'', GMT:'', checked:false },
//'NC_Europe' : { name:'NC_Europe', url:'maptest.newcompte.fr', color:'#aaa', location:'Paris', GMT:'2', checked:false },
};
var selectedServers = $.extend(true, {}, serverURLs, GM_getValue('selectedServers', serverURLs));
$.each(selectedServers, function(key, value) {
if (selectedServers.hasOwnProperty(key) && serverURLs.hasOwnProperty(key)) {
$.each(value, function(k, v) {
if (k !== 'checked') selectedServers[key][k] = serverURLs[key][k];
});
} else if (selectedServers.hasOwnProperty(key)) { //a server has been removed, so best we remove it from our saved options too...
delete selectedServers[key];
GM_setValue('selectedServers', selectedServers);
}
});
if (!GM_getValue('selectedServers')) { //first time
GM_setValue('selectedServers', selectedServers);
}
var ping2 = function(server, callback) {
var n = Date.now();
GM_xmlhttpRequest({
method: 'GET',
timeout: 10000,
url: 'http://'+server.url+'/stats', //?callback=?
headers: { "Content-Type": "application/x-www-form-urlencoded" }, //application/x-www-form-urlencoded
onload: function(response) {
if (response.status === 200) {
var data = JSON.parse(response.responseText);
server.ping = ((Date.now() - n) * 0.9).toFixed(0);
server.players = data.players;
server.capacity = data.playerCapacity;
server.games = data.games;
server.error = false;
} else {
server.error = true;
}
callback(server);
},
onerror: function(response) {
server.error = true;
callback(server);
},
ontimeout: function() {
server.error = true;
callback(server);
}
});
};
var comparer = function(index) {
return function(a, b) {
var valA = getCellValue(a, index), valB = getCellValue(b, index);
if (!valA || valA === undefined) valA = '0';
if (!valB || valB === undefined) valB = '0';
if (index === 1) {
return $.isNumeric(valA) && $.isNumeric(valB) ? valA - valB : valB.localeCompare(valA);
} else {
return $.isNumeric(valA) && $.isNumeric(valB) ? valB - valA : valA.localeCompare(valB);
}
};
};
var getCellValue = function(row, index) {
return $(row).children('td').eq(index).data('raw');
};
var sortAndMax = function() {
var $table = $('#HR_ASS_Servers'), $column, prevMax;
for (var i=3; i<=3; i++) {
$column = $('#HR_ASS_Servers tr:gt(0) td:nth-child('+i+')');
prevMax = 0;
$( $column ).each(function(k, v) {
if ($(this).data('raw') > prevMax) {
$($column).removeClass('ASS_Max');
$(this).addClass('ASS_Max');
prevMax = $(this).data('raw');
} else if ($(this).data('raw') === prevMax) {
$(this).addClass('ASS_Max');
}
});
}
//sort the table by last saved...
$('#HR_ASS_Servers').find('th:eq('+GM_getValue('ASS_SortBy', 2)+')').trigger('click', true);
$('#HR_ASS_UpdatingMessage').hide();
$('#HR_ASS_Servers').show();
};
var shortTimeFormat = function(z) {
var day = '';
var hours = z.getHours();
var minutes = z.getMinutes();
if (z.getDay() === 0) day = 'Sun';
else if (z.getDay() === 1) day = 'Mon';
else if (z.getDay() === 2) day = 'Tue';
else if (z.getDay() === 3) day = 'Wed';
else if (z.getDay() === 4) day = 'Thu';
else if (z.getDay() === 5) day = 'Fri';
else if (z.getDay() === 6) day = 'Sat';
if (z.getHours() < 10) hours = '0' + z.getHours();
if (z.getMinutes() < 10) minutes = '0' + z.getMinutes();
return day + ' ' + hours + ':' + minutes;
};
var maxs = {};
var getServerStats = function() {
var count = 0;
$('#HR_ASS_Servers').remove();
$('#HR_ASS').append('<table id="HR_ASS_Servers"><tr><th title="Check server to include when updating"></th><th>Server</th><th title="Local">Time</th><th title="Number of Players">#P</th><th title="Number of Games">#G</th><th title="Maximum number of players (since page was loaded)">Max</th></tr></table>'); //<th>Ping</th>
$('#HR_ASS_Servers').hide();
$('#HR_ASS_UpdatingMessage').show();
var lastChecked;
$.each(selectedServers, function(key, value) {
if (value.checked) lastChecked = key;
});
$.each(selectedServers, function(key, value) {
if (!maxs.hasOwnProperty(key)) maxs[key] = 0;
if (value.checked) {
ping2(value, function(response) {
var x = new Date().getTimezoneOffset();
var y = response.GMT*60;
var z = new Date(Date.now() + ((x+y)*60*1000));
if (response.error) {
$('#HR_ASS_Servers').append('<tr style="color:'+response.color+';'+(response.url === window.location.hostname ? ' background:rgba(200,200,200,0.2);' : '')+'" title="Location: '+response.location+' ('+((x+y)/60)+' Hours)'+'\nLocal Time: '+z.toLocaleTimeString()+', '+z.toDateString()+'">' +
' <td data-raw="checked"><input type="checkbox" class="HR_ASS_ChooseServer" data-raw="'+response.name+'"></td>' +
' <td data-raw="'+response.name+'"><a href="http://'+response.url+'" class="HR_ASS_ServerName" style="color:'+response.color+';">'+response.name+'</a></td>' +
' <td data-raw="'+response.GMT+'">'+shortTimeFormat(z)+'</td>' +
//' <td data-raw="'+0+'" style="color:red">x</td>' +
' <td data-raw="'+0+'" style="color:red">x</td>' +
' <td data-raw="'+0+'" style="color:red">x</td>' +
' <td data-raw="'+0+'" style="color:red">x</td>' +
'</tr>');
} else {
if (response.players > maxs[response.name]) maxs[response.name] = response.players;
$('#HR_ASS_Servers').append('<tr style="color:'+response.color+';'+(response.url === window.location.hostname ? ' background:rgba(200,200,200,0.2);' : '')+'" title="Capacity: '+response.capacity+"\nLocation: "+response.location+' ('+((x+y)/60)+' Hours)'+"\nLocal Time: "+z.toLocaleTimeString()+', '+z.toDateString()+'">' +
' <td data-raw="checked"><input type="checkbox" class="HR_ASS_ChooseServer" data-raw="'+response.name+'" checked></td>' +
' <td data-raw="'+response.name+'"><a href="http://'+response.url+'" class="HR_ASS_ServerName" style="color:'+response.color+';">'+response.name+'</a></td>' +
' <td data-raw="'+response.GMT+'">'+shortTimeFormat(z)+'</td>' +
//' <td data-raw="'+response.ping+'">'+(response.ping===0?'-':response.ping)+'</td>' +
' <td data-raw="'+response.players+'">'+(response.players===0?'-':response.players)+'</td>' +
' <td data-raw="'+response.games+'">'+(response.games===0?'-':response.games)+'</td>' +
' <td data-raw="'+maxs[response.name]+'">'+(maxs[response.name]===0?'-':maxs[response.name])+'</td>' +
'</tr>');
}
if (response.name === lastChecked) setTimeout(sortAndMax, 1000);
});
} else {
var x = new Date().getTimezoneOffset();
var y = value.GMT*60;
var z = new Date(Date.now() + ((x+y)*60*1000));
$('#HR_ASS_Servers').append('<tr style="color:#777;'+(value.url === window.location.hostname ? ' background:rgba(200,200,200,0.2);' : '')+'" title="Location: '+value.location+' ('+((x+y)/60)+' Hours)'+'\nLocal Time: '+z.toLocaleTimeString()+', '+z.toDateString()+'">' +
' <td data-raw="unchecked"><input type="checkbox" class="HR_ASS_ChooseServer" data-raw="'+value.name+'"></td>' +
' <td data-raw="'+value.name+'"><a href="http://'+response.url+'" class="HR_ASS_ServerName">'+value.name+'</a></td>' +
' <td data-raw="'+value.GMT+'">'+shortTimeFormat(z)+'</td>' +
//' <td data-raw="'+0+'" style="color:gray">.</td>' +
' <td data-raw="'+0+'">.</td>' +
' <td data-raw="'+0+'">.</td>' +
' <td data-raw="'+0+'">.</td>' +
'</tr>');
}
});
};
$uHome.append('<div id="HR_ASS" style="display:flex; align-items:center; justify-content:space-around; background:#222"></div>');
$('#HR_ASS').append('<div id="HR_ASS_UpdatingMessage" style="display:none; font:12px Arial; color:yellow; font-style:italic;">Getting Server Stats...</div>');
GM_addStyle('#HR_ASS_Servers { font-size:10px; color:#bbb; text-align:center; border-collapse:collapse; cursor:default }');
GM_addStyle('#HR_ASS_Servers th { background:#ddd; color:#000; font-weight:bold; border:1px solid #569; }');
GM_addStyle('#HR_ASS_Servers td { padding:0 6px; border:1px solid #569; }');
GM_addStyle('.HR_ASS_ServerName { text-decoration:none; }');
GM_addStyle('.HR_ASS_ServerName:hover { text-decoration:underline; }');
$('#HR_ASS').on('click', '.HR_ASS_ChooseServer', function() {
var servers = $('#HR_ASS_Servers').find('input.HR_ASS_ChooseServer');
$.each(servers, function(key, value) {
selectedServers[$(value).data('raw')].checked = $(value).is(':checked');
});
GM_setValue('selectedServers', selectedServers);
});
$('#HR_ASS').on('click', 'th', function(e, preventReverse) {
if ($(this).index() !== GM_getValue('ASS_SortBy', $(this).index())) this.asc = false;
GM_setValue('ASS_SortBy', $(this).index()); //save the header we're sorting by
$('#HR_ASS_Servers').find('th').css('text-decoration', 'none');
$(this).css('text-decoration', 'underline');
var table = $('#HR_ASS_Servers');
var rows = table.find('tr:gt(0)').toArray().sort(comparer($(this).index()));
if (!preventReverse) {
this.asc = !this.asc;
if (!this.asc) rows = rows.reverse();
}
for (var i = 0; i < rows.length; i++) { table.append(rows[i]); }
});
setTimeout(getServerStats, 5000);
setInterval(getServerStats, 120000 + rand(0, 60000));
}
//Refreshing Stats Server Button with Countdown...
if (HR_Selections.HR_AddCurrentServerButton.value) {
var refreshInterval = 10;
var count = refreshInterval - 1;
var refreshCount = 0;
$('body').append('<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").text("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);
}
//Leaderboards Widget...
if (HR_Selections.HR_ShowDWMBoardWinners.value) {
$('body').append('<div id="HR_Boards">' +
' <div id="HR_Boards_Inner" style="font:11px Arial;">' +
' <ul class="tab-list">' +
' <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>' +
'</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);
});
setTimeout(function() {
$.get(window.location.origin+'/boards').done(function(data) {
$('#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...');
});
}, 400);
}
//Maps Widget...
if (HR_Selections.HR_ShowRotationMapsGraph.value) {
var color1 = '#22BB22';
var color2 = '#BB4444';
var color3 = '#333355';
$('body').append('<div id="HR_Mappys">' +
' <div id="HR_Mappys_Inner">' +
' <ul class="tab-list">' +
' <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 &quot;I like it&quot;">Likes</option>' +
' <option value="dislikes" style="color:'+color2+'; font-weight:bold;" title="How many people voted &quot;I dislike it&quot;">Dislikes</option>' +
' <option value="neutral" style="color:'+color3+'; font-weight:bold;" title="How many people voted &quot;I\'m Indifferent&quot;">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" width="40" height="260"></canvas></div>' +
'</div>');
setTimeout(function() {
$.getJSON(window.location.origin+'/maps.json').done(function(rawData) {
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 ctx = $("#HR_Mappys_Graph").get(0).getContext("2d");
var selectedTheme = GM_getValue('selectedTheme', 'HR_Theme_None');
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",
backgroundColor: hexToRGBA(color1, '0.6'),
}, {
type: 'bar',
data: $.map(rawData.rotation, function(value) { return +((value.totalDislikes / value.totalUsers) * 100).toFixed(2); }),
label: "Disliked",
backgroundColor: hexToRGBA(color2, '0.6'),
}, {
type: 'bar',
data: $.map(rawData.rotation, function(value) { return +((value.totalIndifferents / value.totalUsers) * 100).toFixed(2); }),
label: "Neutral",
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(color1, '0.9'),
backgroundColor: hexToRGBA(color1, '0.9'),
hoverBackgroundColor: hexToRGBA(color1, '0.9'),
pointRadius: 2,
pointHoverRadius: 3,
pointBorderColor: hexToRGBA(color1, '0.9'),
pointHoverBorderColor: hexToRGBA(color1, '0.9'),
}]
};
setTimeout(function() {
if ($("#HR_Mappys_Graph").is(":visible")) {
var myChart = new Chart(ctx, {
type: 'bar',
data: graphData,
options: {
tooltips: {
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,
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>');
}
},
maintainAspectRatio:false
}
});
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() {
var current = 'rotation';
if ($('#HR_Retired').hasClass('active')) current = 'retired';
GM_setValue('MapDataSortBy', this.value);
sortMapData();
updateDataSets();
myChart.update();
});
}
}, 300);
}).fail(function(data) {
console.log('HR: Get Map Data Failure...');
//console.log(data);
});
}, 500);
}
}
//Group Play Now - Launch...
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 (let 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) {
$('body').append('<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"></div>');
$('#HR_FlairNameDegreeWins').append('<div id="HR_FlairCurrent" class="flair" style="width:16px; margin-right:4px; cursor:pointer;" title="Show Quick Flair Menu"></div>');
$('#HR_FlairNameDegreeWins').append('<div id="HR_WinsUntilNextDegree"></div>');
}
if (HR_Selections.HR_AddStatsFromProfile.value) {
$('body').append('<div id="HR_Stats"></div>');
}
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 disableBallSpin = document.cookie.replace(/(?:(?:^|.*;\s*)disableBallSpin\s*\=\s*([^;]*).*$)|^.*$/, "$1");
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");
$('#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);
//$('#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();
$('#HR_Settings').find('a[href^="/textures"]').remove(); //removes the textures link
$('#HR_Settings').find('a[href^="/profile/accounts"]').parent('div').parent('div').remove(); //removes the "Link Kongregate Account" link
$('#HR_Settings').find('#showEmail').parent('div').parent('div').remove(); //remove the email link
$('#HR_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.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('&#10003; 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('&#10007; 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('&#10007; 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!");
});
}
});
}
//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':'11px Arial', 'width':'100%' });
$('#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;
}
}
};
$.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);
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 (let 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">&nbsp;&nbsp;&#10003;</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">&nbsp;&nbsp;&#10007;</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') { //only allow rearranging on the server home page
//You can add the id of any other divs that you want to drag & resize here...
var defaultDivs = {'header': { top:20, left:380, width:600, height:120, border:false }, //movable/detached logo+nav header (this script)
'HR_PlayNow': { top:40, left:$('#logo').offset().left+$('#logo').width()+200, width:180, height: 60, border:false }, //new detached "Play Now" button (this script)
'HR_CurrentServerButton': { top:0, left:$('#logo').offset().left+$('#logo').width()+370, width:180, height: 60, border:false }, //updating Server button (this script)
'HR_FlairNameDegreeWins': { top:110, left:$('#logo').offset().left+$('#logo').width()+80, width:360, height: 30, border:false }, //Current Display Name, Current Flair, Flair Menu & Wins Until Next Degree (this script)
'HR_Stats': { top:400, left:0, width:340, height: 365, border:false }, //Stats from "Profile" Page (this script)
'HR_Mappys': { top:0, left:0, width:780, height:300, border:true }, //Maps Bar Graph (this script)
'HR_Boards': { top:500, left:600, width:600, height:300, border:true }, //Leaderboards (this script)
'HR_ASS': { top:200, left:200, width:200, height:300, border:true }, //All Server Stats (this script)
'HR_PlayPubsInGroup': { top:200, left:200, width:150, height:60, border:false }, //
'USS': { top:200, left:200, width:200, height:300, border:true }, //Updating Server Stats (In Game) Ping Graph
'HR_Footer': { top:1000, left:0, width:800, height:140, border:false }, //koalabeast footer
'ReplayMenuButton': { top:40, left:$('#logo').offset().left+$('#logo').width()+20, width:170, height: 60, border:false }, //Replays Extension
'CTS_Container': { top:0, left:0, width:780, height:150, border:true }, //KFC Timeline
'R300': { top:0, left:0, width:780, height:350, border:true }, //Rolling 300 Timeline
'O300': { top:0, left:0, width:780, height:350, border:true }, //Stats Off R300 Timeline
'DWP': { top:0, left:0, width:780, height:200, border:true }, //Daily Win Percentage & Timeline
'WLT': { top:0, left:0, width:780, height:300, border:true }, //Win/Loss Timeline (old)
'ROT': { top:0, left:0, width:400, height:560, border:true }, //Reddit on TagPro
'MapFreq': { top:0, left:0, width:860, height:550, border:true }, //MapStats
'SBPR': { top:0, left:0, width:780, height:300, border:true }, //Scoreboard Position Recorder
'MVE': { top:0, left:0, width:780, height:300, border:true }, //Me vs. Everyone
'SLB': { top:0, left:0, width:780, height:300, border:true }, //?
'ASS': { top:0, left:0, width:780, height:300, border:true }, //All Server Stats
};
var divsToMove = $.extend(true, {}, defaultDivs, GM_getValue('divsToMove', defaultDivs));
$.each(divsToMove, function(key, value) {
if (!defaultDivs.hasOwnProperty(key)) { //something has been removed from the list above, so remove it from our saved list too.
console.log('Removing from divsToMove: ' + key);
delete divsToMove[key];
GM_setValue('divsToMove', divsToMove);
}
});
if (!GM_getValue('divsToMove')) GM_setValue('divsToMove', divsToMove);
//useful when debugging movable divs...
//console.log(divsToMove);
//delete divsToMove.HR_AddCurrentServerButton;
//GM_setValue('divsToMove', divsToMove);
var $header = $('.header');
var $middle = $('.home');
var $footer = $('.footer');
var $body = $('body');
//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.1')+'; padding:0 8px; font-size:25px; text-align:center; border-radius:25px; cursor:pointer; z-index:1000" title="Homepage Rearranger">&#8674;</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_Options" style="position:relative; background:burlywood; border-radius:3px; margin:0; padding:8px"></div>');
$('#HR_Menu_Container').append('<div id="HR_Menu_Adds" style="position:relative; background:burlywood; border-radius:3px; margin:0 0 0 20px; padding:8px"></div>');
$('#HR_Menu_Container').append('<div id="HR_Menu_Themes" style="position:relative; background:burlywood; border-radius:3px; margin:0 0 0 20px; 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 === 'radio') {
$('#'+HR_Selections[key].submenu).append('<li style="list-style:none"><label><input type="radio" id="'+key+'" class="HR_Theme" name="HR_Themes"'+ (GM_getValue('selectedTheme', 'HR_Theme_None') === key ? ' 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 input { height:11px; width:11px; margin:1px 0 0; color:black; }');
GM_addStyle('#HR_Menu label { margin-bottom:3px; font-weight:normal; }');
GM_addStyle('a.HR_CheckBoxLink:hover { border-bottom:1px dotted #333; }');
$('#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');
}
}
});
//Create a new movable "Play Now" button...
$('#play-now').clone().attr('id', 'HR_PlayNow').appendTo($body);
if (HR_Selections.HR_MovablePlayNow.value) {
$('#play-now').hide();
$('#HR_PlayNow').show();
$PlayNowButton = $('#HR_PlayNow');
} else {
$('#HR_PlayNow').hide();
}
GM_addStyle('#HR_PlayNow, #HR_CurrentServerButton { display:flex; padding:0; justify-content:center; align-items:center; flex-flow:column wrap; }');
//Add an id to the footer so we can drag it...
$('footer').attr('id', 'HR_Footer');
//Hide various elements as needed...
if (!HR_Selections.HR_ShowGameControls.value) $('#game-controls').hide();
if (!HR_Selections.HR_ShowYoutube1.value) $('#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();
//Add "Group Play Now"...
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();
});
}
//If the header isn't movable, then remove it from our list of movable objects...
if (!HR_Selections.HR_Modify_Header.value) {
delete divsToMove.header;
}
var jqUI_CssSrc;
if (modifyHome) {
jqUI_CssSrc = GM_getResourceText("jqUI_CSS"); //this just allows us to drag things around
GM_addStyle(jqUI_CssSrc);
modifyHomeLayout();
if (HR_Selections.HR_EnableResizing.value) {
$.each(divsToMove, function(id) {
if (id !== 'HR_Footer') $('#'+id).resizable('option', { disabled:false } );
});
} else {
$.each(divsToMove, function(id) {
if (id !== 'HR_Footer') $('#'+id).resizable('option', { disabled:true } );
});
}
}
//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_Theme').on('click', function() {
if (this.id !== GM_getValue('selectedTheme', 'HR_Theme_None')) {
GM_setValue('selectedTheme', this.id);
modifyCSS('HR_Change_Theme');
}
});
$('#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_EnableDragging') {
if ($(this).is(':checked')) {
$.each(divsToMove, function(id) {
$('#'+id).draggable('enable');
});
} else {
$.each(divsToMove, function(id) {
$('#'+id).draggable('disable');
});
}
} else if (this.id === 'HR_EnableResizing') {
if ($(this).is(':checked')) {
$.each(divsToMove, function(id) {
if (id !== 'HR_Footer') $('#'+id).resizable('option', { disabled:false } );
});
} else {
$.each(divsToMove, function(id) {
if (id !== 'HR_Footer') $('#'+id).resizable('option', { disabled:true } );
});
}
} else if (this.id === 'HR_MovablePlayNow') {
if ($(this).is(':checked')) {
if (!$('#HR_PlayNow').length) $('#play-now').clone().attr('id', 'HR_PlayNow').appendTo($body);
$('#play-now').hide();
$('#HR_PlayNow').show();
$PlayNowButton = $('#HR_PlayNow');
} else {
$('#HR_PlayNow').hide();
$('#play-now').show();
$PlayNowButton = $('#play-now');
}
} else 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.1');
}
} else if (this.id === 'HR_HeaderBackgroundImage') {
modifyCSS('HR_HeaderBackgroundImage');
} else if (this.id === 'HR_Hide_Footer') {
modifyCSS('HR_Hide_Footer');
} else if (this.id === 'HR_UseBackgroundImage') {
modifyCSS();
}
});
$('#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.0);
});
$('#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.1));
});
$("#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;
//"Ping:"+i.ping +
$(target).text("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);
}
modifyCSS();
function resetAll() {
GM_deleteValue('divsToMove');
GM_deleteValue('HR_Selections');
GM_deleteValue('selectedTheme');
}
function modifyCSS(single) {
var selectedTheme = GM_getValue('selectedTheme', 'HR_Theme_None');
if (!single || single === 'HR_Change_Theme') {
if (selectedTheme !== 'HR_Theme_None') {
//change the logo...
$('h1.logo').find('img').attr('src', themes[selectedTheme].logo);
//all headers & links in a .container...
GM_addStyle('.container h1 { color:'+themes[selectedTheme].primary+'; }');
GM_addStyle('.container h2 { color:'+themes[selectedTheme].primary+'; }');
GM_addStyle('.container h3 { color:'+themes[selectedTheme].primary+'; }');
GM_addStyle('.container a:not(.btn) { color:'+themes[selectedTheme].primary+'; }');
GM_addStyle('.container a:not(.btn):hover { color:'+themes[selectedTheme].secondary+'; }');
//buttons...
GM_addStyle('.btn { background:'+themes[selectedTheme].primary+'; border:1px solid '+themes[selectedTheme].primary+'; box-shadow:none; }');
GM_addStyle('.btn:active { background:'+themes[selectedTheme].primary+'; }');
GM_addStyle('.btn:focus { background:'+themes[selectedTheme].primary+'; }');
GM_addStyle('.btn:hover { background:'+themes[selectedTheme].primary+'; border:1px solid #fff; box-shadow:0 0 5px white; }');
GM_addStyle('.btn-primary { background:'+themes[selectedTheme].primary+'; border:1px solid '+themes[selectedTheme].primary+'; box-shadow:none; }');
GM_addStyle('.btn-primary:active { background:'+themes[selectedTheme].primary+'; }');
GM_addStyle('.btn-primary:focus { background:'+themes[selectedTheme].primary+'; }');
GM_addStyle('.btn-primary:hover { background:'+themes[selectedTheme].primary+'; border:1px solid #fff; box-shadow:0 0 5px white; }');
GM_addStyle('.btn-secondary { background:'+themes[selectedTheme].secondary+'; border:1px solid '+themes[selectedTheme].secondary+'; box-shadow:none; }');
GM_addStyle('.btn-secondary:active { background:'+themes[selectedTheme].secondary+'; }');
GM_addStyle('.btn-secondary:focus { background:'+themes[selectedTheme].secondary+'; }');
GM_addStyle('.btn-secondary:hover { background:'+themes[selectedTheme].secondary+'; border:1px solid #bbb; box-shadow:0 0 5px white; }');
GM_addStyle('.btn-default { background:'+themes[selectedTheme].default+'; border:1px solid '+themes[selectedTheme].default+'; box-shadow:none; }');
GM_addStyle('.btn-default:active { background:'+themes[selectedTheme].default+'; }');
GM_addStyle('.btn-default:focus { background:'+themes[selectedTheme].default+'; }');
GM_addStyle('.btn-default:hover { background:'+themes[selectedTheme].default+'; border:1px solid #bbb; box-shadow:0 0 5px white; }');
//nav bar...
//GM_addStyle('#site-nav { background:'+themes[selectedTheme].background1+'; }');
GM_addStyle('.header .nav a:hover { color:'+themes[selectedTheme].secondary+'; }');
GM_addStyle('.header .nav .active-tab a { color:'+themes[selectedTheme].primary+'; }');
//group...
GM_addStyle('.group #pub-players .player-group-header { background:'+themes[selectedTheme].primary+'; }');
GM_addStyle('.header .nav .group-indicator { color:'+themes[selectedTheme].primary+'; }');
GM_addStyle('#group .header-title { color:'+themes[selectedTheme].primary+'; }');
GM_addStyle('.groups-list .group-item .group-name { color:'+themes[selectedTheme].primary+'; }');
//leaderboards...
GM_addStyle('.leaderboard-menu li.active { background:'+themes[selectedTheme].primary+'; }');
GM_addStyle('.leaderboard-menu li:hover { color:'+themes[selectedTheme].secondary+'; }');
GM_addStyle('.leaderboard-menu ul { border-right:2px solid '+themes[selectedTheme].primary+'; }');
GM_addStyle('.table-stripped thead { background:'+themes[selectedTheme].primary+'; }');
GM_addStyle('#HR_Boards_Inner div a { color:'+themes[selectedTheme].primary+'; }');
GM_addStyle('#HR_Boards_Inner div a:hover { color:'+themes[selectedTheme].secondary+'; }');
//tabs...
GM_addStyle('.tab-list { margin-bottom:6px; font:14px Arial; border-bottom:1px solid '+themes[selectedTheme].primary+'; }');
GM_addStyle('.tab-list li a { color:'+themes[selectedTheme].background3+'; }');
GM_addStyle('.tab-list li a:hover { color:'+themes[selectedTheme].secondary+'; }');
GM_addStyle('.tab-list li.active { border:1px solid '+themes[selectedTheme].primary+'; background:'+themes[selectedTheme].background2+'; border-bottom:none; }');
GM_addStyle('.tab-list li.active a { color:'+themes[selectedTheme].primary+'; }');
//maps...
GM_addStyle('.maps .map-detail .name { color:'+themes[selectedTheme].primary+'; }');
GM_addStyle('.maps .tooltip .name { color:'+themes[selectedTheme].secondary+'; }');
GM_addStyle('.maps .graph svg text { fill:'+themes[selectedTheme].primary+'; }');
GM_addStyle('.maps .dot { fill:'+themes[selectedTheme].secondary+'; }');
GM_addStyle('.maps .dot.active { fill:'+themes[selectedTheme].primary+'; }');
//profile/settings...
GM_addStyle('.profile .header-title { color:'+themes[selectedTheme].primary+'; }');
GM_addStyle('.profile .table td.table-row-label { color:'+themes[selectedTheme].primary+'; }');
GM_addStyle('.profile .flair-tooltip .flair-type { color:'+themes[selectedTheme].primary+'; }');
GM_addStyle('.form-control:focus { border-color:'+themes[selectedTheme].primary+'; box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px '+themes[selectedTheme].primary+' }');
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');
} else {
$('body').css('background', themes[selectedTheme].background1);
$('#header').css('background', themes[selectedTheme].background1);
$('footer.footer').css('background', themes[selectedTheme].background1);
}
if (single) single = 'HR_Modify_Header';
}
}
if (!single || single === 'HR_Modify_Header') {
if (PageLoc === 'server' && HR_Selections.HR_Modify_Header.value) {
//$('#header').css('z-index', '2');
//GM_addStyle('.nav { width:100% }');
GM_addStyle('.header-main { padding:0; width:auto; }');
GM_addStyle('#logo { padding:10px }');
GM_addStyle('#header { padding:0; border-bottom:none }');
GM_addStyle('#header .nav a { padding:5px 12px; font-size:12px; }');
GM_addStyle('#header .nav li { margin-right:0; border-radius:3px; }');
GM_addStyle('#header .nav li:hover { background:'+themes[selectedTheme].background3+'; }');
GM_addStyle('#header .nav { background:'+themes[selectedTheme].background2+'; bottom:0; }');
GM_addStyle('#header .nav .active-tab a { background:none; border:none }');
}
}
if (!single || single === 'HR_HeaderBackgroundImage') {
if (HR_Selections.HR_HeaderBackgroundImage.value) {
$('#header').css('background', '#2b2b2b url(\'/images/background_cropped.jpg\') no-repeat bottom');
} else {
if (HR_Selections.HR_UseBackgroundImage.value) {
$('#header').css('background', 'none');
} else {
if (HR_Selections.HR_Modify_Header.value) {
$('#header').css('background', 'none');
} else {
$('#header').css('background', themes[selectedTheme].background2);
}
}
}
}
if (!single || single === 'HR_Hide_Footer') {
if (HR_Selections.HR_Hide_Footer.value) {
$('footer').fadeOut(200);
} else {
$('footer').fadeIn(200);
}
}
}
function modifyHomeLayout() {
var bodyHeightBuffer = 0;
var oldCSS;
var divsCount = Object.keys(defaultDivs).length;
$body.css('height', $(window).height() + 'px');
$body.css('margin', '0');
$.each(divsToMove, function(id, value) {
if ( ($('#'+id).length) ) {
$body.append($('#'+id)); //move to body so we can drag anywhere on the page
$('#'+id).addClass('HR_Moveable');
$('#'+id).css('position', 'absolute');
$('#'+id).css('margin', '0px auto');
$('#'+id).css('padding', '0');
$('#'+id).css('z-index', divsCount);
divsCount -= 1;
$('#'+id).css('top', value.top);
$('#'+id).css('height', value.height);
if (id !== 'HR_Footer') {
$('#'+id).css('left', value.left);
$('#'+id).css('width', value.width);
$('#'+id).resizable({
containment: $body,
delay: 100,
//grid: [10,10],
disabled: !HR_Selections.HR_EnableResizing.value,
start: function() {
oldCSS = $('#'+id).css('border');
},
resize: function(event, ui) {
$('#'+id).css('border', '1px dashed white');
},
stop: function(event, ui) {
event.stopPropagation();
event.stopImmediatePropagation();
divsToMove[id].width = ui.size.width;
divsToMove[id].height = ui.size.height;
GM_setValue('divsToMove', divsToMove);
$('#'+id).css('border', oldCSS);
$('#'+id).css('outline', 'none');
}
});
}
$('#'+id).draggable({
//containment: $body,
axis: (id === 'HR_Footer' ? 'y' : ''),
delay: 100,
//grid: [10,10],
disabled: !HR_Selections.HR_EnableDragging.value,
scroll: true,
start: function(event, ui) {
oldCSS = $('#'+id).css('border');
},
drag: function(event, ui) {
$('#'+id).css('border', '1px dashed white');
},
stop: function(event, ui) {
event.stopPropagation();
event.stopImmediatePropagation();
divsToMove[id].top = ui.offset.top;
divsToMove[id].left = ui.offset.left;
GM_setValue('divsToMove', divsToMove);
$('#'+id).css('border', oldCSS);
$('#'+id).css('outline', 'none');
if (id === 'HR_Footer') {
$body.css('height', ($('#HR_Footer').position().top + $('#HR_Footer').height()) + 'px');
}
}
});
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment