Compare commits
4 Commits
f376de2b48
...
c23fdbf310
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c23fdbf310 | ||
|
|
dfeed305e1 | ||
|
|
bc5485d622 | ||
|
|
d3b2949ff7 |
@@ -23,7 +23,6 @@
|
||||
<span slot="headline">错误</span>
|
||||
<span slot="description" id="ErrorDialog_Message"></span>
|
||||
</mdui-dialog>
|
||||
<input style="display: none;" id="copy_to_clipboard_fallback"></input>
|
||||
|
||||
<script nomodule>
|
||||
alert('很抱歉, 此应用无法在较旧的浏览器运行, 请使用基于 Chromium 89+ 的浏览器(内核)使用 :(')
|
||||
|
||||
@@ -7,6 +7,7 @@ import * as React from 'react'
|
||||
import ReactDOM from 'react-dom/client'
|
||||
|
||||
import './ui/custom-elements/chat-image.ts'
|
||||
import './ui/custom-elements/chat-video.ts'
|
||||
|
||||
const urlParams = new URL(location.href).searchParams
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@ const markedInstance = new marked.Marked({
|
||||
},
|
||||
image({ text, href }) {
|
||||
const type = /^(Video|File)=.*/.exec(text)?.[1] || 'Image'
|
||||
|
||||
if (/uploaded_files\/[A-Za-z0-9]+$/.test(href)) {
|
||||
return ({
|
||||
Image: `<chat-image src="${href}" alt="${text}"></chat-image>`,
|
||||
@@ -272,6 +271,8 @@ export default function ChatFragment({ target, showReturnButton, onReturnButtonC
|
||||
const rendeText = DOMPurify.sanitize(markedInstance.parse(msg.text) as string, {
|
||||
ALLOWED_TAGS: [
|
||||
"chat-image",
|
||||
"chat-video",
|
||||
"chat-file",
|
||||
"span",
|
||||
"chat-link",
|
||||
],
|
||||
|
||||
@@ -1,14 +1,20 @@
|
||||
import { $ } from 'mdui/jq'
|
||||
|
||||
export default function copyToClipboard(text: string) {
|
||||
if (navigator.clipboard) {
|
||||
navigator.clipboard.writeText(text)
|
||||
if (navigator.clipboard)
|
||||
return navigator.clipboard.writeText(text)
|
||||
return new Promise((res rej) => {
|
||||
if (document.hasFocus()) {
|
||||
const a = document.createElement("textarea")
|
||||
document.body.appendChild(a)
|
||||
a.style.position = "fixed"
|
||||
a.style.clip = "rect(0 0 0 0)"
|
||||
a.style.top = "10px"
|
||||
a.value = text
|
||||
a.select()
|
||||
document.execCommand("copy", true)
|
||||
document.body.removeChild(a)
|
||||
res()
|
||||
} else {
|
||||
const input = $('#copy_to_clipboard_fallback').get(0) as HTMLInputElement
|
||||
input.value = text
|
||||
input.select()
|
||||
input.setSelectionRange(0, 1145141919810)
|
||||
document.execCommand('copy')
|
||||
input.setSelectionRange(null, null)
|
||||
rej()
|
||||
}
|
||||
})
|
||||
}
|
||||
17
client/ui/custom-elements/chat-video.ts
Normal file
17
client/ui/custom-elements/chat-video.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { $ } from 'mdui/jq'
|
||||
|
||||
customElements.define('chat-video', class extends HTMLElement {
|
||||
constructor() {
|
||||
super()
|
||||
}
|
||||
connectedCallback() {
|
||||
this.style.display = 'block'
|
||||
const e = new DOMParser().parseFromString(`<video controls>視頻無法播放</video>`, 'text/html').body.firstChild as Node
|
||||
e.style.width = "100%"
|
||||
e.style.height = "100%"
|
||||
e.style.borderRadius = "var(--mdui-shape-corner-medium)"
|
||||
e.alt = $(this).attr('alt') || ""
|
||||
e.src = $(this).attr('src') as string
|
||||
this.appendChild(e)
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user