支持从加密聊天打开隔离浏览器链接
This commit is contained in:
1 parent
f4ea1f8e03
commit
6786158a3e
8 files changed
+54
-8
No files matched your search
+1
-1
@@ -6,7 +6,7 @@ interface DeviceProof {
|
||||
interface DesktopBridge {
|
||||
apiBase: string
|
||||
signChallenge: (username: string, challenge: string) => Promise<DeviceProof>
|
||||
openBrowser?: () => Promise<void>
|
||||
openBrowser?: (url?: string) => Promise<void>
|
||||
signMls: (username: string, kind: 'credential' | 'KeyPackage', user: string, device: string, value: Uint8Array<ArrayBuffer>) => Promise<Uint8Array<ArrayBuffer>>
|
||||
protectMls: (key: string) => Promise<string>
|
||||
unprotectMls: (key: string) => Promise<string>
|
||||
|
||||
@@ -92,6 +92,7 @@ input { width: 100%; color: var(--text); background: var(--base); border: 1px so
|
||||
.chat-lines blockquote { border-left: 2px solid var(--line); margin: 0 0 4px; padding: 0 6px; color: var(--muted); font-size: .9em; }
|
||||
.message-actions { margin-top: 5px; }
|
||||
.message-actions .plain { font-size: .78em; padding: 2px 6px; }
|
||||
.chat-link { border: 0; background: transparent; color: var(--green); text-decoration: underline; padding: 0; overflow-wrap: anywhere; font: inherit; }
|
||||
.account-footer { display: grid; gap: 12px; margin-top: auto; }
|
||||
.account-footer p { color: var(--muted); font-size: 13px; }
|
||||
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin: 0 8px 1px 4px; }
|
||||
|
||||
@@ -38,6 +38,31 @@ const lines = computed(() => {
|
||||
(!favoritesOnly.value || line.favorite) &&
|
||||
(!query || [line.text, line.attachment?.name, line.quote].some((part) => part?.toLowerCase().includes(query))))
|
||||
})
|
||||
const internalBrowser = window.xhchat?.openBrowser
|
||||
|
||||
function messageParts(text: string) {
|
||||
const parts: { text: string; url?: string }[] = []
|
||||
let offset = 0
|
||||
for (const match of text.matchAll(/https?:\/\/[^\s<>"']+/giu)) {
|
||||
const label = match[0].replace(/[.,!?;:,。!?;:、))\]】]+$/u, '')
|
||||
try {
|
||||
const url = new URL(label)
|
||||
if (url.username || url.password || label.length > 4096 ||
|
||||
(url.protocol !== 'https:' && !['127.0.0.1', 'localhost', '[::1]'].includes(url.hostname))) continue
|
||||
if (match.index > offset) parts.push({ text: text.slice(offset, match.index) })
|
||||
parts.push({ text: label, url: url.href })
|
||||
offset = match.index + label.length
|
||||
} catch {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if (offset < text.length) parts.push({ text: text.slice(offset) })
|
||||
return parts
|
||||
}
|
||||
|
||||
function openLink(url: string) {
|
||||
if (internalBrowser) void execute(() => internalBrowser(url))
|
||||
}
|
||||
let timer: ReturnType<typeof setInterval>
|
||||
|
||||
async function execute(action: () => Promise<void>) {
|
||||
@@ -235,7 +260,10 @@ onBeforeUnmount(() => clearInterval(timer))
|
||||
<span v-if="line.recalled" class="muted">消息已撤回</span>
|
||||
<button v-else-if="line.attachment" type="button" class="plain" :disabled="busy"
|
||||
@click="saveAttachment(line.attachment)">下载 {{ line.attachment.name }}</button>
|
||||
<span v-else>{{ line.text }}</span><small v-if="view?.unsent.includes(line.id)">待发送</small>
|
||||
<span v-else><template v-for="(part, index) in messageParts(line.text)" :key="index"><button v-if="part.url && internalBrowser"
|
||||
type="button" class="chat-link" @click="openLink(part.url)">{{ part.text }}</button><a v-else-if="part.url"
|
||||
class="chat-link" :href="part.url" target="_blank" rel="noopener noreferrer">{{ part.text }}</a><template v-else>{{ part.text }}</template></template></span>
|
||||
<small v-if="view?.unsent.includes(line.id)">待发送</small>
|
||||
<small v-if="line.edited && !line.recalled">已编辑</small>
|
||||
<div class="message-actions">
|
||||
<button v-if="!line.recalled" type="button" class="plain" :disabled="busy || Boolean(editing)" @click="reply = line">引用</button>
|
||||
|
||||
Reference in new issue
Block a user