diff --git a/app.vue b/app.vue
index c6db309..9c8fb1c 100644
--- a/app.vue
+++ b/app.vue
@@ -14,6 +14,7 @@ const banner = useState("banner", () => false);
onMounted(() => {
document.removeEventListener("contextmenu", contextMenuHandler);
document.addEventListener("contextmenu", (e) => {
+ if (e.target instanceof Element && e.target.classList.contains("default-contextmenu")) return;
contextMenuHandler(e);
});
document.addEventListener("mousedown", (e) => {
diff --git a/components/Message.vue b/components/Message.vue
index 7bff711..82bc151 100644
--- a/components/Message.vue
+++ b/components/Message.vue
@@ -50,8 +50,9 @@
{{ date.toLocaleTimeString(undefined, { hour12: props.format == "12", timeStyle: "short" }) }}
-
+
+
+
@@ -71,6 +73,7 @@
import DOMPurify from 'dompurify';
import { parse } from 'marked';
import type { MessageProps } from '~/types/props';
+import MessageMedia from './MessageMedia.vue';
import MessageReply from './UserInterface/MessageReply.vue';
const props = defineProps();
@@ -86,6 +89,13 @@ console.log("[MSG] message to render:", props.message);
console.log("author:", props.author);
console.log("[MSG] reply message:", props.replyMessage);
+const linkRegex = /https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)/g;
+const linkMatches = props.message.message.matchAll(linkRegex).map(link => link[0]);
+const mediaLinks: string[] = [];
+console.log("link matches:", linkMatches);
+
+const hasEmbed = ref(false);
+
const sanitized = ref();
onMounted(async () => {
@@ -112,6 +122,27 @@ onMounted(async () => {
});
console.log("added listeners");
}
+
+ for (const link of linkMatches) {
+ console.log("link:", link);
+ try {
+ const res = await $fetch.raw(link);
+ if (res.ok && res.headers.get("content-type")?.match(/^image\/(apng|gif|jpeg|png|webp)$/)) {
+ console.log("link is image");
+ mediaLinks.push(link);
+ }
+ if (mediaLinks.length) {
+ hasEmbed.value = true
+ setTimeout(() => {
+ scrollToBottom(document.getElementById("messages") as HTMLDivElement);
+ }, 500);
+ };
+ } catch (error) {
+ console.error(error);
+ }
+}
+
+console.log("media links:", mediaLinks);
});
//function toggleTooltip(e: Event) {
diff --git a/components/MessageMedia.vue b/components/MessageMedia.vue
new file mode 100644
index 0000000..ab62387
--- /dev/null
+++ b/components/MessageMedia.vue
@@ -0,0 +1,47 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file