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-09-03 15:16:00 +02:00
|
|
|
if (!feature_flags.alert_words || !exports.notifies(message)) {
|
2013-08-29 21:33:26 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_.each(exports.words, function (word) {
|
|
|
|
var clean = escape_user_regex(word);
|
|
|
|
var regex = new RegExp('(\\b' + clean + '\\b)', 'i');
|
|
|
|
var replaced = "<span class='alert-word'>$1</span>";
|
|
|
|
message.content = message.content.replace(regex, replaced);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|