From 0ce6b32a125c38698113a1cb1ccdb7a788c616b2 Mon Sep 17 00:00:00 2001 From: easrng Date: Mon, 14 Feb 2022 12:31:30 -0500 Subject: [PATCH] Squash: Emojis! * Emojis! * fix bug * no more discord * maia: proper cache bustin --- frontend/emojis/blobcat.png | Bin 0 -> 2751 bytes frontend/lib/chat.mjs | 5 +++-- frontend/lib/emojis.mjs | 11 +++++++++++ frontend/styles.css | 7 +++++++ 4 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 frontend/emojis/blobcat.png create mode 100644 frontend/lib/emojis.mjs diff --git a/frontend/emojis/blobcat.png b/frontend/emojis/blobcat.png new file mode 100644 index 0000000000000000000000000000000000000000..761b24c108b321e97827b6a6894701391787014e GIT binary patch literal 2751 zcmV;w3PAOVP)2i*H^_uJV$LV&v?M`9BH=;yeZ z+u!{jpYQv7yYPsD^7&%%V{6Q7;^R2}XnUY5+Pohe1Rnfv9!%II@6B||do%s=-b~w{ z>ZU!OmCB2kn_DEXi38U!6pMDhnDQ9_^T-eZ@EmOq?pX1N^+C&kJb126?_M#o?*M=d z02}}Z;FJK9UK=MEz>p5?+yk;$VkcZxmCl}6oA4uNuRU-5^R^vf0=)KE;)eUH<6eri zxUDC+zx*NVEtUb<1I8l^E%0A%YTGhS-IpTy^+kZHDD^z1 z{e^$O{WH&}u?fJm7e_?w0(|^@!4x8H#BswAivS^)xkOrz22FY6?7(~g8w?YmYOx`8 z%w=fN1oCuo0{2`9DRD#yi%mX#s4Z|LOn|f`w(#r{jVv2`?G7^Z4smb=*`;@;(23fq z-T=uCrxJ{mg^VLpRf$IhQ~>NcDB`sb<6s+NNHP&N{d5>*1%XQ{hiZLJjp|^a9#LXI z0%L5V=07>4$J1NPIA!DD3o!KAIXwH883XPMpf3Q#6TnYtl@^mu!jRg+jI+QUcYx*Q z!VTZ}Y@@o(s~?!g?V^T3{}6}cT>_RC1g1uu0j(AuZ|pFlwOfZdSpjUg#f4cZN=(aD zE0}b;yyDrK4$fjp7H@VAak@DD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0=%MIe|-*4EHPa5GI!T3^7Jwa+d$wVd$1 z-)Z%I(D=2>wyzD;))u~KQWEJ2Kyfjcq~~1w=&>p%PqYV{x(9swnj5_>(lpun&5$BDeF^IBi_S4- zE#_texoKdz8GvMBxVlJhh8r1%pm7EAj2 zZ1UJu4Kt#iwyt1Te!9O87Ufij1A5OyFqO&VB*1G2ii`7^0U-t z9SkX { // clear events by just reconstructing the form @@ -236,7 +237,7 @@ export const logEventToChat = (event) => { case "ChatMessage": { const messageContent = document.createElement("span"); messageContent.classList.add("message-content"); - messageContent.textContent = event.data; + messageContent.append(...emojify(event.data)); printChatMessage( "chat-message", event.user, diff --git a/frontend/lib/emojis.mjs b/frontend/lib/emojis.mjs new file mode 100644 index 0000000..b97c31e --- /dev/null +++ b/frontend/lib/emojis.mjs @@ -0,0 +1,11 @@ +export function emojify(text) { + let last = 0; + let nodes = []; + text.replace(/:([^\s:]+):/g, (match, name, index) => { + if(last <= index) nodes.push(document.createTextNode(text.slice(last, index))) + nodes.push(Object.assign(new Image(), {src: `/emojis/${name}.png`, className: "emoji", alt: name})) + last = index + match.length + }) + if(last < text.length) nodes.push(document.createTextNode(text.slice(last))) + return nodes +} \ No newline at end of file diff --git a/frontend/styles.css b/frontend/styles.css index f1b9d52..7f019fe 100644 --- a/frontend/styles.css +++ b/frontend/styles.css @@ -159,6 +159,13 @@ button.small-button { color: unset !important; } +.emoji { + width: 2ch; + height: 2ch; + object-fit: contain; + margin-bottom: -0.35ch; +} + #chatbox { padding: 0.5em 2em; min-height: 8em;