Last active
September 29, 2015 00:01
-
-
Save theVDude/90b00a98fdbf23ee2b9e to your computer and use it in GitHub Desktop.
Tagpro Chat Enhancer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name TagPro Chat Enhancer | |
// @namespace http://www.reddit.com/user/-omicron-/ | |
// @description Disables ingame chat messages while logging messages outside the game environment with the same styling/formating but allowing for all kinds of extra functionality in doing so. | |
// @include http://tagpro-*.koalabeast.com:* | |
// @include http://tagpro-*.koalabeast.com/groups/* | |
// @include http://tangent.jukejuice.com:* | |
// @include http://tangent.jukejuice.com/groups/* | |
// @include http://maptest.newcompte.fr:* | |
// @include http://maptest.newcompte.fr/groups/* | |
// @include http://maptest2.newcompte.fr:* | |
// @include http://maptest2.newcompte.fr/groups/* | |
// @require http://reanimated.net/tagpro/jquery.mCustomScrollbar.concat.min.js | |
// @require http://reanimated.net/tagpro/Autolinker.min.js | |
// @require http://reanimated.net/tagpro/jquery.a-tools-1.4.1.js | |
// @require http://reanimated.net/tagpro/jquery.asuggest.js | |
// @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html | |
// @author OmicroN | |
// @version 3.2.1 | |
// ==/UserScript== | |
// Returns "group", "game", or false, depending on our location. | |
function getLocation() { | |
var url = w.location.href; | |
if (/http:\/\/tagpro-.+?\.koalabeast\.com:\d+?/.test(url) || | |
/http:\/\/tangent\.jukejuice\.com:\d+?/.test(url) || | |
/http:\/\/maptest2?\.newcompte\.fr:\d+?/.test(url)) { | |
return "game"; | |
} else if (/http:\/\/tagpro-.+?\.koalabeast\.com\/groups\/.+?/.test(url) || | |
/http:\/\/tangent\.jukejuice\.com\/groups\/.+?/.test(url) || | |
/http:\/\/maptest2?\.newcompte\.fr\/groups\/.+?/.test(url)) { | |
return "group"; | |
} else { | |
return false; | |
} | |
} | |
tagpro.ready(function() { | |
// Whether to auto save the chat log at the end of every match | |
// automatically. | |
var SAVELOGEVERYGAME = false; | |
// Toggle when clicking the save chat download button if the | |
// download starts right away or when the game ends/window unloads | |
var STARTSAVEONGAMEEND = true; | |
// Sets the snap point in pixels for resizing the chat windows | |
// height, this is to prevent you from resizing the window where | |
// words get cut off at the top when scrolling. Adjust according | |
// to your systems font and how the text is displayed ingame. | |
var RESIZEHEIGHTSNAP = 14; | |
// Toggle whether to save the chat window via absolute position | |
// of the top left corner of the browser (false) or relative | |
// position of the top left corner of the games viewport (true). | |
// Using true will make it so if you resize your browser the chat | |
// will be repositioned b | |
var RELATIVEVIEWPORT = true; | |
// Delay to fade the chat after no activity in milliseconds, | |
// default 10000 (10 seconds) | |
var FADEDELAY = 10000; | |
// true = show auto complete of names automatically while being | |
// typed, false = only auto complete on tab press | |
var AUTOCOMPLETE = true; | |
///////////////////////////////////////////////////////////////// | |
var CHATINPUTSTYLED = false; | |
var CLICKEDID = null, | |
CLICKEDNAME = null; | |
var PLAYERLIST = [], | |
PLAYERSINGAME = [], | |
PLAYERSTEAM = []; | |
var FIRSTRUNCHECK = false, | |
CHATFADE = null, | |
AUTOSCROLL = true; | |
var CEHEIGHT, CETOP, CELEFT, CEWIDTH = getCookie('ce-width'); | |
tagpro.keys.chatAsMod = [76]; | |
// jQuery draggable plugin | |
(function($) { | |
$.fn.drag = function(options) { | |
options = $.extend({ | |
handle: null, | |
cursor: 'move', | |
draggingClass: 'dragging' | |
}, options); | |
var $handle = this, | |
$drag = this; | |
if (options.handle) { | |
$handle = $(options.handle); | |
} | |
$handle.css('cursor', options.cursor).on("mousedown", function(e) { | |
var x = $drag.offset().left - e.pageX, | |
y = $drag.offset().top - e.pageY, | |
z = $drag.css('z-index'); | |
$drag.css('z-index', 100000); | |
$(document.documentElement).on('mousemove.drag', function(e) { | |
$drag.offset({ | |
left: x + e.pageX, | |
top: y + e.pageY | |
}); | |
}).one('mouseup', function() { | |
if (RELATIVEVIEWPORT) { | |
setCookie('ce-top', $drag.offset().top - $('#viewport').offset().top, 365); | |
setCookie('ce-left', $drag.offset().left - $('#viewport').offset().left, 365); | |
} else { | |
setCookie('ce-top', $drag.offset().top, 365); | |
setCookie('ce-left', $drag.offset().left, 365); | |
} | |
$(this).off('mousemove.drag'); | |
$drag.css('z-index', z); | |
}); | |
// disable selection | |
e.preventDefault(); | |
}); | |
}; | |
})(jQuery); | |
// Function prototype to add format method to the Date object | |
// (author: (SO) meizz) | |
Date.prototype.format = function(format) { | |
var hours = this.getHours(); | |
var ttime = "AM"; | |
if (format.indexOf("t") > -1 && hours > 12) { | |
hours = hours - 12; | |
ttime = "PM"; | |
} | |
var o = { | |
"M+": this.getMonth() + 1, | |
//month | |
"d+": this.getDate(), | |
//day | |
"h+": hours, | |
//hour | |
"m+": this.getMinutes(), | |
//minute | |
"s+": this.getSeconds(), | |
//second | |
"q+": Math.floor((this.getMonth() + 3) / 3), | |
//quarter | |
"S": this.getMilliseconds(), | |
//millisecond | |
"t+": ttime | |
}; | |
if (/(y+)/.test(format)) { | |
format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); | |
} | |
for (var k in o) { | |
if (new RegExp("(" + k + ")").test(format)) { | |
if (format.replace(RegExp.$1, RegExp.$1.length == 1)) { | |
format = o[k]; | |
} else { | |
format = ("00" + o[k]).substr(("" + o[k]).length); | |
} | |
} | |
} | |
return format; | |
} | |
// Takes an object and returns the number of properties possessed | |
// by it. | |
function objectLength(obj) { | |
var result = 0; | |
for (var prop in obj) { | |
if (obj.hasOwnProperty(prop)) { | |
result++; | |
} | |
} | |
return result; | |
} | |
// Function to save chat to txt file | |
function exportChat() { | |
var d = new Date(); | |
window.URL = window.webkitURL || window.URL; | |
var bb = new Blob([$('<div>').html($('#message-logger .mCSB_container').html().replace(/<br\s?\/?>/gi, '_br2nl_')).text().replace(/_br2nl_/gi, '\r\n')], { | |
type: 'text/plain' | |
}); | |
var event = document.createEvent('MouseEvents') | |
event.initEvent('click', true, false); | |
var a = document.createElement('a'); | |
a.download = d.format("yyyy-MM-dd hh.mm.ss") + ' ' + tagpro.host.replace(':', ' ') + ' chatlog.txt'; | |
a.href = window.URL.createObjectURL(bb); | |
a.dispatchEvent(event); | |
} | |
// Helper function to set cookie | |
function setCookie(cname, cvalue, exdays) { | |
var d = new Date(); | |
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); | |
var expires = "expires=" + d.toGMTString(); | |
var domain = location.hostname.split('.'); | |
if (domain.length != 2) domain.shift(); | |
document.cookie = cname + "=" + cvalue + "; " + expires + ";path=/;domain=" + domain.join('.'); | |
} | |
// Helper function to get cookie | |
function getCookie(cname) { | |
var name = cname + "=", | |
ca = document.cookie.split(';'); | |
for (var i = 0; i < ca.length; i++) { | |
var c = ca[i].trim(); | |
if (c.indexOf(name) == 0) return c.substring(name.length, c.length); | |
} | |
return ""; | |
} | |
// Helper function to load/inject external javascript onto page | |
function getScript(url, success) { | |
var script = document.createElement('script'), | |
head = document.getElementsByTagName('head')[0], | |
done = false; | |
script.src = url; | |
// Attach handlers for all browsers | |
script.onload = script.onreadystatechange = function() { | |
if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) { | |
done = true; | |
success(); | |
script.onload = script.onreadystatechange = null; | |
head.removeChild(script); | |
} | |
}; | |
head.appendChild(script); | |
} | |
// Helper function to escape HTML characters to prevent code injection | |
function htmlEscape(str) { | |
return String(str).replace(/&/g, '&').replace(/"/g, '"').replace(/'/g, ''').replace(/</g, '<').replace(/>/g, '>'); | |
} | |
// Check if setting to save chat log of every game is enabled | |
if (SAVELOGEVERYGAME) { | |
// Call save chat function on browser unload event | |
$(window).on('beforeunload', function() { | |
exportChat(); | |
}); | |
} | |
// Create a new style element to load up external css for jquery custom scrollbar script | |
var STYLE = document.createElement('link'); | |
STYLE.setAttribute("rel", "stylesheet"); | |
STYLE.setAttribute("type", "text/css"); | |
STYLE.href = 'http://reanimated.net/tagpro/jquery.mCustomScrollbar.css'; | |
document.body.appendChild(STYLE); | |
// if width isn't set from cookie then first load so set defaults and save to cookie | |
if (CEWIDTH == "") { | |
CEWIDTH = 500; | |
CEHEIGHT = 70; | |
FIRSTRUNCHECK = true; | |
setCookie('ce-width', CEWIDTH, 365); | |
setCookie('ce-height', CEHEIGHT, 365); | |
} else { // load last saved position/size of chat container into variables | |
CEWIDTH = parseInt(getCookie('ce-width')); | |
CEHEIGHT = parseInt(getCookie('ce-height')); | |
CETOP = parseInt(getCookie('ce-top')); | |
CELEFT = parseInt(getCookie('ce-left')); | |
} | |
if (RELATIVEVIEWPORT) { | |
delay = null; | |
CETOP = $('#viewport').offset().top + parseInt(getCookie('ce-top')); | |
CELEFT = $('#viewport').offset().left + parseInt(getCookie('ce-left')); | |
$(window).resize(function() { | |
delay && clearTimeout(delay), delay = setTimeout(function() { | |
delay = null; | |
CETOP = $('#viewport').offset().top + parseInt(getCookie('ce-top')); | |
CELEFT = $('#viewport').offset().left + parseInt(getCookie('ce-left')); | |
$('#message-logger').css('top', CETOP).css('left', CELEFT); | |
}, 1000) | |
}); | |
} | |
$('body').append('<div id="message-logger" style="position: absolute; z-index: 100; box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; padding: 5px 0px 5px 12px; left: ' + CELEFT + 'px; top: ' + CETOP + 'px; width: ' + CEWIDTH + 'px; height: ' + CEHEIGHT + 'px; font-family: Arial; font-size: 11px; color: #fff; text-shadow: 0px 0px 10px #000, 0px 0px 10px #000, 0px 0px 10px #000, -1px -1px 1px #000, 1px 1px 1px #000, -1px 1px 1px #000, 1px -1px 1px #000, 0px 0px 3px #000; font-weight: bold;"><div class="data" style="height: 100%; box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box;"> </div><div class="draghandle" title="Move Chat Area" style="z-index: 100; width: 16px; height: 16px; top: 0; left: 0; position: absolute; background: URL(\'http://reanimated.net/tagpro/move.png\') no-repeat; display: none; margin: 5px;"></div> <div class="savechat" title="Save Chat" style="cursor: pointer; z-index: 100; width: 16px; height: 16px; top: 20px; left: 0; position: absolute; background: URL(\'http://reanimated.net/tagpro/download.png\') no-repeat; display: none; margin: 5px;"></div><div class="resizehandle" title="Resize Chat Area" style="z-index: 100; width: 10px; height: 10px; bottom: 0; right: 0; position: absolute; background: URL(\'http://reanimated.net/tagpro/resize.png\') no-repeat; margin: 0px; cursor: nwse-resize; display: none;"></div></div>'); | |
// Initiate jQuery custome scrollbars on chat containers data element, feel free to change theme and/or google additional settings for this plugin if you wish | |
$("#message-logger .data").mCustomScrollbar({ | |
set_width: '100%', | |
set_height: '100%', | |
horizontalScroll: false, | |
mouseWheelPixels: 50, | |
theme: "light", | |
/*"light", "dark", "light-2", "dark-2", "light-thick", "dark-thick", "light-thin", "dark-thin"*/ | |
callbacks: { | |
onScroll: function() { | |
if (mcs.topPct == 100) AUTOSCROLL = true; | |
else AUTOSCROLL = false; | |
} | |
} | |
}).find('.mCSB_container').css('padding', '5px 5px 5px 15px').css('marginRight', '10px'); | |
$("#message-logger .data").mCustomScrollbar("update"); | |
$("#message-logger .data").mCustomScrollbar('scrollTo', 'bottom'); | |
$("#message-logger .mCSB_draggerContainer").css('visibility', 'hidden'); | |
$('#message-logger .savechat').on('click', function() { | |
if (STARTSAVEONGAMEEND) { | |
$(window).on('beforeunload', function() { | |
exportChat(); | |
}); | |
$('#message-logger .data').fadeIn(); | |
if (typeof $("#message-logger .data").mCustomScrollbar !== "undefined") $("#message-logger .data").mCustomScrollbar("update"); | |
$('#message-logger .mCSB_container').append('<span style="color: #cccccc;">Chat log will be downloaded at the end of the match.</span><br />'); | |
// New message appended to chat container so update/inform custom scrollbar plugin of new lengths and auto scroll to bottom of chat container to show new message | |
if (typeof $("#message-logger .data").mCustomScrollbar !== "undefined") { | |
$("#message-logger .data").mCustomScrollbar("update"); | |
if (AUTOSCROLL) $("#message-logger .data").mCustomScrollbar('scrollTo', 'bottom'); | |
} | |
if (FADEDELAY && $('#chat').is(':hidden')) { | |
clearTimeout(CHATFADE); | |
CHATFADE = setTimeout(function() { | |
$('#message-logger .data').fadeOut('slow'); | |
}, FADEDELAY); | |
} | |
} else { | |
exportChat(); | |
} | |
}); | |
// On mouse over of chat container, show boundary box along with move/resize handles | |
$('#message-logger').on('mouseover', function() { | |
$('#message-logger .data').fadeIn(); | |
clearTimeout(CHATFADE); | |
$(this).css('boxShadow', '0px 0px 0px 3px rgba(255,255,255,0.3)'); | |
$(this).find('.draghandle').show(); | |
$(this).find('.savechat').show(); | |
$(this).find('.resizehandle').show(); | |
$("#message-logger .mCSB_draggerContainer").css('visibility', 'visible'); | |
}).on('mouseout', function() { // On mouse out hide boundary box and move/resize handles | |
if (FADEDELAY && $('#chat').is(':hidden')) { | |
CHATFADE = setTimeout(function() { | |
$('#message-logger .data').fadeOut('slow'); | |
}, FADEDELAY); | |
} | |
$(this).css('boxShadow', 'none'); | |
$(this).find('.draghandle').hide(); | |
$(this).find('.savechat').hide(); | |
$(this).find('.resizehandle').hide(); | |
$("#message-logger .mCSB_draggerContainer").css('visibility', 'hidden'); | |
}).drag({ | |
handle: '.draghandle' | |
}); | |
// Code to handle resizing of chat container | |
$('#message-logger .resizehandle').on('mousedown', function(e) { | |
$(document).on('mousemove.drag', function(e) { | |
var x = e.pageX - $('#message-logger').offset().left + 5 + parseInt($('#message-logger .resizehandle').css('marginRight')), | |
y = e.pageY - $('#message-logger').offset().top + 5 + parseInt($('#message-logger .resizehandle').css('marginRight')); | |
x = (x < 200) ? x = 200 : x = x; | |
y = (Math.round(y / RESIZEHEIGHTSNAP) < 3) ? 3 * RESIZEHEIGHTSNAP : Math.round(y / RESIZEHEIGHTSNAP) * RESIZEHEIGHTSNAP; | |
$('#message-logger').css('boxShadow', '0px 0px 0px 3px rgba(255,255,255,0.3)'); | |
$('#message-logger').find('.draghandle').show(); | |
$('#message-logger').find('.savechat').show(); | |
$('#message-logger').find('.resizehandle').show(); | |
$("#message-logger .mCSB_draggerContainer").css('visibility', 'visible') | |
$('#message-logger').css('width', x); | |
$('#message-logger').css('height', y); | |
$("#message-logger .data").mCustomScrollbar("update"); | |
}).one('mouseup', function() { | |
$('#message-logger').css('boxShadow', 'none'); | |
$('#message-logger').find('.draghandle').hide(); | |
$('#message-logger').find('.savechat').hide(); | |
$('#message-logger').find('.resizehandle').hide(); | |
$("#message-logger .mCSB_draggerContainer").css('visibility', 'hidden'); | |
setCookie('ce-width', parseInt($('#message-logger').css('width')), 365); | |
setCookie('ce-height', parseInt($('#message-logger').css('height')), 365); | |
$(this).off('mousemove.drag'); | |
}); | |
e.preventDefault(); | |
}); | |
// Initiate our script in the 'map event' as thats one of the first events fired when you connect to a match | |
tagpro.socket.on('map', function(data) { | |
tagpro.settings.ui.allChat = false; | |
tagpro.settings.ui.groupChat = false; | |
tagpro.settings.ui.systemChat = false; | |
tagpro.settings.ui.teamChat = false; | |
$('#chat').on('focus', function() { | |
$(this).css('top', $('#message-logger').offset().top + $('#message-logger').height() + 5).css('left', $('#message-logger').offset().left + 25); | |
clearTimeout(CHATFADE); | |
$('#message-logger .data').fadeIn(); | |
}); | |
//console.log('chats disabled on ' + data.info.name + ' - ' + data.info.author); | |
if (FIRSTRUNCHECK) { | |
function canvasPositionCheck() { | |
if ($('#viewport')[0].offsetParent != null) { | |
CETOP = $('#viewport').offset().top + 25; | |
CELEFT = $('#viewport').offset().left - 8; | |
if (RELATIVEVIEWPORT) { | |
CETOP = 25; | |
CELEFT = -8; | |
} | |
setCookie('ce-top', CETOP, 365); | |
setCookie('ce-left', CELEFT, 365); | |
if (RELATIVEVIEWPORT) { | |
$('#message-logger').css('top', $('#viewport').offset().top + CETOP).css('left', $('#viewport').offset().left + CELEFT); | |
} else { | |
$('#message-logger').css('top', CETOP).css('left', CELEFT); | |
} | |
} else { | |
setTimeout(function() { | |
canvasPositionCheck(); | |
}, 100); | |
} | |
} | |
canvasPositionCheck(); | |
} | |
if (RELATIVEVIEWPORT && !FIRSTRUNCHECK) { | |
function setPositionOnLoad() { | |
if ($('#viewport')[0].offsetParent != null) { | |
CETOP = $('#viewport').offset().top + parseInt(getCookie('ce-top')); | |
CELEFT = $('#viewport').offset().left + parseInt(getCookie('ce-left')); | |
$('#message-logger').css('top', CETOP).css('left', CELEFT); | |
} else { | |
setTimeout(function() { | |
setPositionOnLoad(); | |
}, 100); | |
} | |
} | |
setPositionOnLoad(); | |
} | |
$(document).keyup(function(char) { | |
if ($('#chat').is(':visible') && tagpro.disableControls) { | |
if ((char.keyCode == 13 || char.keyCode == 77 || char.keyCode == 222 || char.keyCode == 84 || char.keyCode == 186 || char.keyCode == 71 || char.keyCode == 103 || char.keyCode == 116 && char.originalEvent.keyIdentifier != "F5") && tagpro.disableControls && !CHATINPUTSTYLED) { | |
if ($("#name").is(":focus")) return; | |
$('#chat').css('outline', '#ccc solid 1px'); | |
if (char.keyCode == 13) $('#chat').css('border', '2px solid #ffffff'); | |
if (char.keyCode == 222 || char.keyCode == 84) { | |
if (tagpro.spectator == 'watching') | |
{ | |
$('#chat').css('border', '2px solid #ffffff'); | |
} | |
else | |
{ | |
if (tagpro.players[tagpro.playerId] == 1) { | |
$('#chat').css('border', '2px solid #ff0000'); | |
} else { | |
$('#chat').css('border', '2px solid #0000ff'); | |
} | |
} | |
} | |
if (char.keyCode == 77) $('#chat').css('border', '2px solid #00B900'); | |
if (char.keyCode == 186 || char.keyCode == 71 || char.keyCode == 103) $('#chat').css('border', '2px solid gold'); | |
CHATINPUTSTYLED = true; | |
} | |
} else { | |
if ($('#chat').is(':hidden') && CHATINPUTSTYLED) { | |
$('#chat').css('border', 'none'); | |
if (FADEDELAY && $('#chat').is(':hidden')) { | |
clearTimeout(CHATFADE); | |
CHATFADE = setTimeout(function() { | |
$('#message-logger .data').fadeOut('slow'); | |
}, FADEDELAY); | |
} | |
CHATINPUTSTYLED = false; | |
} | |
} | |
}); | |
$('body').on('click', 'span.scoreName', function(e) { | |
for (playerId in tagpro.players) { | |
if (tagpro.players[playerId].name == $(this).html()) { | |
if ($('#ec-options').length) { | |
// Show options where mouse was clicked | |
$('#ec-options').css('left', e.pageX - 110).css('top', e.pageY - 30).show(); | |
} else { | |
// Show options where mouse was clicked | |
$('body').append('<div id="ec-options" style="position: absolute; left: ' + (e.pageX - 110) + 'px; top: ' + (e.pageY - 30) + 'px; z-index: 999; color: ##00FF00; text-shadow: 0px 0px 10px #000, 0px 0px 10px #000, 0px 0px 10px #000, -1px -1px 1px #000, 1px 1px 1px #000, -1px 1px 1px #000, 1px -1px 1px #000, 0px 0px 3px #000; white-space: nowrap; height: 70px; border: 1px solid black; font-size: 11px;"><div style="position: absolute; left: 0; top: 0; width: 100%; height: 100%; background-color: #fff; border: 1px solid #fff; opacity: .6; z-index: -1;"></div><div class="list" style="position: static; left: 0; top: 0; width: 100%; height: 100%;"> <a style="display: block; white-space: nowrap; font-weight: bold; text-align: center; padding: 4px; cursor: pointer;" class="ec-report">Report Player <span class="ec-name"></span></a> <hr style="opacity: .1; margin: 0;"> <a style="display: block; white-space: nowrap; font-weight: bold; text-align: center; padding: 4px; cursor: pointer;" class="ec-profile">Goto <span class="ec-name"></span> Profile / <span class="ec-modprofile">Goto MOD Page</span></a> <hr style="opacity: .1; margin: 0;"> <a style="display: block; white-space: nowrap; font-weight: bold; text-align: center; padding: 4px; cursor: pointer;" class="ec-stats">Lookup <span class="ec-name"></span> TP-Stats</a></div></div>'); | |
} | |
CLICKEDID = playerId; | |
CLICKEDNAME = tagpro.players[playerId].name; | |
$('#ec-options .ec-name').html(decodeURIComponent(CLICKEDNAME)); | |
break; | |
} | |
} | |
}); | |
// Monitor click events on player name in chat | |
$('body').on('click', '.playeroptions', function(e) { | |
// Check if player options on click is on the page | |
if ($('#ec-options').length) { | |
// Show options where mouse was clicked | |
$('#ec-options').css('left', e.pageX - 60).css('top', e.pageY - 30).show(); | |
} else { | |
// Show options where mouse was clicked | |
$('body').append('<div id="ec-options" style="position: absolute; left: ' + (e.pageX - 60) + 'px; top: ' + (e.pageY - 30) + 'px; z-index: 999; color: ##00FF00; text-shadow: 0px 0px 10px #000, 0px 0px 10px #000, 0px 0px 10px #000, -1px -1px 1px #000, 1px 1px 1px #000, -1px 1px 1px #000, 1px -1px 1px #000, 0px 0px 3px #000; white-space: nowrap; height: 70px; border: 1px solid black; font-size: 11px;"><div style="position: absolute; left: 0; top: 0; width: 100%; height: 100%; background-color: #fff; border: 1px solid #fff; opacity: .6; z-index: -1;"></div><div class="list" style="position: static; left: 0; top: 0; width: 100%; height: 100%;"> <a style="display: block; white-space: nowrap; font-weight: bold; text-align: center; padding: 4px; cursor: pointer;" class="ec-report">Report Player <span class="ec-name"></span></a> <hr style="opacity: .1; margin: 0;"> <a style="display: block; white-space: nowrap; font-weight: bold; text-align: center; padding: 4px; cursor: pointer;" class="ec-profile">Goto <span class="ec-name"></span> Profile / <span class="ec-modprofile">Goto MOD Page</span></a> <hr style="opacity: .1; margin: 0;"> <a style="display: block; white-space: nowrap; font-weight: bold; text-align: center; padding: 4px; cursor: pointer;" class="ec-stats">Lookup <span class="ec-name"></span> TP-Stats</a></div></div>'); | |
} | |
if ($(this).attr('pid') == undefined) { | |
$('.ec-report').css('cursor', 'default'); | |
$('.ec-report').css('color', '#ccc'); | |
} else { | |
$('.ec-report').css('cursor', 'pointer'); | |
$('.ec-report').css('color', '#00FF00'); | |
} | |
// Store player id and player name of clicked player incase user selects an option | |
CLICKEDID = $(this).attr('pid'); | |
CLICKEDNAME = $(this).attr('pname'); | |
$('#ec-options .ec-name').html(decodeURIComponent(CLICKEDNAME)); | |
}); | |
// Hide options on mouseout of div | |
$('body').on('mouseleave', '#ec-options', function() { | |
$('#ec-options .ec-name').html(''); | |
$(this).hide(); | |
}); | |
// Show report player prompt if "Report Player" option clicked | |
$('body').on('click', '#ec-options .ec-report', function() { | |
// Since we also make group chat player names clickable, only show the report prompt if CLICKEDID contains an id which means its a user ingame | |
if (typeof CLICKEDID !== "undefined") { | |
tagpro.kick.player(tagpro.players[CLICKEDID]); | |
} | |
$('#ec-options .ec-name').html(''); | |
$('#ec-options').hide(); | |
}); | |
// Lookup player on my site using tagpro-stats db to get tagpro profile id | |
$('body').on('click', '#ec-options .ec-modprofile', function(e) { | |
e.stopPropagation(); | |
$.get('http://tagpro-stats.com/chat_lookup.php?name=' + CLICKEDNAME, function(results) { | |
//results = $.parseJSON(data); | |
// If player found and has a tagpro profile id then open a popup to the users profile in another window | |
if (results['profile'] != null) { | |
window.open('http://tagpro-origin.koalabeast.com/moderate/users/' + results['profile'], 'tagpromodprofile', 'height=747,width=857,menubar=no,location=no,status=no,toolbar=no'); | |
} else { | |
// Player not found in DB so display message in chat saying so | |
$('#message-logger .mCSB_container').append('<span style="color: #999">Could not find the profile id for "' + decodeURIComponent(CLICKEDNAME) + '".</span><br />'); | |
} | |
}); | |
$('#ec-options .ec-name').html(''); | |
$('#ec-options').hide(); | |
}); | |
// Lookup player on my site using tagpro-stats db to get tagpro profile id | |
$('body').on('click', '#ec-options .ec-profile', function() { | |
$.get('http://tagpro-stats.com/chat_lookup.php?name=' + CLICKEDNAME, function(results) { | |
//results = $.parseJSON(data); | |
// If player found and has a tagpro profile id then open a popup to the users profile in another window | |
if (results['profile'] != null) { | |
window.open('http://tagpro-pi.koalabeast.com/profile/' + results['profile'], 'tagproprofile', 'height=747,width=857,menubar=no,location=no,status=no,toolbar=no'); | |
} else { | |
// Player not found in DB so display message in chat saying so | |
$('#message-logger .mCSB_container').append('<span style="color: #999">Could not find the profile id for "' + decodeURIComponent(CLICKEDNAME) + '".</span><br />'); | |
} | |
}); | |
$('#ec-options .ec-name').html(''); | |
$('#ec-options').hide(); | |
}); | |
// Lookup player on my site using tagpro-stats db to get tagpro-stats id | |
$('body').on('click', '#ec-options .ec-stats', function() { | |
$.get('http://tagpro-stats.com/chat_lookup.php?name=' + CLICKEDNAME, function(results) { | |
//results = $.parseJSON(data); | |
// If player found and has a tagpro-stats id then open a popup to the users tagpro-stats.com in another window | |
if (results['id'] != null) { | |
window.open('http://tagpro-stats.com/profile.php?userid=' + results['id'], 'tagprostats', 'height=747,width=857,menubar=no,location=no,status=no,toolbar=no'); | |
} else { | |
// Player not found in DB so display message in chat saying so | |
$('#message-logger .mCSB_container').append('<span style="color: #999">Could not find the tagpro-stats id for "' + decodeURIComponent(CLICKEDNAME) + '".</span><br />'); | |
} | |
}); | |
$('#ec-options .ec-name').html(''); | |
$('#ec-options').hide(); | |
}); | |
// Monitor all chat messages | |
tagpro.socket.on('chat', function(data) { | |
// Bug when the 'sign' sound fires it emites both a "sound" and "chat" emit which causes an "undefined" message to show in chat from my chatenhancer | |
if (typeof data.s !== "undefined") return; | |
$('#message-logger .data').fadeIn(); | |
if (typeof $("#message-logger .data").mCustomScrollbar !== "undefined") $("#message-logger .data").mCustomScrollbar("update"); | |
// Message has no from then its from the system, display in default white text | |
if (data.from == null) { | |
if (typeof data.c !== "undefined") { // If system message contains a c property then it has a custom color to display the message in (flair reward messages) | |
$('#message-logger .mCSB_container').append('<span style="color: ' + data.c + '">' + data.message + '</span><br />'); | |
} else { // Message is a basic system message, show in white | |
var pattern = /'(.+?)' has (connected|joined the Red team|joined the Blue team)\./i; | |
var results = pattern.exec(data.message); | |
if (results != null) { | |
/* | |
setInterval(function() { | |
for (var pID in tagpro.players) { | |
if (tagpro.players[pID].name == results[1]) { | |
$('#message-logger .mCSB_container').append(tagpro.players[pID].name + ' has joined the ' + (tagpro.players[pID].team == '1' ? '<span style="color: #FFB5BD;">red team</span>' : '<span style="color: #CFCFFF;">blue team</span>') + '.<br />'); | |
break; | |
} | |
} | |
}, 100); | |
*/ | |
} else { | |
var pattern = /'(.+?)' has left the (Red team|Blue team|game)\./i; | |
var results = pattern.exec(data.message); | |
if (results != null) { | |
// Player has left message found but player leaving chat message is handled elsewhere in the script so ignore the message | |
} else { | |
var pattern = /'(.+?)' has switched teams\./; | |
var results = pattern.exec(data.message); | |
if (results != null) { | |
for (var pID in tagpro.players) { | |
if (tagpro.players[pID].name == results[1]) { | |
$('#message-logger .mCSB_container').append(tagpro.players[pID].name + ' has switched to the ' + (tagpro.players[pID].team == '1' ? '<span style="color: #CFCFFF;">blue team</span>' : '<span style="color: #FFB5BD;">red team</span>') + '.<br />'); | |
break; | |
} | |
} | |
} else { | |
$('#message-logger .mCSB_container').append(data.message + '<br />'); | |
} | |
} | |
} | |
} | |
} else { | |
// Message to 'team' rather then 'all' so we need to display the whole message in team color rathern then just the player name | |
if (data.to == 'team') { | |
// Check to see what team the person who sent the message is from, if team = 1 then red and write message with FFB5BD else team = 2 blue so write with CFCFFF | |
if (tagpro.players[data.from].team == '1') { // Message from red team player to team, show in red | |
$('#message-logger .mCSB_container').append('<span style="color: #FFB5BD;"><span style="z-index: 10; cursor: pointer;" class="playeroptions" pid="' + data.from + '" pname="' + encodeURIComponent(tagpro.players[data.from].name) + '">' + (tagpro.players[data.from].auth == true ? '<span style="color: #BFFF00;">✓</span> ' : '') + tagpro.players[data.from].name + '</span><span style="font-weight: normal">:</span> ' + Autolinker.link(htmlEscape(data.message).replace(/%20/g, ' '), { | |
stripPrefix: false | |
}) + '</span><br />'); | |
} else { // Message from blue team player to team, show in blue | |
$('#message-logger .mCSB_container').append('<span style="color: #CFCFFF;"><span style="z-index: 10; cursor: pointer;" class="playeroptions" pid="' + data.from + '" pname="' + encodeURIComponent(tagpro.players[data.from].name) + '">' + (tagpro.players[data.from].auth == true ? '<span style="color: #BFFF00;">✓</span> ' : '') + tagpro.players[data.from].name + '</span><span style="font-weight: normal">:</span> ' + Autolinker.link(htmlEscape(data.message).replace(/%20/g, ' '), { | |
stripPrefix: false | |
}) + '</span><br />'); | |
} | |
} else { | |
if (typeof data.mod !== "undefined") { | |
// Message is from a mod, show in green | |
$('#message-logger .mCSB_container').append('<span style="color: #00B900; z-index: 10;">' + data.from + ': ' + Autolinker.link(htmlEscape(data.message).replace(/%20/g, ' '), { | |
stripPrefix: false | |
}) + '</span><br />'); | |
} | |
else | |
{ | |
// Check to see what team the person who sent the message is from, if team = 1 then red and write message in white but name with FFB5BD else team = 2 blue so write name with CFCFFF | |
if (tagpro.players[data.from].team == '1') { // Message from red team player, show in white but name in red | |
$('#message-logger .mCSB_container').append('<span style="color: #FFB5BD; z-index: 10; cursor: pointer;" class="playeroptions" pid="' + data.from + '" pname="' + encodeURIComponent(tagpro.players[data.from].name) + '">' + (tagpro.players[data.from].auth == true ? '<span style="color: #BFFF00;">✓</span> ' : '') + tagpro.players[data.from].name + '</span><span style="font-weight: normal">:</span> ' + Autolinker.link(htmlEscape(data.message).replace(/%20/g, ' '), { | |
stripPrefix: false | |
}) + '<br />'); | |
} else { // Message from blue team player, show in white but name in blue | |
$('#message-logger .mCSB_container').append('<span style="color: #CFCFFF; z-index: 10; cursor: pointer;" class="playeroptions" pid="' + data.from + '" pname="' + encodeURIComponent(tagpro.players[data.from].name) + '">' + (tagpro.players[data.from].auth == true ? '<span style="color: #BFFF00;">✓</span> ' : '') + tagpro.players[data.from].name + '</span><span style="font-weight: normal">:</span> ' + Autolinker.link(htmlEscape(data.message).replace(/%20/g, ' '), { | |
stripPrefix: false | |
}) + '<br />'); | |
} | |
} | |
} | |
} | |
// New message appended to chat container so update/inform custom scrollbar plugin of new lengths and auto scroll to bottom of chat container to show new message | |
if (typeof $("#message-logger .data").mCustomScrollbar !== "undefined") { | |
$("#message-logger .data").mCustomScrollbar("update"); | |
if (AUTOSCROLL) $("#message-logger .data").mCustomScrollbar('scrollTo', 'bottom'); | |
} | |
if (FADEDELAY && $('#chat').is(':hidden')) { | |
clearTimeout(CHATFADE); | |
CHATFADE = setTimeout(function() { | |
$('#message-logger .data').fadeOut('slow'); | |
}, FADEDELAY); | |
} | |
}); | |
}); | |
// We will also initiate our script in settings as its also one of the first events fired but also the player list will have generated and plus we need to override the chat settings to disable them again | |
tagpro.socket.on('settings', function(data) { | |
tagpro.settings.ui.allChat = false; | |
tagpro.settings.ui.groupChat = false; | |
tagpro.settings.ui.systemChat = false; | |
tagpro.settings.ui.teamChat = false; | |
for (playerId in tagpro.players) { | |
if (PLAYERLIST.indexOf(tagpro.players[playerId].name) == -1) | |
PLAYERLIST.push(tagpro.players[playerId].name); | |
PLAYERSINGAME[playerId] = tagpro.players[playerId].name; | |
PLAYERSTEAM[playerId] = tagpro.players[playerId].team; | |
} | |
$("#chat").asuggest(PLAYERLIST, { | |
'stopSuggestionKeys': [$.asuggestKeys.RETURN], | |
'minChunkSize': 1, | |
'delimiters': ' \n', | |
'cycleOnTab': true, | |
'autoComplete': AUTOCOMPLETE, | |
'ignoreCase': true | |
}); | |
tagpro.socket.on('playerLeft', function(playerId) { | |
$('#message-logger .data').fadeIn(); | |
if (typeof $("#message-logger .data").mCustomScrollbar !== "undefined") | |
$("#message-logger .data").mCustomScrollbar("update"); | |
$('#message-logger .mCSB_container').append(PLAYERSINGAME[playerId] + ' has left the ' + (PLAYERSTEAM[playerId] == '1' ? '<span style="color: #FFB5BD;">red team</span>' : '<span style="color: #CFCFFF;">blue team</span>') + '.<br />'); | |
PLAYERLIST.splice(PLAYERLIST.indexOf(PLAYERSINGAME[playerId]), 1); | |
delete PLAYERSINGAME[playerId]; | |
delete PLAYERSTEAM[playerId]; | |
// New message appended to chat container so update/inform custom scrollbar plugin of new lengths and auto scroll to bottom of chat container to show new message | |
if (typeof $("#message-logger .data").mCustomScrollbar !== "undefined") { | |
$("#message-logger .data").mCustomScrollbar("update"); | |
if (AUTOSCROLL) $("#message-logger .data").mCustomScrollbar('scrollTo', 'bottom'); | |
} | |
if (FADEDELAY && $('#chat').is(':hidden')) { | |
clearTimeout(CHATFADE); | |
CHATFADE = setTimeout(function() { | |
$('#message-logger .data').fadeOut('slow'); | |
}, FADEDELAY); | |
} | |
}); | |
tagpro.socket.on('p', function(data) { | |
data = data.u || data; | |
for (var i = 0; i < data.length; i++) { | |
if (typeof data[i].id !== "undefined" && typeof data[i].name !== "undefined") { | |
if (PLAYERLIST.indexOf(data[i].name) == -1) | |
{ | |
PLAYERLIST.push(data[i].name); | |
} | |
else | |
{ | |
continue; | |
} | |
PLAYERSINGAME[data[i].id] = data[i].name; | |
PLAYERSTEAM[data[i].id] = data[i].team; | |
$('#message-logger .data').fadeIn(); | |
if (typeof $("#message-logger .data").mCustomScrollbar !== "undefined") $("#message-logger .data").mCustomScrollbar("update"); | |
$('#message-logger .mCSB_container').append(data[i].name + ' has joined the ' + (data[i].team == '1' ? '<span style="color: #FFB5BD;">red team</span>' : '<span style="color: #CFCFFF;">blue team</span>') + '.<br />'); | |
// New message appended to chat container so update/inform custom scrollbar plugin of new lengths and auto scroll to bottom of chat container to show new message | |
if (typeof $("#message-logger .data").mCustomScrollbar !== "undefined") { | |
$("#message-logger .data").mCustomScrollbar("update"); | |
if (AUTOSCROLL) $("#message-logger .data").mCustomScrollbar('scrollTo', 'bottom'); | |
} | |
if (FADEDELAY && $('#chat').is(':hidden')) { | |
clearTimeout(CHATFADE); | |
CHATFADE = setTimeout(function() { | |
$('#message-logger .data').fadeOut('slow'); | |
}, FADEDELAY); | |
} | |
} | |
} | |
}); | |
// Monitor all group chat messages if part of a group | |
if (tagpro.group.socket != null) { | |
tagpro.group.socket.on('chat', function(data) { | |
$('#message-logger .data').fadeIn(); | |
if (typeof $("#message-logger .data").mCustomScrollbar !== "undefined") $("#message-logger .data").mCustomScrollbar("update"); | |
// Message from group so write entire message in yellow E7E700, if no from name then system group message of someone joining/leaving | |
if (data.from == null) { // Message has no from so system group message (join/leave events) | |
$('#message-logger .mCSB_container').append('<span style="color: #E7E700">' + htmlEscape(data.message).replace(/%20/g, ' ') + '</span><br />'); | |
} else { // Message contains a from property so display message as if user sent it | |
$('#message-logger .mCSB_container').append('<span style="color: #E7E700"><span style="cursor: pointer;" class="playeroptions" pname="' + encodeURIComponent(data.from) + '">' + data.from + '</span><span style="font-weight: normal">:</span> ' + Autolinker.link(htmlEscape(data.message).replace(/%20/g, ' '), { | |
stripPrefix: false | |
}) + '</span><br />'); | |
} | |
// New message appended to chat container so update/inform custom scrollbar plugin of new lengths and auto scroll to bottom of chat container to show new message | |
if (typeof $("#message-logger .data").mCustomScrollbar !== "undefined") { | |
$("#message-logger .data").mCustomScrollbar("update"); | |
if (AUTOSCROLL) $("#message-logger .data").mCustomScrollbar('scrollTo', 'bottom'); | |
} | |
if (FADEDELAY && $('#chat').is(':hidden')) { | |
clearTimeout(CHATFADE); | |
CHATFADE = setTimeout(function() { | |
$('#message-logger .data').fadeOut('slow'); | |
}, FADEDELAY); | |
} | |
}); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment