feat(wip): 複製到剪貼薄

This commit is contained in:
CrescentLeaf
2025-09-25 11:36:03 +08:00
parent a6ee231ad5
commit fdf52c0548
2 changed files with 15 additions and 0 deletions

View File

@@ -23,6 +23,7 @@
<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+ 的浏览器(内核)使用 :(')

View File

@@ -0,0 +1,14 @@
import { $ } from 'mdui/jq'
export default function copyToClipboard(text: string) {
if (navigator.clipboard) {
navigator.clipboard.writeText(text)
} else {
const input = $('#copy_to_clipboard_fallback').get(0) as HTMLInputElement
input.value = text
input.select()
input.setSelectionRange(0, 1145141919810)
document.execCommand('copy')
input.clearSelection()
}
}