forked from lavender/watch-party
		
	only emojify actual emojis
This commit is contained in:
		
							parent
							
								
									e6699e05dd
								
							
						
					
					
						commit
						e9a1b762e7
					
				
					 2 changed files with 15 additions and 10 deletions
				
			
		|  | @ -286,7 +286,7 @@ const formatTime = (ms) => { | |||
|   }:${seconds < 10 ? "0" + seconds : seconds}`;
 | ||||
| }; | ||||
| 
 | ||||
| export const logEventToChat = (event) => { | ||||
| export const logEventToChat = async (event) => { | ||||
|   if (checkDebounce(event)) { | ||||
|     return; | ||||
|   } | ||||
|  | @ -313,7 +313,7 @@ export const logEventToChat = (event) => { | |||
|     case "ChatMessage": { | ||||
|       const messageContent = document.createElement("span"); | ||||
|       messageContent.classList.add("message-content"); | ||||
|       messageContent.append(...emojify(event.data)); | ||||
|       messageContent.append(...(await emojify(event.data))); | ||||
|       printChatMessage( | ||||
|         "chat-message", | ||||
|         event.user, | ||||
|  |  | |||
|  | @ -1,16 +1,21 @@ | |||
| export function emojify(text) { | ||||
| export async function emojify(text) { | ||||
|   const emojiList = await emojis; | ||||
|   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, | ||||
|       }) | ||||
|     ); | ||||
|     if (!emojiList.includes(name)) { | ||||
|       nodes.push(document.createTextNode(match)); | ||||
|     } else { | ||||
|       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))); | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue