mirror of
https://github.com/nuttylmao/nutty.gg.git
synced 2026-09-19 04:00:59 -04:00
Fixed issue with emotes that contain colons
This commit is contained in:
@@ -352,7 +352,21 @@ async function TwitchChatMessage(data) {
|
|||||||
// Render emotes
|
// Render emotes
|
||||||
for (i in data.emotes) {
|
for (i in data.emotes) {
|
||||||
const emoteElement = `<img src="${data.emotes[i].imageUrl}" class="emote"/>`;
|
const emoteElement = `<img src="${data.emotes[i].imageUrl}" class="emote"/>`;
|
||||||
messageDiv.innerHTML = messageDiv.innerHTML.replace(new RegExp(`\\b${data.emotes[i].name}\\b`), emoteElement);
|
const emoteName = EscapeRegExp(data.emotes[i].name);
|
||||||
|
|
||||||
|
let regexPattern = emoteName;
|
||||||
|
|
||||||
|
// Check if the emote name consists only of word characters (alphanumeric and underscore)
|
||||||
|
if (/^\w+$/.test(emoteName)) {
|
||||||
|
regexPattern = `\\b${emoteName}\\b`;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// For non-word emotes, ensure they are surrounded by non-word characters or boundaries
|
||||||
|
regexPattern = `(?:^|[^\\w])${emoteName}(?:$|[^\\w])`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const regex = new RegExp(regexPattern, 'g');
|
||||||
|
messageDiv.innerHTML = messageDiv.innerHTML.replace(regex, emoteElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render cheermotes
|
// Render cheermotes
|
||||||
@@ -417,7 +431,21 @@ async function TwitchAnnouncement(data) {
|
|||||||
for (i in data.parts) {
|
for (i in data.parts) {
|
||||||
if (data.parts[i].type == `emote`) {
|
if (data.parts[i].type == `emote`) {
|
||||||
const emoteElement = `<img src="${data.parts[i].imageUrl}" class="emote"/>`;
|
const emoteElement = `<img src="${data.parts[i].imageUrl}" class="emote"/>`;
|
||||||
message = message.replace(new RegExp(`\\b${data.parts[i].text}\\b`), emoteElement);
|
const emoteName = EscapeRegExp(data.parts[i].text);
|
||||||
|
|
||||||
|
let regexPattern = emoteName;
|
||||||
|
|
||||||
|
// Check if the emote name consists only of word characters (alphanumeric and underscore)
|
||||||
|
if (/^\w+$/.test(emoteName)) {
|
||||||
|
regexPattern = `\\b${emoteName}\\b`;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// For non-word emotes, ensure they are surrounded by non-word characters or boundaries
|
||||||
|
regexPattern = `(?:^|[^\\w])${emoteName}(?:$|[^\\w])`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const regex = new RegExp(regexPattern, 'g');
|
||||||
|
message = message.replace(regex, emoteElement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1101,8 +1129,7 @@ function AddMessageItem(element, elementID, platform, userId) {
|
|||||||
messageList.removeChild(messageList.firstChild);
|
messageList.removeChild(messageList.firstChild);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hideAfter > 0)
|
if (hideAfter > 0) {
|
||||||
{
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
lineItem.style.opacity = 0;
|
lineItem.style.opacity = 0;
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
@@ -1252,6 +1279,10 @@ function TranslateToFurry(sentence) {
|
|||||||
return furryWords.join('');
|
return furryWords.join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function EscapeRegExp(string) {
|
||||||
|
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////
|
///////////////////////////////////
|
||||||
|
|||||||
@@ -319,8 +319,7 @@ async function TwitchChatMessage(data) {
|
|||||||
const isSharedChat = data.isSharedChat;
|
const isSharedChat = data.isSharedChat;
|
||||||
if (isSharedChat) {
|
if (isSharedChat) {
|
||||||
if (showTwitchSharedChat > 1) {
|
if (showTwitchSharedChat > 1) {
|
||||||
if (!data.sharedChat.primarySource)
|
if (!data.sharedChat.primarySource) {
|
||||||
{
|
|
||||||
const sharedChatChannel = data.sharedChat.sourceRoom.name;
|
const sharedChatChannel = data.sharedChat.sourceRoom.name;
|
||||||
sharedChatDiv.style.display = 'block';
|
sharedChatDiv.style.display = 'block';
|
||||||
sharedChatChannelDiv.innerHTML = `💬 ${sharedChatChannel}`;
|
sharedChatChannelDiv.innerHTML = `💬 ${sharedChatChannel}`;
|
||||||
@@ -380,8 +379,7 @@ async function TwitchChatMessage(data) {
|
|||||||
messageDiv.style.color = messageColor;
|
messageDiv.style.color = messageColor;
|
||||||
|
|
||||||
// Remove the line break
|
// Remove the line break
|
||||||
if (inlineChat)
|
if (inlineChat) {
|
||||||
{
|
|
||||||
instance.querySelector("#colon-separator").style.display = `inline`;
|
instance.querySelector("#colon-separator").style.display = `inline`;
|
||||||
instance.querySelector("#line-space").style.display = `none`;
|
instance.querySelector("#line-space").style.display = `none`;
|
||||||
}
|
}
|
||||||
@@ -406,7 +404,21 @@ async function TwitchChatMessage(data) {
|
|||||||
// Render emotes
|
// Render emotes
|
||||||
for (i in data.emotes) {
|
for (i in data.emotes) {
|
||||||
const emoteElement = `<img src="${data.emotes[i].imageUrl}" class="emote"/>`;
|
const emoteElement = `<img src="${data.emotes[i].imageUrl}" class="emote"/>`;
|
||||||
messageDiv.innerHTML = messageDiv.innerHTML.replace(new RegExp(`\\b${data.emotes[i].name}\\b`), emoteElement);
|
const emoteName = EscapeRegExp(data.emotes[i].name);
|
||||||
|
|
||||||
|
let regexPattern = emoteName;
|
||||||
|
|
||||||
|
// Check if the emote name consists only of word characters (alphanumeric and underscore)
|
||||||
|
if (/^\w+$/.test(emoteName)) {
|
||||||
|
regexPattern = `\\b${emoteName}\\b`;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// For non-word emotes, ensure they are surrounded by non-word characters or boundaries
|
||||||
|
regexPattern = `(?:^|[^\\w])${emoteName}(?:$|[^\\w])`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const regex = new RegExp(regexPattern, 'g');
|
||||||
|
messageDiv.innerHTML = messageDiv.innerHTML.replace(regex, emoteElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render cheermotes
|
// Render cheermotes
|
||||||
@@ -585,7 +597,21 @@ async function TwitchAnnouncement(data) {
|
|||||||
for (i in data.parts) {
|
for (i in data.parts) {
|
||||||
if (data.parts[i].type == `emote`) {
|
if (data.parts[i].type == `emote`) {
|
||||||
const emoteElement = `<img src="${data.parts[i].imageUrl}" class="emote"/>`;
|
const emoteElement = `<img src="${data.parts[i].imageUrl}" class="emote"/>`;
|
||||||
content.querySelector("#message").innerHTML = content.querySelector("#message").innerHTML.replace(new RegExp(`\\b${data.parts[i].text}\\b`), emoteElement);
|
const emoteName = EscapeRegExp(data.parts[i].text);
|
||||||
|
|
||||||
|
let regexPattern = emoteName;
|
||||||
|
|
||||||
|
// Check if the emote name consists only of word characters (alphanumeric and underscore)
|
||||||
|
if (/^\w+$/.test(emoteName)) {
|
||||||
|
regexPattern = `\\b${emoteName}\\b`;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// For non-word emotes, ensure they are surrounded by non-word characters or boundaries
|
||||||
|
regexPattern = `(?:^|[^\\w])${emoteName}(?:$|[^\\w])`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const regex = new RegExp(regexPattern, 'g');
|
||||||
|
content.querySelector("#message").innerHTML = content.querySelector("#message").innerHTML.replace(regex, emoteElement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -920,8 +946,7 @@ function YouTubeMessage(data) {
|
|||||||
messageDiv.innerText = TranslateToFurry(data.message);
|
messageDiv.innerText = TranslateToFurry(data.message);
|
||||||
|
|
||||||
// Remove the line break
|
// Remove the line break
|
||||||
if (inlineChat)
|
if (inlineChat) {
|
||||||
{
|
|
||||||
instance.querySelector("#colon-separator").style.display = `inline`;
|
instance.querySelector("#colon-separator").style.display = `inline`;
|
||||||
instance.querySelector("#line-space").style.display = `none`;
|
instance.querySelector("#line-space").style.display = `none`;
|
||||||
}
|
}
|
||||||
@@ -2014,6 +2039,10 @@ function TranslateToFurry(sentence) {
|
|||||||
return furryWords.join('');
|
return furryWords.join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function EscapeRegExp(string) {
|
||||||
|
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////
|
///////////////////////////////////
|
||||||
|
|||||||
Reference in New Issue
Block a user