mirror of
https://github.com/smogon/pokemon-showdown-client.git
synced 2026-10-02 15:53:11 -05:00
Merge pull request #302 from sirDonovan/removemessages
Add support for removal of messages from chats
This commit is contained in:
13
js/battle.js
13
js/battle.js
@@ -5259,9 +5259,9 @@ var Battle = (function () {
|
||||
}
|
||||
var message = args.join('|');
|
||||
if (message.substr(0,2) === '//') {
|
||||
this.log('<div class="chat"><strong style="' + hashColor(toUserid(name)) + '">' + clickableName + ':</strong> <em>' + Tools.parseMessage(message.substr(1), name) + '</em></div>', preempt);
|
||||
this.log('<div class="chat chatmessage-' + toId(name) + '"><strong style="' + hashColor(toUserid(name)) + '">' + clickableName + ':</strong> <em>' + Tools.parseMessage(message.substr(1)) + '</em></div>', preempt);
|
||||
} else if (message.substr(0,4).toLowerCase() === '/me ') {
|
||||
this.log('<div class="chat"><strong style="' + hashColor(toUserid(name)) + '">•</strong> <em>' + clickableName + ' <i>' + Tools.parseMessage(message.substr(4), name) + '</i></em></div>', preempt);
|
||||
this.log('<div class="chat chatmessage-' + toId(name) + '"><strong style="' + hashColor(toUserid(name)) + '">•</strong> <em>' + clickableName + ' <i>' + Tools.parseMessage(message.substr(4)) + '</i></em></div>', preempt);
|
||||
} else if (message.substr(0,14).toLowerCase() === '/data-pokemon ') {
|
||||
if (window.Chart) this.log('<div class="chat"><ul class=\"utilichart\">'+Chart.pokemonRow(Tools.getTemplate(message.substr(14)),'',{})+'<li style=\"clear:both\"></li></ul></div>', preempt);
|
||||
} else if (message.substr(0,11).toLowerCase() === '/data-item ') {
|
||||
@@ -5271,7 +5271,7 @@ var Battle = (function () {
|
||||
} else if (message.substr(0,11).toLowerCase() === '/data-move ') {
|
||||
if (window.Chart) this.log('<div class="chat"><ul class=\"utilichart\">'+Chart.moveRow(Tools.getMove(message.substr(11)),'',{})+'<li style=\"clear:both\"></li></ul></div>', preempt);
|
||||
} else {
|
||||
this.log('<div class="chat"><strong style="' + hashColor(toUserid(name)) + '" class="username" data-name="'+Tools.escapeHTML(name)+'">' + clickableName + ':</strong> <em>' + Tools.parseMessage(message, name) + '</em></div>', preempt);
|
||||
this.log('<div class="chat chatmessage-' + toId(name) + '"><strong style="' + hashColor(toUserid(name)) + '" class="username" data-name="'+Tools.escapeHTML(name)+'">' + clickableName + ':</strong> <em>' + Tools.parseMessage(message) + '</em></div>', preempt);
|
||||
}
|
||||
break;
|
||||
case 'chatmsg':
|
||||
@@ -5457,6 +5457,13 @@ var Battle = (function () {
|
||||
this.log('<div class="debug"><div class="chat"><small style="color:#999">[DEBUG] ' + Tools.escapeHTML(name) + '.</small></div></div>', preempt);
|
||||
break;
|
||||
case 'unlink':
|
||||
var user = toId(args[2]) || toId(args[1]);
|
||||
var $messages = $('.chatmessage-' + user);
|
||||
$messages.find('a').contents().unwrap();
|
||||
if (args[2]) {
|
||||
$messages.hide();
|
||||
this.log('<div class="chatmessage-' + user + '"><button name="revealMessages" value="' + user + '"><small>Some messages were hidden, click here to restore them.</small></button></div>');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
this.logConsole('unknown command: ' + args[0]);
|
||||
|
||||
@@ -313,7 +313,7 @@ var Tools = {
|
||||
return Tools.escapeHTML(formatid);
|
||||
},
|
||||
|
||||
parseMessage: function(str, linkclass) {
|
||||
parseMessage: function(str) {
|
||||
str = Tools.escapeHTML(str);
|
||||
// Don't format console commands (>>).
|
||||
if (str.substr(0, 8) === '>>') return str;
|
||||
@@ -330,13 +330,9 @@ var Tools = {
|
||||
options.hidestrikethrough ? '$1' : '<s>$1</s>');
|
||||
// linking of URIs
|
||||
if (!options.hidelinks) {
|
||||
var classbit = '';
|
||||
if (linkclass) {
|
||||
classbit = ' class="message-link-' + toId(linkclass) + '"';
|
||||
}
|
||||
str = str.replace(/https?\:\/\/[a-z0-9-.]+(?:\:[0-9]+)?(?:\/(?:[^\s]*[^\s?.,])?)?|[a-z0-9.]+\@[a-z0-9.]+\.[a-z0-9]{2,3}|(?:[a-z0-9](?:[a-z0-9-\.]*[a-z0-9])?\.(?:com|org|net|edu|us|jp)(?:\:[0-9]+)?|qmark\.tk)(?:(?:\/(?:[^\s]*[^\s?.,])?)?)\b/ig, function(uri) {
|
||||
if (/[a-z0-9.]+\@[a-z0-9.]+\.[a-z0-9]{2,3}/ig.test(uri)) {
|
||||
return '<a href="mailto:'+uri+'" target="_blank"'+classbit+'>'+uri+'</a>';
|
||||
return '<a href="mailto:'+uri+'" target="_blank">'+uri+'</a>';
|
||||
}
|
||||
// Insert http:// before URIs without a URI scheme specified.
|
||||
var fulluri = uri.replace(/^([a-z]*[^a-z:])/g, 'http://$1');
|
||||
@@ -361,8 +357,7 @@ var Tools = {
|
||||
event + '\', \'' + Tools.escapeQuotes(fulluri) + '\');';
|
||||
}
|
||||
return '<a href="' + fulluri +
|
||||
'" target="_blank" onclick="' + onclick + '"' + classbit +
|
||||
'>' + uri + '</a>';
|
||||
'" target="_blank" onclick="' + onclick + '">' + uri + '</a>';
|
||||
});
|
||||
// google [blah]
|
||||
// google[blah]
|
||||
@@ -370,7 +365,7 @@ var Tools = {
|
||||
str = str.replace(/\bgoogle ?\[([^\]<]+)\]/ig, function(p0, p1) {
|
||||
p1 = Tools.escapeHTML(encodeURIComponent(Tools.unescapeHTML(p1)));
|
||||
return '<a href="http://www.google.com/search?ie=UTF-8&q=' + p1 +
|
||||
'" target="_blank"' + classbit + '>' + p0 + '</a>';
|
||||
'" target="_blank">' + p0 + '</a>';
|
||||
});
|
||||
// gl [blah]
|
||||
// gl[blah]
|
||||
@@ -378,21 +373,21 @@ var Tools = {
|
||||
str = str.replace(/\bgl ?\[([^\]<]+)\]/ig, function(p0, p1) {
|
||||
p1 = Tools.escapeHTML(encodeURIComponent(Tools.unescapeHTML(p1)));
|
||||
return '<a href="http://www.google.com/search?ie=UTF-8&btnI&q=' + p1 +
|
||||
'" target="_blank"' + classbit + '>' + p0 + '</a>';
|
||||
'" target="_blank">' + p0 + '</a>';
|
||||
});
|
||||
// wiki [blah]
|
||||
// Search Wikipedia for 'blah' (and visit the article for 'blah' if it exists)
|
||||
str = str.replace(/\bwiki ?\[([^\]<]+)\]/ig, function(p0, p1) {
|
||||
p1 = Tools.escapeHTML(encodeURIComponent(Tools.unescapeHTML(p1)));
|
||||
return '<a href="http://en.wikipedia.org/w/index.php?title=Special:Search&search=' +
|
||||
p1 + '" target="_blank"' + classbit + '>' + p0 + '</a>';
|
||||
p1 + '" target="_blank">' + p0 + '</a>';
|
||||
});
|
||||
// [[blah]]
|
||||
// Short form of gl[blah]
|
||||
str = str.replace(/\[\[([^< ](?:[^<`]*?[^< ])?)\]\]/ig, function(p0, p1) {
|
||||
var q = Tools.escapeHTML(encodeURIComponent(Tools.unescapeHTML(p1)));
|
||||
return '<a href="http://www.google.com/search?ie=UTF-8&btnI&q=' + q +
|
||||
'" target="_blank"' + classbit + '>' + p1 +'</a>';
|
||||
'" target="_blank">' + p1 +'</a>';
|
||||
});
|
||||
}
|
||||
// __italics__
|
||||
|
||||
@@ -133,6 +133,11 @@
|
||||
this.battle.add('', Tools.prefs('noanim'));
|
||||
this.updateControls();
|
||||
},
|
||||
revealMessages: function(user) {
|
||||
var $messages = $('.chatmessage-' + user);
|
||||
$messages.show();
|
||||
$messages.find('button').parent().remove();
|
||||
},
|
||||
|
||||
/*********************************************************
|
||||
* Battle stuff
|
||||
|
||||
@@ -993,9 +993,13 @@
|
||||
case 'unlink':
|
||||
// note: this message has global effects, but it's handled here
|
||||
// so that it can be included in the scrollback buffer.
|
||||
$('.message-link-' + toId(row[1])).each(function() {
|
||||
$(this).replaceWith($(this).html());
|
||||
});
|
||||
var user = toId(row[2]) || toId(row[1]);
|
||||
var $messages = $('.chatmessage-' + user);
|
||||
$messages.find('a').contents().unwrap();
|
||||
if (row[2]) {
|
||||
$messages.hide();
|
||||
this.$chat.append('<div class="chatmessage-' + user + '"><button name="revealMessages" value="' + user + '"><small>Some messages were hidden, click here to restore them.</small></button></div>');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'tournament':
|
||||
@@ -1015,6 +1019,11 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
revealMessages: function(user) {
|
||||
var $messages = $('.chatmessage-' + user);
|
||||
$messages.show();
|
||||
$messages.find('button').parent().remove();
|
||||
},
|
||||
tournamentButton: function(val, button) {
|
||||
if (this.tournamentBox) this.tournamentBox[$(button).data('type')](val, button);
|
||||
},
|
||||
@@ -1152,23 +1161,23 @@
|
||||
}
|
||||
}
|
||||
var highlight = isHighlighted ? ' highlighted' : '';
|
||||
var chatDiv = '<div class="chat' + highlight + '">';
|
||||
var chatDiv = '<div class="chat chatmessage-' + toId(name) + highlight + '">';
|
||||
var timestamp = ChatRoom.getTimestamp('lobby', deltatime);
|
||||
if (name.charAt(0) !== ' ') clickableName = '<small>' + Tools.escapeHTML(name.charAt(0)) + '</small>'+clickableName;
|
||||
var self = this;
|
||||
var outputChat = function() {
|
||||
self.$chat.append(chatDiv + timestamp + '<strong style="' + color + '">' + clickableName + ':</strong> <em' + (name.substr(1) === app.user.get('name') ? ' class="mine"' : '') + '>' + Tools.parseMessage(message, name) + '</em></div>');
|
||||
self.$chat.append(chatDiv + timestamp + '<strong style="' + color + '">' + clickableName + ':</strong> <em' + (name.substr(1) === app.user.get('name') ? ' class="mine"' : '') + '>' + Tools.parseMessage(message) + '</em></div>');
|
||||
};
|
||||
var showme = !((Tools.prefs('chatformatting') || {}).hideme);
|
||||
if (pm) {
|
||||
var pmuserid = toUserid(pm);
|
||||
var oName = pm;
|
||||
if (pmuserid === app.user.get('userid')) oName = name;
|
||||
this.$chat.append('<div class="chat">' + timestamp + '<strong style="' + color + '">' + clickableName + ':</strong> <span class="message-pm"><i class="pmnote" data-name="' + Tools.escapeHTML(oName) + '">(Private to ' + Tools.escapeHTML(pm) + ')</i> ' + Tools.parseMessage(message, name) + '</span></div>');
|
||||
this.$chat.append('<div class="chat chatmessage-' + toId(name) + '">' + timestamp + '<strong style="' + color + '">' + clickableName + ':</strong> <span class="message-pm"><i class="pmnote" data-name="' + Tools.escapeHTML(oName) + '">(Private to ' + Tools.escapeHTML(pm) + ')</i> ' + Tools.parseMessage(message) + '</span></div>');
|
||||
} else if (message.substr(0,4) === '/me ') {
|
||||
message = message.substr(4);
|
||||
if (showme) {
|
||||
this.$chat.append(chatDiv + timestamp + '<strong style="' + color + '">•</strong> <em' + (name.substr(1) === app.user.get('name') ? ' class="mine"' : '') + '>' + clickableName + ' <i>' + Tools.parseMessage(message, name) + '</i></em></div>');
|
||||
this.$chat.append(chatDiv + timestamp + '<strong style="' + color + '">•</strong> <em' + (name.substr(1) === app.user.get('name') ? ' class="mine"' : '') + '>' + clickableName + ' <i>' + Tools.parseMessage(message) + '</i></em></div>');
|
||||
} else {
|
||||
outputChat();
|
||||
}
|
||||
@@ -1176,13 +1185,13 @@
|
||||
} else if (message.substr(0,5) === '/mee ') {
|
||||
message = message.substr(5);
|
||||
if (showme) {
|
||||
this.$chat.append(chatDiv + timestamp + '<strong style="' + color + '">•</strong> <em' + (name.substr(1) === app.user.get('name') ? ' class="mine"' : '') + '>' + clickableName + '<i>' + Tools.parseMessage(message, name) + '</i></em></div>');
|
||||
this.$chat.append(chatDiv + timestamp + '<strong style="' + color + '">•</strong> <em' + (name.substr(1) === app.user.get('name') ? ' class="mine"' : '') + '>' + clickableName + '<i>' + Tools.parseMessage(message) + '</i></em></div>');
|
||||
} else {
|
||||
outputChat();
|
||||
}
|
||||
Storage.logChat(this.id, '* '+name+message);
|
||||
} else if (message.substr(0,10) === '/announce ') {
|
||||
this.$chat.append(chatDiv + timestamp + '<strong style="' + color + '">' + clickableName + ':</strong> <span class="message-announce">' + Tools.parseMessage(message.substr(10), name) + '</span></div>');
|
||||
this.$chat.append(chatDiv + timestamp + '<strong style="' + color + '">' + clickableName + ':</strong> <span class="message-announce">' + Tools.parseMessage(message.substr(10)) + '</span></div>');
|
||||
Storage.logChat(this.id, ''+name+': /announce '+message);
|
||||
} else if (message.substr(0,14) === '/data-pokemon ') {
|
||||
this.$chat.append('<div class="message"><ul class="utilichart">'+Chart.pokemonRow(Tools.getTemplate(message.substr(14)),'',{})+'<li style=\"clear:both\"></li></ul></div>');
|
||||
|
||||
@@ -140,15 +140,15 @@
|
||||
if (name.substr(0, 1) !== ' ') clickableName = '<small>' + Tools.escapeHTML(name.substr(0, 1)) + '</small>'+clickableName;
|
||||
|
||||
if (message.substr(0,4) === '/me ') {
|
||||
$chat.append('<div class="chat">' + timestamp + '<strong style="' + color + '">•</strong> <em' + (name.substr(1) === app.user.get('name') ? ' class="mine"' : '') + '>' + clickableName + ' <i>' + Tools.parseMessage(message.substr(4), name) + '</i></em></div>');
|
||||
$chat.append('<div class="chat chatmessage-' + toId(name) + '">' + timestamp + '<strong style="' + color + '">•</strong> <em' + (name.substr(1) === app.user.get('name') ? ' class="mine"' : '') + '>' + clickableName + ' <i>' + Tools.parseMessage(message.substr(4)) + '</i></em></div>');
|
||||
} else if (message.substr(0,5) === '/mee ') {
|
||||
$chat.append('<div class="chat">' + timestamp + '<strong style="' + color + '">•</strong> <em' + (name.substr(1) === app.user.get('name') ? ' class="mine"' : '') + '>' + clickableName + '<i>' + Tools.parseMessage(message.substr(5), name) + '</i></em></div>');
|
||||
$chat.append('<div class="chat chatmessage-' + toId(name) + '">' + timestamp + '<strong style="' + color + '">•</strong> <em' + (name.substr(1) === app.user.get('name') ? ' class="mine"' : '') + '>' + clickableName + '<i>' + Tools.parseMessage(message.substr(5)) + '</i></em></div>');
|
||||
} else if (message.substr(0,8) === '/invite ') {
|
||||
var roomid = toRoomid(message.substr(8));
|
||||
$chat.append('<div class="chat">' + timestamp + '<em>' + clickableName + ' invited you to join the room "'+roomid+'"</em></div>');
|
||||
$chat.append('<div class="notice"><button name="joinRoom" value="'+roomid+'">Join '+roomid+'</button></div>');
|
||||
} else if (message.substr(0,10) === '/announce ') {
|
||||
$chat.append('<div class="chat">' + timestamp + '<strong style="' + color + '">' + clickableName + ':</strong> <span class="message-announce">' + Tools.parseMessage(message.substr(10), name) + '</span></div>');
|
||||
$chat.append('<div class="chat chatmessage-' + toId(name) + '">' + timestamp + '<strong style="' + color + '">' + clickableName + ':</strong> <span class="message-announce">' + Tools.parseMessage(message.substr(10)) + '</span></div>');
|
||||
} else if (message.substr(0,14) === '/data-pokemon ') {
|
||||
$chat.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) === '/data-item ') {
|
||||
@@ -164,7 +164,7 @@
|
||||
} else {
|
||||
// Normal chat message.
|
||||
if (message.substr(0,2) === '//') message = message.substr(1);
|
||||
$chat.append('<div class="chat">' + timestamp + '<strong style="' + color + '">' + clickableName + ':</strong> <em' + (target === oName ? ' class="mine"' : '') + '>' + Tools.parseMessage(message, name) + '</em></div>');
|
||||
$chat.append('<div class="chat chatmessage-' + toId(name) + '">' + timestamp + '<strong style="' + color + '">' + clickableName + ':</strong> <em' + (target === oName ? ' class="mine"' : '') + '>' + Tools.parseMessage(message) + '</em></div>');
|
||||
}
|
||||
|
||||
if (autoscroll) {
|
||||
|
||||
Reference in New Issue
Block a user