Skip to content

Instantly share code, notes, and snippets.

@theVDude
Created September 2, 2014 18:29
Show Gist options
  • Select an option

  • Save theVDude/35b37d20904cf88e6a5d to your computer and use it in GitHub Desktop.

Select an option

Save theVDude/35b37d20904cf88e6a5d to your computer and use it in GitHub Desktop.
TagPro In Game Settings Editor
// ==UserScript==
// @name Tagpro In-Game Settings
// @version 0.1
// @description Modify settings such as showing names and degrees in-game
// @include http://tagpro-*.koalabeast.com/*
// @include http://tagpro-*.koalabeast.com:*
// @author Some Ball -1
// @grant GM_getValue
// @grant GM_setValue
// ==/UserScript==
$(function() {
var registeredName = "Some Ball 1"; //put your registered name here in between the double quotation marks
var saveData = true; //set to true to save the settings between games, false to modify only in-game
if(saveData)
{
var act = GM_getValue('settingsSaved'); //check if there's anything new to update
if(act)
{
var vals = GM_getValue('vals'); //grab the saved values
//all the items we need to store and send
/*{allChat: true
degrees: true
displayedName: true
groupChat: true
matchState: true
names: true
performanceInfo: true
reservedName: true
spectatorInfo: true
stats: true
systemChat: true
teamChat: true};*/
}
}
if(tagpro.host.match(/.+:\d*/)) //URL has a port number, so in a game
{
tagpro.ready(function() {
var items = tagpro.settings.ui;
items['stats'] = true; //filler because undefined at the moment
if(saveData) //include Game Stats checkbox and Submit button
{
$('#name').parent().after('<table><tbody><tr><td style="text-align:left;"><label id="allChat" class="setting"><input name="allChat" type="checkbox" for="allChat" checked="" class="post"><span>Show all chat</span></label></td><td style="text-align:left;"><label id="teamChat" class="setting"><input name="teamChat" type="checkbox" for="teamChat" checked="" class="post"><span>Show team chat</span></label></td><td style="text-align:left;"><label id="groupChat" class="setting"><input name="groupChat" type="checkbox" for="groupChat" checked="" class="post"><span>Show group chat</span></label></td><td style="text-align:left;"><label id="systemChat" class="setting"><input name="systemChat" type="checkbox" for="systemChat" checked="" class="post"><span>Show system messages</span></label></td></tr><tr><td style="text-align:left;"><label id="spectatorInfo" class="setting"><input name="spectatorInfo" type="checkbox" for="spectatorInfo" checked="" class="post"><span>Show spectator state</span></label></td><td style="text-align:left;"><label id="performanceInfo" class="setting"><input name="performanceInfo" type="checkbox" for="performanceInfo" checked="" class="post"><span>Show fps and ping</span></label></td><td style="text-align:left;"><label id="matchState" class="setting"><input name="matchState" type="checkbox" for="matchState" checked="" class="post"><span>Show time, score &amp; flag state</span></label></td><td id="submitText" style="text-align:right; font:10px Lucida Grande;"></td></tr><tr><td style="text-align:left;"><label id="names" class="setting"><input name="names" type="checkbox" for="names" checked="" class="post"><span>Player names</span></label></td><td style="text-align:left;"><label id="degrees" class="setting"><input name="degrees" type="checkbox" for="degrees" checked="" class="post"><span>Player degrees</span></label></td><td style="text-align:left;"><label id="stats" class="setting"><input name="stats" type="checkbox" for="stats" class="post"><span>Collect game stats</span></label></td><td><button type="button" id="submit" style="margin-left:100px;">Submit</button></td></tr></tbody></table>');
}
else //don't include Game Stats checkbox and Submit button
{
$('#name').parent().after('<table><tbody><tr><td style="text-align:left;"><label id="allChat" class="setting"><input name="allChat" type="checkbox" for="allChat" checked="" class="post"><span>Show all chat</span></label></td><td style="text-align:left;"><label id="teamChat" class="setting"><input name="teamChat" type="checkbox" for="teamChat" checked="" class="post"><span>Show team chat</span></label></td><td style="text-align:left;"><label id="groupChat" class="setting"><input name="groupChat" type="checkbox" for="groupChat" checked="" class="post"><span>Show group chat</span></label></td></tr><tr><td style="text-align:left;"><label id="systemChat" class="setting"><input name="systemChat" type="checkbox" for="systemChat" checked="" class="post"><span>Show system messages</span></label></td><td style="text-align:left;"><label id="spectatorInfo" class="setting"><input name="spectatorInfo" type="checkbox" for="spectatorInfo" checked="" class="post"><span>Show spectator state</span></label></td><td style="text-align:left;"><label id="performanceInfo" class="setting"><input name="performanceInfo" type="checkbox" for="performanceInfo" checked="" class="post"><span>Show fps and ping</span></label></td></tr><tr><td style="text-align:left;"><label id="matchState" class="setting"><input name="matchState" type="checkbox" for="matchState" checked="" class="post"><span>Show time, score &amp; flag state</span></label></td><td style="text-align:left;"><label id="names" class="setting"><input name="names" type="checkbox" for="names" checked="" class="post"><span>Player names</span></label></td><td style="text-align:left;"><label id="degrees" class="setting"><input name="degrees" type="checkbox" for="degrees" checked="" class="post"><span>Player degrees</span></label></td></tr></tbody></table>');
}
$('.post').each(function() { //run through all objects of class 'post' (all the checkboxes)
if(this.name=='names')
{
$(this).prop('checked', items[this.name]);
$(this).change(function() {
var which = $(this).prop('checked');
tagpro.settings.ui.names = which;
items['names'] = which;
for(var x in tagpro.players)
{
tagpro.players[x].cache.update(); //update names for everyone
}
});
}
else if(this.name=='degrees')
{
$(this).prop('checked', items[this.name]);
$(this).change(function() {
var which = $(this).prop('checked');
tagpro.settings.ui.degrees = which;
items['degrees'] = which;
for(var x in tagpro.players)
{
tagpro.players[x].cache.update(); //update degrees for everyone
}
});
}
else if(this.name=='allChat')
{
$(this).prop('checked', items[this.name]);
$(this).change(function() {
var which = $(this).prop('checked');
tagpro.settings.ui.allChat = which; //not need to manually update anything, this is fine
items['allChat'] = which;
});
}
else if(this.name=='teamChat')
{
$(this).prop('checked', items[this.name]);
$(this).change(function() {
var which = $(this).prop('checked');
tagpro.settings.ui.teamChat = which;
items['teamChat'] = which;
});
}
else if(this.name=='groupChat')
{
$(this).prop('checked', items[this.name]);
$(this).change(function() {
var which = $(this).prop('checked');
tagpro.settings.ui.groupChat = which;
items['groupChat'] = which;
});
}
else if(this.name=='systemChat')
{
$(this).prop('checked', items[this.name]);
$(this).change(function() {
var which = $(this).prop('checked');
tagpro.settings.ui.systemChat = which;
items['systemChat'] = which;
});
}
else if(this.name=='spectatorInfo')
{
$(this).prop('checked', items[this.name]);
$(this).change(function() {
var which = $(this).prop('checked');
tagpro.settings.ui.spectatorInfo = which;
items['spectatorInfo'] = which;
});
}
else if(this.name=='performanceInfo')
{
$(this).prop('checked', items[this.name]);
$(this).change(function() {
var which = $(this).prop('checked');
tagpro.settings.ui.performanceInfo = which;
items['performanceInfo'] = which;
});
}
else if(this.name=='matchState')
{
$(this).prop('checked', items[this.name]);
$(this).change(function() {
var which = $(this).prop('checked');
tagpro.settings.ui.matchState = which;
items['matchState'] = which;
});
}
else if(this.name=='stats')
{
setTimeout(function(stat) { //this one is delayed a bit for whatever reason, so put it in a setTimeout
items['stats'] = tagpro.settings.stats;
stat.prop('checked', items['stats']);
stat.change(function() {
var which = stat.prop('checked');
tagpro.settings.stats = which;
items['stats'] = which;
});
},1000,$(this));
}
});
$('#submit').click(function() {
var player = tagpro.players[tagpro.playerId];
if(player.auth) //if they are playing under their reg name, then override the saved name just in case it's wrong (becaue we KNOW this is right)
{
registeredName = player.name;
}
if(registeredName!='')
{
items['displayedName'] = player.name;
items['reservedName'] = registeredName;
GM_setValue('settingsSaved', true); //set to true so we know there's new values to update
GM_setValue('vals', items);
vals = items;
$('#submitText').css('color','#00ff00');
$('#submitText').text('Settings will save on game exit.');
setTimeout(function() {
$('#submitText').text('');
}, 3500);
}
else
{
$('#submitText').css('color','#ff0000');
$('#submitText').text('No registered name, cannot save.');
setTimeout(function() {
$('#submitText').text('');
}, 3500);
}
});
});
}
else if(saveData && act)
{
jQuery.ajax({url:'http://'+document.location.hostname+'/profile/update',type:'POST',dataType:undefined,data:vals,success:function(e){
GM_setValue('settingsSaved', false); //don't keep overwriting settings in case things are changed in profile page
if(e.error)
{
alert('Your settings could not be saved due to the following error:\n'+e.error);
}
}});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment