improve internal patch, add client side emoji rendering

This commit is contained in:
Soph :3 2024-11-26 20:15:06 +02:00
parent e5afe772e3
commit 53d64decf2
Signed by: sophie
GPG key ID: EDA5D222A0C270F2
3 changed files with 53 additions and 13 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,8 +1,3 @@
if(window.PvInternals.services_client) {
console.log("%c--> pv.me", `color:yellow;font-size:30pt;`)
console.log("%cinternals available at window.PvInternals", `color:yellow;font-size:20pt;`)
}
// Reimplement PopupManager.open
(() => {
const pv = window.PvInternals;
@ -110,11 +105,12 @@ if(window.PvInternals.services_client) {
const emojiRequest = await fetch("emojis.json");
let emojis = await emojiRequest.json()
const discordEmojis = ['<:bratkanye:1271842184798273668>', '<a:aniblobsweat:586029851870363660>', '<:blobpensive:978314885337346089>', '<:blobsip:978314935077597231>', '<:blobheart:856700296302428170>', '<:blobsaluteban:463464097137295392>', '<:blobthinkban:812905997034061834>', '<:blobreach:474817265339203584>', '<a:blobReachAustralia:1247812442239795282>', '<:nixos:1252753664397934646>', '<:archlinux:1252754080640667658>', '<:rust:1263598244588425388>', '<:perfect:1243013970764370061>', '<:True:811294080662896640>', '<:froglove:1228043131430240407>', '<a:frogpop:1228043129811374081>', '<a:frogwave:1228043128871845979>', '<:pianoverse:1218346119705133116>', '<:restart:1257118826106064899>', '<:tape:1274061265714811054>', '<:what:1279839007714316392>', '<:boof:1261047926088663161>', '<:CHECK_CHECK_1:1075442774649872384>', '<:CHECK_CROSS_1:1075442781708898414>', '<a:pogg:947236908256362496>', '<a:peeposhy:1052873747561971732>', '<a:catfbi:1292722712212672582>', '<:cat:1184105614994063410>', '<:MBDTF:1263773146972946442>', '<a:SpeedL:906979227939778580>', '<a:SpeedR:906979227876864051>', '<a:newports:1005206666792419458>', '<a:myman:829624853845245953>', '<a:skyperock:937848388685279262>', '<:shut:714946339850420324>', '<a:sponge:854419399871561800>', '<a:weedwalker:855115903426625578>', '<a:furret:791595456147750943>', '<a:weewoo_red:706925335228317868>'];
const discordEmojiRegex = /<(a?):.*?:(\d+)>/g;
const discordEmojis = ["<:silly:1287108299057266850>", '<:bratkanye:1271842184798273668>', '<a:aniblobsweat:586029851870363660>', '<:blobpensive:978314885337346089>', '<:blobsip:978314935077597231>', '<:blobheart:856700296302428170>', '<:blobsaluteban:463464097137295392>', '<:blobthinkban:812905997034061834>', '<:blobreach:474817265339203584>', '<a:blobReachAustralia:1247812442239795282>', '<:nixos:1252753664397934646>', '<:archlinux:1252754080640667658>', '<:rust:1263598244588425388>', '<:perfect:1243013970764370061>', '<:True:811294080662896640>', '<:froglove:1228043131430240407>', '<a:frogpop:1228043129811374081>', '<a:frogwave:1228043128871845979>', '<:pianoverse:1218346119705133116>', '<:restart:1257118826106064899>', '<:tape:1274061265714811054>', '<:what:1279839007714316392>', '<:boof:1261047926088663161>', '<:CHECK_CHECK_1:1075442774649872384>', '<:CHECK_CROSS_1:1075442781708898414>', '<a:pogg:947236908256362496>', '<a:peeposhy:1052873747561971732>', '<a:catfbi:1292722712212672582>', '<:cat:1184105614994063410>', '<:MBDTF:1263773146972946442>', '<a:SpeedL:906979227939778580>', '<a:SpeedR:906979227876864051>', '<a:newports:1005206666792419458>', '<a:myman:829624853845245953>', '<a:skyperock:937848388685279262>', '<:shut:714946339850420324>', '<a:sponge:854419399871561800>', '<a:weedwalker:855115903426625578>', '<a:furret:791595456147750943>', '<a:weewoo_red:706925335228317868>'];
const discordEmojiRegex = /<(a?):(.*?):(\d+)>/g;
const discordEmojiRegexWeb = /&lt;(a?):(.*?):(\d+)&gt;/g;
function renderEmoji(emoji, size = "64") {
const id = emoji.replace(discordEmojiRegex, "$2");
const id = emoji.replace(discordEmojiRegex, "$3");
const isAnimated = !!emoji.replace(discordEmojiRegex, "$1")
const img = document.createElement("img");
img.src = `https://cdn.discordapp.com/emojis/${id}.${isAnimated ? "gif" : "png"}?size=${size}`;
@ -234,4 +230,48 @@ if(window.PvInternals.services_client) {
document.querySelector("body > div > div.chat > pv-chat > div").appendChild(button)
//#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 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" />`
);
}
return result;
}
})();