diff --git a/client/index.ts b/client/index.ts index 892bc88..dc27019 100644 --- a/client/index.ts +++ b/client/index.ts @@ -8,6 +8,7 @@ import ReactDOM from 'react-dom/client' import './ui/custom-elements/chat-image.ts' import './ui/custom-elements/chat-video.ts' +import './ui/custom-elements/chat-file.ts' const urlParams = new URL(location.href).searchParams diff --git a/client/ui/chat/ChatFragment.tsx b/client/ui/chat/ChatFragment.tsx index 67f8b5a..cdc53be 100644 --- a/client/ui/chat/ChatFragment.tsx +++ b/client/ui/chat/ChatFragment.tsx @@ -36,8 +36,8 @@ const markedInstance = new marked.Marked({ if (/uploaded_files\/[A-Za-z0-9]+$/.test(href)) { return ({ Image: ``, - Video: ``, - File: ``, + Video: ``, + File: ``, })?.[type] || `` } return `` @@ -280,6 +280,7 @@ export default function ChatFragment({ target, showReturnButton, onReturnButtonC 'src', 'alt', 'href', + 'name', ], }).replaceAll('\n', '
') const lastDate = date diff --git a/client/ui/custom-elements/chat-file.ts b/client/ui/custom-elements/chat-file.ts new file mode 100644 index 0000000..4fea0eb --- /dev/null +++ b/client/ui/custom-elements/chat-file.ts @@ -0,0 +1,22 @@ +import { $ } from 'mdui/jq' + +customElements.define('chat-file', class extends HTMLElement { + constructor() { + super() + } + connectedCallback() { + this.style.display = 'block' + const e = new DOMParser().parseFromString(` +
+ + + + +
`, 'text/html').body.firstChild as HTMLElement + $(e).find('span').text($(this).attr("name")) + const href = $(this).attr('href') + // deno-lint-ignore no-window + e.onclick = () => window.open(href, '_blank') + this.appendChild(e) + } +})