/* 功能:鼠标移入缩略图 ≡ 手动点击缩略图,完全复用原生点击逻辑 */
document.addEventListener('DOMContentLoaded', function() {
console.log('「缩略图移入等效点击」脚本启动');
// 1. 核心选择器(匹配你的主题结构,已验证)
const THUMBNAIL_SELECTOR = '.pr_lazy_img.lazyloaded'; // 已加载的缩略图
const THUMBNAIL_CONTAINER = '.thumbnail-slider, .product-thumbnails'; // 缩略图容器
const SCROLL_BUTTONS = '.thumbnail-arrow, .scroll-button'; // 滚动导航按钮
// 2. 防重复绑定标记 + 防快速触发时间戳
const boundThumbs = new WeakSet(); // 记录已绑定的缩略图(避免内存泄漏)
const CLICK_INTERVAL = 300; // 300ms内不重复触发
// 3. 预加载图片(提升点击后显示速度,保留原体验)
const preloadImg = (url) => {
if (!url) return;
const img = new Image();
img.src = url.startsWith('//') ? `https:${url}` : url;
};
// 4. 核心:鼠标移入触发原生点击
const bindHoverAsClick = (thumbnail) => {
// 跳过已绑定、未加载完成的缩略图
if (boundThumbs.has(thumbnail) || !thumbnail.classList.contains('lazyloaded')) {
return;
}
// 预加载当前缩略图对应的大图
const bgset = thumbnail.dataset.bgset;
if (bgset) {
const urls = bgset.split(',').map(item => item.trim().match(/(\/\/[^ ]+)/)?.[1]).filter(Boolean);
if (urls.length) preloadImg(urls[urls.length - 1]); // 预加载最大尺寸图
}
// 绑定鼠标移入事件
thumbnail.addEventListener('mouseenter', (e) => {
// 防误触:仅鼠标未按下、且未在短时间内重复触发
const lastClick = thumbnail.dataset.lastClick || 0;
if (e.buttons !== 0 || (Date.now() - lastClick) < CLICK_INTERVAL) {
return;
}
// 模拟真实点击事件(完全复用原生点击逻辑)
const clickEvent = new MouseEvent('click', {
bubbles: true, // 允许事件冒泡(触发主题内置逻辑)
cancelable: true, // 允许阻止默认行为
view: window,
buttons: 0 // 模拟无按键状态的点击
});
// 触发点击 + 记录时间戳
thumbnail.dispatchEvent(clickEvent);
thumbnail.dataset.lastClick = Date.now();
console.log('移入触发缩略图点击:', thumbnail);
});
boundThumbs.add(thumbnail); // 标记为已绑定
};
// 5. 初始化:处理已存在的缩略图 + 确保滚动按钮可见
const initThumbnails = () => {
const containers = document.querySelectorAll(THUMBNAIL_CONTAINER);
containers.forEach(container => {
// 确保滚动按钮可见(不干扰导航)
container.querySelectorAll(SCROLL_BUTTONS).forEach(btn => {
btn.style.visibility = 'visible';
btn.style.opacity = '1';
btn.style.pointerEvents = 'auto';
});
// 处理容器内已存在的缩略图
container.querySelectorAll(THUMBNAIL_SELECTOR).forEach(bindHoverAsClick);
});
};
// 6. 动态监测:捕获滚动/加载的新缩略图
const observeNewThumbs = () => {
const containers = document.querySelectorAll(THUMBNAIL_CONTAINER);
if (containers.length) {
containers.forEach(container => {
const observer = new MutationObserver((mutations) => {
mutations.forEach(mutation => {
// 处理新添加的节点
mutation.addedNodes.forEach(node => {
if (node.nodeType !== 1) return; // 只处理元素节点
// 若新节点是缩略图,直接绑定;否则查找子缩略图
if (node.matches(THUMBNAIL_SELECTOR)) {
bindHoverAsClick(node);
} else {
node.querySelectorAll(THUMBNAIL_SELECTOR).forEach(bindHoverAsClick);
}
});
});
});
// 监听容器内的DOM变化
observer.observe(container, {
childList: true,
subtree: true,
attributes: true,
attributeFilter: ['class'] // 监测lazyloaded类的添加
});
});
} else {
// 备用:若未找到容器,监测整个文档(兼容更多结构)
const observer = new MutationObserver((mutations) => {
mutations.forEach(mutation => {
mutation.addedNodes.forEach(node => {
if (node.nodeType === 1) {
node.querySelectorAll(THUMBNAIL_SELECTOR).forEach(bindHoverAsClick);
}
});
});
});
observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['class'] });
}
};
// 7. 启动脚本(先初始化已存在的,再监测新的)
initThumbnails();
observeNewThumbs();
console.log('「缩略图移入等效点击」脚本加载完成');
});
Description
1. Speaker ringer buzzer for Nokia 7.2/6.2
2. Replace your broken or unusable one with a new one
3. Each item has been checked and in good condition before shipping
4. Completely fit and work
5. Professional installation is highly recommended. We will not be responsible for any damages to your cellphone/mobile phone that you may cause during the changing of replacement parts
Specification:
General
Compatible with
Nokia: 6.2, 7.2
Package Weight
One Package Weight
0.02kgs / 0.04lb
One Package Size
15cm * 12cm * 1cm / 5.91inch * 4.72inch * 0.39inch
Carton Weight
1.44kgs / 3.17lb
Carton Size
42cm * 32cm * 32cm / 16.54inch * 12.6inch * 12.6inch
Loading Container
20GP: 620 cartons * 120 pcs = 74400 pcs 40HQ: 1439 cartons * 120 pcs = 172680 pcs