优化
This commit is contained in:
56
test.html
Normal file
56
test.html
Normal file
@@ -0,0 +1,56 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>复制赛事录制码</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<button onclick="copyEventInfo()">复制赛事录制码</button>
|
||||
|
||||
<textarea id="copyText" style="position: fixed; left: -9999px;"></textarea>
|
||||
|
||||
<script>
|
||||
function copyEventInfo() {
|
||||
const data = {
|
||||
title: '王东方 丨李想 空中格斗赛',
|
||||
startTimestamp: 1717334400,
|
||||
endTimestamp: 1717334400,
|
||||
address: '广州市番禺区·粤港澳大湾区青年人才双创小镇',
|
||||
}
|
||||
|
||||
const jsonStr = JSON.stringify(data)
|
||||
|
||||
if (navigator.clipboard && window.isSecureContext) {
|
||||
navigator.clipboard.writeText(jsonStr)
|
||||
.then(() => {
|
||||
alert('赛事录制码已复制')
|
||||
})
|
||||
.catch(() => {
|
||||
fallbackCopy(jsonStr)
|
||||
})
|
||||
} else {
|
||||
fallbackCopy(jsonStr)
|
||||
}
|
||||
}
|
||||
|
||||
function fallbackCopy(text) {
|
||||
const textarea = document.getElementById('copyText')
|
||||
textarea.value = text
|
||||
textarea.select()
|
||||
textarea.setSelectionRange(0, textarea.value.length)
|
||||
|
||||
try {
|
||||
document.execCommand('copy')
|
||||
alert('赛事录制码已复制')
|
||||
} catch (err) {
|
||||
console.error('复制失败:', err)
|
||||
alert('复制失败,请手动复制')
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user