the previous version was overcomplicated, scrapping
This commit is contained in:
parent
53d64decf2
commit
90e3a578c1
1 changed files with 15 additions and 40 deletions
55
extra.js
55
extra.js
|
@ -232,46 +232,21 @@
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
let chatComponent = document.querySelector("pv-chat");
|
let chatComponent = document.querySelector("pv-chat");
|
||||||
chatComponent.supercharge = (t) => {
|
const proxied = new Proxy(chatComponent.sendChatMessage, {
|
||||||
let result = "";
|
apply: async function (target, thisArg, argumentsList) {
|
||||||
|
let result = chatComponent.input.value
|
||||||
for (let word of t.content.split(" ")) {
|
const normalEmojiMatches = result.matchAll(/(?<!<)(?<!<):([a-z0-9A-Z]*):/gm);
|
||||||
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 emojiMatches = result.matchAll(discordEmojiRegexWeb);
|
for (const normalEmojiMatch of normalEmojiMatches) {
|
||||||
for (const emojiMatch of emojiMatches) {
|
let emoji = emojis.find(z => z[0] == normalEmojiMatch[1]);
|
||||||
console.log(emojiMatch)
|
|
||||||
const isGif = emojiMatch[1] === "a";
|
if(emoji) {
|
||||||
const emojiId = emojiMatch[3];
|
result = result.replaceAll(":"+emoji[0]+":", emoji[1])
|
||||||
result = result.replace(
|
}
|
||||||
emojiMatch[0],
|
}
|
||||||
`<img src="https://cdn.discordapp.com/emojis/${emojiId}.${isGif ? "gif" : "png"}" alt="emoji" />`
|
chatComponent.input.value = result;
|
||||||
);
|
return target();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
return result;
|
chatComponent.sendChatMessage = proxied;
|
||||||
}
|
|
||||||
})();
|
})();
|
Loading…
Reference in a new issue