${index + 1}. ${shortDisplayName}
💰 价格: ${product.price_info || '无'}
📈 销量: ${product.sales_tip || '无'}
🔍 搜索文本: "${searchText.substring(0, 20)}${searchText.length > 20 ? '...' : ''}"
`;
item.appendChild(img);
item.appendChild(info);
list.appendChild(item);
});
}
function updateServerStatus(connected, message = '') {
const statusElement = document.getElementById('pdd-server-status');
if (!statusElement) return;
if (connected) {
statusElement.innerHTML = '✅ 已连接';
statusElement.style.background = 'rgba(34, 197, 94, 0.2)';
} else {
statusElement.innerHTML = message || '❌ 未连接';
statusElement.style.background = 'rgba(239, 68, 68, 0.2)';
}
}
function updateServerProductCount(count) {
const countElement = document.getElementById('pdd-server-count');
if (countElement) {
countElement.textContent = count;
countElement.style.color = count > 0 ? '#10b981' : '#ef4444';
}
}
// ==================== 样式 ====================
function addStyles() {
const style = document.createElement('style');
style.textContent = `
@keyframes pdd-highlight-blink {
0% { background-color: #ffff00; }
50% { background-color: #ffea00; }
100% { background-color: #ffff00; }
}
.pdd-product-highlight {
transition: outline 0.3s ease;
animation: pdd-product-pulse 2s infinite;
}
@keyframes pdd-product-pulse {
0% { outline-color: #ff6b6b; }
50% { outline-color: #ff9e6b; }
100% { outline-color: #ff6b6b; }
}
#pdd-ctrl-f-matcher {
touch-action: none !important;
}
`;
document.head.appendChild(style);
}
// ==================== 初始化 ====================
function initialize() {
STATE.matchState.searcher = new TextSearcher();
installJsonHook();
setupScrollListener();
createUI();
addStyles();
console.log(`🚀 PDD Ctrl+F式商品匹配系统启动(终极修复版)`);
console.log(`📱 设备类型: ${IS_MOBILE ? '移动设备' : '桌面设备'}`);
console.log('🔄 滚动控制: 终极修复版本');
// 启动WebSocket连接
initSocket();
startHealthCheck();
// 页面加载自动开始
safeSetTimeout(() => {
autoStartOnPageLoad();
}, 3000);
}
// ==================== 全局暴露 ====================
window.PDD_CtrlF_Matcher = {
start: startMatching,
stop: stopMatching,
startAutoScroll: startAutoScroll,
stopAutoScroll: completelyStopAllScrolling,
getProducts: () => STATE.socketState.processedProducts,
getRawProducts: () => STATE.socketState.currentProducts,
getFirstInteraction: () => STATE.firstInteraction,
state: STATE
};
// 启动
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initialize);
} else {
setTimeout(initialize, 1000);
}
})();