mirror of
https://github.com/smogon/pokemon-showdown-client.git
synced 2026-06-02 22:09:20 -05:00
Adding highlighting words
Added highlighting words: Users may now use the new highlight commands: -Use /highlight add, word to add a highlighting word. You might add several words separated with commands. -In a likewise fashion, /highlight delete, word deletes words. -Using /highlight delete with no words will delete all. -/highlight show or list will show all current highlight words. -By default no word is added to highlights. -Words are escaped
This commit is contained in:
parent
1208dee10f
commit
7dd40a7d3b
65
js/sim.js
65
js/sim.js
|
|
@ -1106,6 +1106,53 @@ function Lobby(id, elem) {
|
|||
Tools.prefs.set('timestamps', target, true);
|
||||
}
|
||||
return false;
|
||||
|
||||
case 'highlight':
|
||||
var highlights = Tools.prefs.get('highlights') || [];
|
||||
if (target.indexOf(',') > -1) {
|
||||
var targets = target.split(',');
|
||||
// trim the targets to be safe
|
||||
for (var i=0, len=targets.length; i<len; i++) {
|
||||
targets[i] = targets[i].trim();
|
||||
}
|
||||
switch (targets[0]) {
|
||||
case 'add':
|
||||
for (var i=1, len=targets.length; i<len; i++) {
|
||||
highlights.push(targets[i].trim());
|
||||
}
|
||||
// We update the regex
|
||||
this.regex = new RegExp('\\b('+highlights.join('|')+')\\b', 'gi');
|
||||
break;
|
||||
case 'delete':
|
||||
var newHls = [];
|
||||
for (var i=0, len=highlights.length; i<len; i++) {
|
||||
if (targets.indexOf(highlights[i]) === -1) {
|
||||
newHls.push(highlights[i]);
|
||||
}
|
||||
}
|
||||
highlights = newHls;
|
||||
// We update the regex
|
||||
this.regex = new RegExp('\\b('+highlights.join('|')+')\\b', 'gi');
|
||||
break;
|
||||
}
|
||||
Tools.prefs.set('highlights', highlights, true);
|
||||
} else {
|
||||
if (target === 'delete') {
|
||||
Tools.prefs.set('highlights', false, true);
|
||||
} else if (target === 'show' || target === 'list') {
|
||||
// Shows a list of the current highlighting words
|
||||
if (highlights.length > 0) {
|
||||
var hls = highlights.join(', ');
|
||||
} else {
|
||||
var hls = 'Currently none.';
|
||||
}
|
||||
rooms.lobby.add("Current highlighting words: " + hls);
|
||||
} else {
|
||||
// Wrong command
|
||||
rooms.lobby.add("Error: Valid options are /highlight add, [word]; /highlight delete, [word]; (remove word for highlight cleaning), and /highlight show.");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
case 'rank':
|
||||
case 'ranking':
|
||||
|
|
@ -1254,6 +1301,12 @@ function Lobby(id, elem) {
|
|||
function(x) { return (x < 10) ? '0' + x : x; }
|
||||
).join(':') + '] ';
|
||||
};
|
||||
this.getHighlight = function (message) {
|
||||
var highlights = Tools.prefs.get('highlights') || [];
|
||||
if (!this.regex) this.regex = new RegExp('\\b('+highlights.join('|')+')\\b', 'gi');
|
||||
if (highlights.length > 0) return this.regex.test(message);
|
||||
return false;
|
||||
};
|
||||
this.add = function (log) {
|
||||
if (typeof log === 'string') log = log.split('\n');
|
||||
var autoscroll = false;
|
||||
|
|
@ -1381,6 +1434,8 @@ function Lobby(id, elem) {
|
|||
};
|
||||
var clickableName = '<span style="cursor:pointer" onclick="return rooms.lobby.formChallenge(\'' + userid + '\');">' + sanitize(log[i].name.substr(1)) + '</span>';
|
||||
var message = log[i].message;
|
||||
var highlight = (selfR.getHighlight(message))? ' style="background-color:#F84;"' : '';
|
||||
var chatDiv = '<div class="chat"' + highlight + '>';
|
||||
if (log[i].name.substr(0, 1) !== ' ') clickableName = '<small>' + sanitize(log[i].name.substr(0, 1)) + '</small>'+clickableName;
|
||||
if (log[i].pm) {
|
||||
var pmuserid = (userid === me.userid ? toUserid(log[i].pm) : userid);
|
||||
|
|
@ -1400,13 +1455,13 @@ function Lobby(id, elem) {
|
|||
//} else if (log[i].act) {
|
||||
// selfR.chatElem.append('<div class="chat"><strong style="' + color + '">•</strong> <em' + (log[i].name.substr(1) === me.name ? ' class="mine"' : '') + '>' + clickableName + ' <i>' + message + '</i></em></div>');
|
||||
} else if (message.substr(0,2) === '//') {
|
||||
selfR.chatElem.append('<div class="chat">' + selfR.getTimestamp() + '<strong style="' + color + '">' + clickableName + ':</strong> <em' + (log[i].name.substr(1) === me.name ? ' class="mine"' : '') + '>' + messageSanitize(message.substr(1)) + '</em></div>');
|
||||
selfR.chatElem.append(chatDiv + selfR.getTimestamp() + '<strong style="' + color + '">' + clickableName + ':</strong> <em' + (log[i].name.substr(1) === me.name ? ' class="mine"' : '') + '>' + messageSanitize(message.substr(1)) + '</em></div>');
|
||||
} else if (message.substr(0,4).toLowerCase() === '/me ') {
|
||||
selfR.chatElem.append('<div class="chat">' + selfR.getTimestamp() + '<strong style="' + color + '">•</strong> <em' + (log[i].name.substr(1) === me.name ? ' class="mine"' : '') + '>' + clickableName + ' <i>' + messageSanitize(message.substr(4)) + '</i></em></div>');
|
||||
selfR.chatElem.append(chatDiv + selfR.getTimestamp() + '<strong style="' + color + '">•</strong> <em' + (log[i].name.substr(1) === me.name ? ' class="mine"' : '') + '>' + clickableName + ' <i>' + messageSanitize(message.substr(4)) + '</i></em></div>');
|
||||
} else if (message.substr(0,5).toLowerCase() === '/mee ') {
|
||||
selfR.chatElem.append('<div class="chat">' + selfR.getTimestamp() + '<strong style="' + color + '">•</strong> <em' + (log[i].name.substr(1) === me.name ? ' class="mine"' : '') + '>' + clickableName + '<i>' + messageSanitize(message.substr(5)) + '</i></em></div>');
|
||||
selfR.chatElem.append(chatDiv + selfR.getTimestamp() + '<strong style="' + color + '">•</strong> <em' + (log[i].name.substr(1) === me.name ? ' class="mine"' : '') + '>' + clickableName + '<i>' + messageSanitize(message.substr(5)) + '</i></em></div>');
|
||||
} else if (message.substr(0,10).toLowerCase() === '/announce ') {
|
||||
selfR.chatElem.append('<div class="chat">' + selfR.getTimestamp() + '<strong style="' + color + '">' + clickableName + ':</strong> <em style="padding:1px 4px 2px;color:white;background:#6688AA">' + messageSanitize(message.substr(10)) + '</em></div>');
|
||||
selfR.chatElem.append(chatDiv + selfR.getTimestamp() + '<strong style="' + color + '">' + clickableName + ':</strong> <em style="padding:1px 4px 2px;color:white;background:#6688AA">' + messageSanitize(message.substr(10)) + '</em></div>');
|
||||
} else if (message.substr(0,14).toLowerCase() === '/data-pokemon ') {
|
||||
selfR.chatElem.append('<div class="message"><ul class=\"utilichart\">'+Chart.pokemonRow(Tools.getTemplate(message.substr(14)),'',{})+'<li style=\"clear:both\"></li></ul></div>');
|
||||
} else if (message.substr(0,11).toLowerCase() === '/data-item ') {
|
||||
|
|
@ -1417,7 +1472,7 @@ function Lobby(id, elem) {
|
|||
selfR.chatElem.append('<div class="message"><ul class=\"utilichart\">'+Chart.moveRow(Tools.getMove(message.substr(11)),'',{})+'<li style=\"clear:both\"></li></ul></div>');
|
||||
} else {
|
||||
// Normal chat message.
|
||||
selfR.chatElem.append('<div class="chat">' + selfR.getTimestamp() + '<strong style="' + color + '">' + clickableName + ':</strong> <em' + (log[i].name.substr(1) === me.name ? ' class="mine"' : '') + '>' + messageSanitize(message) + '</em></div>');
|
||||
selfR.chatElem.append(chatDiv + selfR.getTimestamp() + '<strong style="' + color + '">' + clickableName + ':</strong> <em' + (log[i].name.substr(1) === me.name ? ' class="mine"' : '') + '>' + messageSanitize(message) + '</em></div>');
|
||||
}
|
||||
} else if (log[i].name && log[i].action === 'battle') {
|
||||
var id = log[i].room;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user