Take into account wordboundaries for custom highlighting
This commit is contained in:
parent
14eb0c0d7f
commit
43cc2792c9
@ -1,6 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const $ = require("jquery");
|
const $ = require("jquery");
|
||||||
|
const escapeRegExp = require("lodash/escapeRegExp");
|
||||||
const settings = $("#settings");
|
const settings = $("#settings");
|
||||||
const userStyles = $("#user-specified-css");
|
const userStyles = $("#user-specified-css");
|
||||||
const storage = require("./localStorage");
|
const storage = require("./localStorage");
|
||||||
@ -98,6 +99,15 @@ settings.on("change", "input, select, textarea", function() {
|
|||||||
// otherwise, users get notifications for everything
|
// otherwise, users get notifications for everything
|
||||||
return h !== "";
|
return h !== "";
|
||||||
});
|
});
|
||||||
|
// Construct regex with wordboundary for every highlight item
|
||||||
|
const highlightsTokens = options.highlights.map(function(h) {
|
||||||
|
return escapeRegExp(h);
|
||||||
|
});
|
||||||
|
if (highlightsTokens && highlightsTokens.length) {
|
||||||
|
module.exports.highlightsRE = new RegExp("\\b(?:" + highlightsTokens.join("|") + ")\\b", "i");
|
||||||
|
} else {
|
||||||
|
module.exports.highlightsRE = null;
|
||||||
|
}
|
||||||
} else if (name === "showSeconds") {
|
} else if (name === "showSeconds") {
|
||||||
chat.find(".msg > .time").each(function() {
|
chat.find(".msg > .time").each(function() {
|
||||||
$(this).text(tz($(this).parent().data("time")));
|
$(this).text(tz($(this).parent().data("time")));
|
||||||
|
@ -65,9 +65,11 @@ function buildChatMessage(data) {
|
|||||||
const chan = chat.find(target);
|
const chan = chat.find(target);
|
||||||
let template = "msg";
|
let template = "msg";
|
||||||
|
|
||||||
if (!data.msg.highlight && !data.msg.self && (type === "message" || type === "notice") && options.highlights.some(function(h) {
|
// See if any of the custom highlight regexes match
|
||||||
return data.msg.text.toLocaleLowerCase().indexOf(h.toLocaleLowerCase()) > -1;
|
if (!data.msg.highlight && !data.msg.self
|
||||||
})) {
|
&& options.highlightsRE
|
||||||
|
&& (type === "message" || type === "notice")
|
||||||
|
&& options.highlightsRE.exec(data.msg.text)) {
|
||||||
data.msg.highlight = true;
|
data.msg.highlight = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user