' + sanitize(message.name.substr(1)) + ': (Private to ' + sanitize(message.pm) + ') ' + messageSanitize(message.message) + '');
} else if (message.rawMessage) {
selfR.add('|chatmsg-raw|' + message.rawMessage);
} else if (message.evalRawMessage) {
@@ -1109,24 +1086,20 @@ function Lobby(id, elem) {
case 'showjoins':
rooms.lobby.add('Join/leave messages: ON');
- prefs.showjoins = true;
- savePrefs();
+ Tools.prefs.set('showjoins', true, true);
return false;
case 'hidejoins':
rooms.lobby.add('Join/leave messages: HIDDEN');
- prefs.showjoins = false;
- savePrefs();
+ Tools.prefs.set('showjoins', false, true);
return false;
case 'showbattles':
rooms.lobby.add('Battle messages: ON');
- prefs.showbattles = true;
- savePrefs();
+ Tools.prefs.set('showbattles', true, true);
return false;
case 'hidebattles':
rooms.lobby.add('Battle messages: HIDDEN');
- prefs.showbattles = false;
- savePrefs();
+ Tools.prefs.set('showbattles', false, true);
return false;
case 'timestamps':
@@ -1135,8 +1108,7 @@ function Lobby(id, elem) {
if (['off', 'minutes', 'seconds'].indexOf(target) === -1) {
rooms.lobby.add("Error: Valid options are /timestamps off, /timestamps minutes, and /timestamps seconds");
} else {
- prefs.timestamps = target;
- savePrefs();
+ Tools.prefs.set('timestamps', target, true);
}
return false;
@@ -1275,6 +1247,18 @@ function Lobby(id, elem) {
selfR.userActivity.splice(0, 20);
}
};
+ this.getTimestamp = function () {
+ var pref = Tools.prefs.get('timestamps');
+ if ((pref === 'off') || (pref === undefined)) return '';
+ var date = new Date();
+ var components = [ date.getHours(), date.getMinutes() ];
+ if (pref === 'seconds') {
+ components.push(date.getSeconds());
+ }
+ return '[' + components.map(
+ function(x) { return (x < 10) ? '0' + x : x; }
+ ).join(':') + '] ';
+ };
this.add = function (log) {
if (typeof log === 'string') log = log.split('\n');
var autoscroll = false;
@@ -1406,7 +1390,7 @@ function Lobby(id, elem) {
if (log[i].pm) {
var pmuserid = (userid === me.userid ? toUserid(log[i].pm) : userid);
if (!me.pm[pmuserid]) me.pm[pmuserid] = '';
- var pmcode = '
' + getTimestamp() + '' + clickableName + ': ' + messageSanitize(message) + '
';
+ var pmcode = '
' + selfR.getTimestamp() + '' + clickableName + ': ' + messageSanitize(message) + '
';
for (var j = 0; j < me.popups.length; j++) {
if (pmuserid === me.popups[j]) break;
}
@@ -1417,17 +1401,17 @@ function Lobby(id, elem) {
} else {
selfR.updatePopup();
}
- selfR.chatElem.append('
' + getTimestamp() + '' + clickableName + ': (Private to ' + sanitize(log[i].pm) + ') ' + messageSanitize(message) + '
');
+ selfR.chatElem.append('
' + selfR.getTimestamp() + '' + clickableName + ': (Private to ' + sanitize(log[i].pm) + ') ' + messageSanitize(message) + '
');
//} else if (log[i].act) {
// selfR.chatElem.append('
• ' + clickableName + ' ' + message + '
');
} else if (message.substr(0,2) === '//') {
- selfR.chatElem.append('
' + getTimestamp() + '' + clickableName + ': ' + messageSanitize(message.substr(1)) + '
');
+ selfR.chatElem.append('
' + selfR.getTimestamp() + '' + clickableName + ': ' + messageSanitize(message.substr(1)) + '
');
} else if (message.substr(0,4).toLowerCase() === '/me ') {
- selfR.chatElem.append('
' + getTimestamp() + '• ' + clickableName + ' ' + messageSanitize(message.substr(4)) + '
');
+ selfR.chatElem.append('
' + selfR.getTimestamp() + '• ' + clickableName + ' ' + messageSanitize(message.substr(4)) + '
');
} else if (message.substr(0,5).toLowerCase() === '/mee ') {
- selfR.chatElem.append('
' + getTimestamp() + '• ' + clickableName + '' + messageSanitize(message.substr(5)) + '
');
+ selfR.chatElem.append('
' + selfR.getTimestamp() + '• ' + clickableName + '' + messageSanitize(message.substr(5)) + '
');
} else if (message.substr(0,10).toLowerCase() === '/announce ') {
- selfR.chatElem.append('
' + getTimestamp() + '' + clickableName + ': ' + messageSanitize(message.substr(10)) + '
');
+ selfR.chatElem.append('
' + selfR.getTimestamp() + '' + clickableName + ': ' + messageSanitize(message.substr(10)) + '
');
} else if (message.substr(0,14).toLowerCase() === '/data-pokemon ') {
selfR.chatElem.append('
'+Chart.pokemonRow(Tools.getTemplate(message.substr(14)),'',{})+'
');
} else if (message.substr(0,11).toLowerCase() === '/data-item ') {
@@ -1438,7 +1422,7 @@ function Lobby(id, elem) {
selfR.chatElem.append('
'+Chart.moveRow(Tools.getMove(message.substr(11)),'',{})+'
');
} else {
// Normal chat message.
- selfR.chatElem.append('
' + getTimestamp() + '' + clickableName + ': ' + messageSanitize(message) + '
');
+ selfR.chatElem.append('
' + selfR.getTimestamp() + '' + clickableName + ': ' + messageSanitize(message) + '
');
}
} else if (log[i].name && log[i].action === 'battle') {
var id = log[i].room;
@@ -1452,7 +1436,7 @@ function Lobby(id, elem) {
});
if (selfR.rooms.length > 8) selfR.rooms.shift();
- if (log[i].silent && !prefs.showbattles) continue;
+ if (log[i].silent && !Tools.prefs.get('showbattles')) continue;
selfR.joinLeaveElem = null;
selfR.joinLeave = {
@@ -1486,7 +1470,7 @@ function Lobby(id, elem) {
me.users[toUserid(log[i].name)] = log[i].name;
continue;
}
- if (log[i].silent && !prefs.showjoins) continue;
+ if (log[i].silent && !Tools.prefs.get('showjoins')) continue;
if (!selfR.joinLeaveElem) {
selfR.chatElem.append('
Loading...
');
selfR.joinLeaveElem = selfR.chatElem.children().last();
@@ -1569,10 +1553,10 @@ function Lobby(id, elem) {
}
// Disable timestamps for the past log because the server doesn't
// tell us what time the messages were sent at.
- var timestamps = prefs.timestamps;
- prefs.timestamps = 'off';
+ var timestamps = Tools.prefs.get('timestamps');
+ Tools.prefs.set('timestamps', 'off');
selfR.add(data.log); // Add past log.
- prefs.timestamps = timestamps;
+ Tools.prefs.set('timestamps', timestamps);
}
selfR.update(data);
selfR.chatFrameElem.scrollTop(selfR.chatElem.height());