2013-08-29 21:33:26 +02:00
|
|
|
var alert_words = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
|
|
|
exports.words = page_params.alert_words;
|
|
|
|
|
|
|
|
// escape_user_regex taken from jquery-ui/autocomplete.js,
|
|
|
|
// licensed under MIT license.
|
|
|
|
function escape_user_regex(value) {
|
|
|
|
return value.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&");
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.process_message = function (message) {
|
2013-10-11 17:30:57 +02:00
|
|
|
if (!exports.notifies(message)) {
|
2013-08-29 21:33:26 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_.each(exports.words, function (word) {
|
|
|
|
var clean = escape_user_regex(word);
|
2013-10-09 20:09:48 +02:00
|
|
|
var before_punctuation = '\\s|^|>|[\\(\\"]';
|
|
|
|
var after_punctuation = '\\s|$|<|[\\)\\"\\?:.,]';
|
|
|
|
|
|
|
|
var regex = new RegExp('(' + before_punctuation + ')' +
|
|
|
|
'(' + clean + ')' +
|
|
|
|
'(' + after_punctuation + ')' , 'i');
|
|
|
|
message.content = message.content.replace(regex, function (match, before, word, after) {
|
|
|
|
return before + "<span class='alert-word'>" + word + "</span>" + after;
|
|
|
|
});
|
2013-08-29 21:33:26 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.notifies = function (message) {
|
|
|
|
return ((message.sender_email !== page_params.email) &&
|
|
|
|
(message.flags.indexOf('has_alert_word') > -1));
|
|
|
|
};
|
|
|
|
|
|
|
|
return exports;
|
|
|
|
|
|
|
|
}());
|
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
module.exports = alert_words;
|
|
|
|
}
|