the previous version was overcomplicated, scrapping

This commit is contained in:
Soph :3 2024-11-26 20:36:30 +02:00
parent 53d64decf2
commit 90e3a578c1
Signed by: sophie
GPG key ID: EDA5D222A0C270F2

View file

@ -232,46 +232,21 @@
//#endregion
let chatComponent = document.querySelector("pv-chat");
chatComponent.supercharge = (t) => {
let result = "";
for (let word of t.content.split(" ")) {
const hyperlinkMatch = word.match(/https?:\/\/[^\s@"'\$\{\}\\]{2,}/);
if (word.startsWith("@") && word.length > 2 && word.length <= 24) {
word = `<span class="mention">${escapeHtml(word)}</span>`;
} else if (hyperlinkMatch) {
const hyperlink = escapeHtml(hyperlinkMatch[0]).replace(/&amp;/g, "&");
word = `<a href="${hyperlink}" target="_blank">${hyperlink}</a>`;
}
result += `${word} `;
}
const normalEmojiMatches = result.matchAll(/:([^:]*):/gm);
for (const normalEmojiMatch of normalEmojiMatches) {
let emoji = emojis.find(z => z[0] == normalEmojiMatch[1]);
if(!emoji) {
const discordEmoji = discordEmojis.find(z => z.replace(discordEmojiRegex, "$2") == normalEmojiMatch[1]);
if(discordEmoji) emoji = [discordEmoji.replace(discordEmojiRegex, "$2"), discordEmoji.replace(discordEmojiRegex, "<$1:a:$3>").replace("<", "&lt;").replace(">", "&gt;")];
}
if(emoji) {
result = result.replace(":"+emoji[0]+":", emoji[1])
}
}
const proxied = new Proxy(chatComponent.sendChatMessage, {
apply: async function (target, thisArg, argumentsList) {
let result = chatComponent.input.value
const normalEmojiMatches = result.matchAll(/(?<!&lt;)(?<!<):([a-z0-9A-Z]*):/gm);
const emojiMatches = result.matchAll(discordEmojiRegexWeb);
for (const emojiMatch of emojiMatches) {
console.log(emojiMatch)
const isGif = emojiMatch[1] === "a";
const emojiId = emojiMatch[3];
result = result.replace(
emojiMatch[0],
`<img src="https://cdn.discordapp.com/emojis/${emojiId}.${isGif ? "gif" : "png"}" alt="emoji" />`
);
for (const normalEmojiMatch of normalEmojiMatches) {
let emoji = emojis.find(z => z[0] == normalEmojiMatch[1]);
if(emoji) {
result = result.replaceAll(":"+emoji[0]+":", emoji[1])
}
}
chatComponent.input.value = result;
return target();
}
return result;
}
});
chatComponent.sendChatMessage = proxied;
})();