Add custom highlights

This commit is contained in:
Alistair McKinlay 2016-06-21 20:27:49 +01:00
parent 0377c2f780
commit feda6615f9
2 changed files with 29 additions and 2 deletions

View file

@ -273,6 +273,14 @@
Enable notification for all messages
</label>
</div>
<div class="col-sm-12">
<label class="opt">
<label for="highlights" class="sr-only">Custom highlights (comma-separated keywords)</label>
<input type="text" id="highlights" name="highlights" class="input" placeholder="Custom highlights (comma-separated keywords)">
</label>
</div>
<% if (!public) { %>
<div id="change-password">
<form action="" method="post">

View file

@ -224,6 +224,12 @@ $(function() {
var chan = chat.find(target);
var msg;
if (highlights.some(function(h) {
return data.msg.text.indexOf(h) > -1;
})) {
data.msg.highlight = true;
}
if ([
"invite",
"join",
@ -466,12 +472,15 @@ $(function() {
}
settings.find("#user-specified-css-input").val(options[i]);
continue;
}
if (options[i]) {
} else if (i === "highlights") {
settings.find("input[name=" + i + "]").val(options[i]);
} else if (options[i]) {
settings.find("input[name=" + i + "]").prop("checked", true);
}
}
var highlights = [];
settings.on("change", "input, textarea", function() {
var self = $(this);
var name = self.attr("name");
@ -501,6 +510,16 @@ $(function() {
if (name === "userStyles") {
$(document.head).find("#user-specified-css").html(options[name]);
}
if (name === "highlights") {
var highlightString = options[name];
highlights = highlightString.split(",").map(function(h) {
return h.trim();
}).filter(function(h) {
// Ensure we don't have empty string in the list of highlights
// otherwise, users get notifications for everything
return h !== "";
});
}
}).find("input")
.trigger("change");