|
|
本帖最后由 哈哈哈哈_ 于 2026-6-17 22:46 编辑
// 精准提取徽章等图标,过滤掉由于 xi1 样式导致与标题文本重复的高亮文本
const stamps = originalTbody.querySelectorAll('th img:not(.wmsjlazy), th span.xi1, th a.xi1');
小改了一点点,这个位置把th img 改成了 th img:not(.wmsjlazy),如果板块勾选了预览图片,插入会过滤掉已经有的和谐图片
或者const stamps = originalTbody那里维持原样
clone节点插进来的图片是data-src没有src,重新将data-src插入到src,然后加上CSS属性,就可以显示和谐图片了
(修复优化:img加上lazy懒加载属性,并且放到div中,不会和标题在同一行)
- const imgDiv = document.createElement('div');
- // 精准提取徽章等图标,过滤掉由于 xi1 样式导致与标题文本重复的高亮文本
- const stamps = originalTbody.querySelectorAll('th img, th span.xi1, th a.xi1');
- stamps.forEach(stamp => {
- if (stamp.classList.contains('xst')) return;
- const stampText = stamp.textContent.trim();
- // 只有当元素是无字图片,或者其文字不包含主标题时才进行提取,完美过滤
- if (stampText === '' || (!titleText.includes(stampText) && !stampText.includes(titleText))) {
- th.appendChild(document.createTextNode(' '));
- // 图片src处理
- const clonedStamp = stamp.cloneNode(true);
- if (clonedStamp.tagName === 'IMG' && clonedStamp.getAttribute('data-src')) {
- clonedStamp.src = clonedStamp.getAttribute('data-src');
- clonedStamp.style.width = '180px';
- clonedStamp.style.height = 'auto';
- clonedStamp.style.objectFit = 'cover';
- clonedStamp.style.objectPosition = 'center';
- clonedStamp.style.background = '#fafafa';
- clonedStamp.loading = 'lazy';
- imgDiv.appendChild(clonedStamp);
- th.appendChild(imgDiv);
- } else {
- th.appendChild(clonedStamp);
- }
- }
- });
复制代码
|
评分
-
查看全部评分
|