Substack:强制图片懒加载
为所有图片设置 loading="lazy" 与更低的获取优先级,在图片繁多的文章中节省流量。
可复制的代码
// Force lazy-loading on every image to save bandwidth on image-heavy posts
(function () {
function patch() {
document.querySelectorAll('img').forEach(function (img) {
if (img.dataset.jzLazy) { return; }
img.dataset.jzLazy = '1';
try {
img.loading = 'lazy';
img.decoding = 'async';
if (img.fetchPriority && img.fetchPriority !== 'low') { img.fetchPriority = 'low'; }
} catch (e) {}
});
}
patch();
var obs = new MutationObserver(function () {
clearTimeout(window.__jzSubLazy);
window.__jzSubLazy = setTimeout(patch, 300);
});
obs.observe(document.body, { childList: true, subtree: true });
})();
如何使用此示例
- 用上方按钮复制代码。
- 安装 JustZix(2 分钟),在目标页面打开扩展。
- 添加一条匹配该页面的新规则。
- 将代码粘贴到规则的 JavaScript 面板并保存 — 每次访问页面时都会运行。
为此示例评分
暂无评分 — 成为第一个。