feat: 添加国产浏览器兼容性提示和用户交互解锁机制
This commit is contained in:
BIN
logs/server.log
BIN
logs/server.log
Binary file not shown.
@@ -453,6 +453,9 @@
|
||||
<!-- TTS 设置 -->
|
||||
<div class="tts-section">
|
||||
<h3>🔊 TTS语音合成设置</h3>
|
||||
<div class="browser-tip" id="browserTip" style="display: none; background: #fff3cd; padding: 8px 12px; border-radius: 6px; margin-bottom: 10px; font-size: 13px; color: #856404;">
|
||||
⚠️ 当前浏览器可能限制音频播放,建议使用 Chrome/Firefox,或点击页面任意位置解锁播放
|
||||
</div>
|
||||
<div class="tts-options" id="ttsOptions">
|
||||
<div class="tts-option" data-provider="none">
|
||||
<div class="name">❌ 无 TTS</div>
|
||||
@@ -545,6 +548,16 @@
|
||||
let currentVoice = 'zh-CN-XiaoxiaoNeural';
|
||||
let autoPlay = true; // 自动播放开关
|
||||
let volumeLevel = 1.5; // 音量倍率
|
||||
let userInteracted = false; // 用户是否已交互
|
||||
|
||||
// 用户点击页面解锁音频播放能力
|
||||
document.addEventListener('click', () => {
|
||||
userInteracted = true;
|
||||
}, { once: true });
|
||||
|
||||
document.addEventListener('touchstart', () => {
|
||||
userInteracted = true;
|
||||
}, { once: true });
|
||||
|
||||
// 元素
|
||||
const statusDot = document.getElementById('statusDot');
|
||||
@@ -569,10 +582,25 @@
|
||||
await checkStatus();
|
||||
await loadTTSProviders();
|
||||
|
||||
// 检测特殊浏览器(小米浏览器等)
|
||||
checkBrowser();
|
||||
|
||||
// 定时检查状态
|
||||
setInterval(checkStatus, 10000);
|
||||
}
|
||||
|
||||
// 检测浏览器兼容性
|
||||
function checkBrowser() {
|
||||
const ua = navigator.userAgent.toLowerCase();
|
||||
const browserTip = document.getElementById('browserTip');
|
||||
|
||||
// 小米浏览器、华为浏览器等国产浏览器UA特征
|
||||
if (ua.includes('miui') || ua.includes('xiaomi') || ua.includes('huawei') ||
|
||||
ua.includes('micromessenger') || ua.includes('quark') || ua.includes('ucbrowser')) {
|
||||
browserTip.style.display = 'block';
|
||||
}
|
||||
}
|
||||
|
||||
// 检查服务状态
|
||||
async function checkStatus() {
|
||||
try {
|
||||
@@ -913,7 +941,7 @@
|
||||
chatSection.scrollTop = chatSection.scrollHeight;
|
||||
|
||||
// 自动播放(在元素添加到DOM后)
|
||||
if (role === 'assistant' && audioData && autoPlay && audioBtnId) {
|
||||
if (role === 'assistant' && audioData && autoPlay && audioBtnId && userInteracted) {
|
||||
setTimeout(() => {
|
||||
const btn = document.getElementById(audioBtnId);
|
||||
if (btn) {
|
||||
|
||||
Reference in New Issue
Block a user