From ed3e629f19d61a8e0da3f165fb349f472bb455f1 Mon Sep 17 00:00:00 2001 From: Armored Dragon Date: Wed, 22 May 2024 22:31:28 -0500 Subject: [PATCH] Image embedding. Signed-off-by: Armored Dragon --- .../armored-chat/armored_chat.qml | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/scripts/communityScripts/armored-chat/armored_chat.qml b/scripts/communityScripts/armored-chat/armored_chat.qml index b34d941fc5..3bfb7aa95d 100644 --- a/scripts/communityScripts/armored-chat/armored_chat.qml +++ b/scripts/communityScripts/armored-chat/armored_chat.qml @@ -462,6 +462,8 @@ Rectangle { // Format content message = formatContent(message); + message = embedImages(message); + if (type === "notification"){ channel.append({ text: message, date: date, type: "notification" }); last_message_user = ""; @@ -507,6 +509,25 @@ Rectangle { return mess } + function embedImages(mess){ + var image_link = /(https?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+(?:\/[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]*)(?:png|jpe?g|gif|bmp|svg|webp)/g; + var matches = mess.match(image_link); + var new_message = "" + var listed = [] + var total_emeds = 0 + + new_message += mess + + for (var i = 0; matches && matches.length > i && total_emeds < 3; i++){ + if (!listed.includes(matches[i])) { + new_message += "
" + listed.push(matches[i]); + total_emeds++ + } + } + return new_message; + } + // Messages from script function fromScript(message) { let time = new Date().toLocaleTimeString(undefined, { hour12: false });