Update site.js

按构建记下的表判断第一张配图是否在开头附近,和入口页预加载的保持一致。
This commit is contained in:
CyC2018
2026-11-06 06:58:42 +08:00
parent 3a17978a41
commit c3504aae1b
+5
View File
@@ -5,6 +5,11 @@
function encodedRoute(path) { return path.split('/').map(encodeURIComponent).join('/'); }
// 图片前面的正文不到 1200 字(文首目录不算)时,大概率在首屏内
function nearTop(img, root) {
var images = window.CS_NOTES_FIRST_IMAGES;
if (images) {
var route = decode((location.hash.replace(/^#/, '').split('?')[0]) || '');
return images[route] === img.getAttribute('src');
}
var block = img, chars = 0;
while (block.parentElement && block.parentElement !== root && block.parentElement.tagName !== 'BODY') block = block.parentElement;
for (var node = block.previousElementSibling; node; node = node.previousElementSibling) {