diff --git a/extra.js b/extra.js index 5315b8a..5482799 100644 --- a/extra.js +++ b/extra.js @@ -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(/&/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("<", "<").replace(">", ">")]; - } - - 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(/(?<!<)(?<!<):([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; })(); \ No newline at end of file