diff --git a/public/index.html b/public/index.html
index 03db34db..edf8898a 100755
--- a/public/index.html
+++ b/public/index.html
@@ -84,6 +84,90 @@
// name: 'YOU CAN DEFINE USER NAME HERE',
},
}
+
+ // 根据路径控制Dify机器人显示(只在首页/和home页/home显示)
+ function controlDifyChatbot() {
+ const path = window.location.pathname;
+ const chatbotButton = document.getElementById('dify-chatbot-bubble-button');
+ const chatbotWindow = document.getElementById('dify-chatbot-bubble-window');
+
+ // 只在首页(/)和home页(/home)显示Dify机器人
+ // const shouldShowDify = (path === '/' || path === '/home');
+ // 完全不显示Dify机器人(只使用Bytedesk客服)
+ const shouldShowDify = false
+
+ if (chatbotButton) {
+ chatbotButton.style.display = shouldShowDify ? 'block' : 'none';
+ // 同时设置visibility确保完全隐藏
+ chatbotButton.style.visibility = shouldShowDify ? 'visible' : 'hidden';
+ }
+
+ if (chatbotWindow) {
+ chatbotWindow.style.display = shouldShowDify ? '' : 'none';
+ }
+
+ console.log('[Dify] Path:', path, 'Should show:', shouldShowDify, 'Button found:', !!chatbotButton);
+ }
+
+ // 轮询检查Dify按钮(因为Dify脚本加载是异步的)
+ let difyCheckCount = 0;
+ const difyCheckInterval = setInterval(function() {
+ const button = document.getElementById('dify-chatbot-bubble-button');
+ if (button || difyCheckCount > 50) { // 最多检查5秒
+ if (button) {
+ console.log('[Dify] Button found, applying control');
+ controlDifyChatbot();
+ }
+ clearInterval(difyCheckInterval);
+ }
+ difyCheckCount++;
+ }, 100);
+
+ // 页面加载时执行
+ window.addEventListener('load', function() {
+ setTimeout(controlDifyChatbot, 1000);
+ });
+
+ // 监听路由变化(React Router使用pushState)
+ window.addEventListener('popstate', controlDifyChatbot);
+
+ // 监听pushState和replaceState(捕获React Router导航)
+ const originalPushState = history.pushState;
+ const originalReplaceState = history.replaceState;
+
+ history.pushState = function() {
+ originalPushState.apply(history, arguments);
+ setTimeout(controlDifyChatbot, 50);
+ };
+
+ history.replaceState = function() {
+ originalReplaceState.apply(history, arguments);
+ setTimeout(controlDifyChatbot, 50);
+ };
+
+ // 使用MutationObserver监听DOM变化(捕获Dify按钮插入)
+ const observer = new MutationObserver(function(mutations) {
+ for (const mutation of mutations) {
+ if (mutation.addedNodes.length > 0) {
+ for (const node of mutation.addedNodes) {
+ if (node.id && (node.id.includes('dify') || node.id.includes('chatbot'))) {
+ console.log('[Dify] Detected chatbot element insertion:', node.id);
+ setTimeout(controlDifyChatbot, 100);
+ break;
+ }
+ }
+ }
+ }
+ });
+
+ // 观察body的变化
+ window.addEventListener('DOMContentLoaded', function() {
+ observer.observe(document.body, {
+ childList: true,
+ subtree: true,
+ attributes: false
+ });
+ });