Substack:自动标记文章为已读
滚动超过文章 80% 后会在 localStorage 中标记为已读,并显示「Read」徽章。
可复制的代码
// Mark a post as "read" in localStorage after 80% of it has been scrolled through
(function () {
var KEY = 'jz-substack-read';
function load() { try { return JSON.parse(localStorage.getItem(KEY) || '{}'); } catch (e) { return {}; } }
function save(map) { try { localStorage.setItem(KEY, JSON.stringify(map)); } catch (e) {} }
function root() {
return document.querySelector('.body.markup, .available-content, [class*="postBody"]');
}
function badge() {
if (document.getElementById('jz-sub-read-badge')) { return; }
var d = document.createElement('div');
d.id = 'jz-sub-read-badge';
d.textContent = '✓ Read';
d.style.cssText = 'position:fixed;right:14px;bottom:14px;background:#16a34a;color:#fff;padding:6px 10px;border-radius:14px;font:600 12px/1 system-ui,sans-serif;z-index:99999;box-shadow:0 2px 6px rgba(0,0,0,.2);';
document.body.appendChild(d);
}
function check() {
var r = root(); if (!r) { return; }
var rect = r.getBoundingClientRect();
var seen = window.innerHeight - rect.top;
var pct = seen / rect.height;
if (pct < 0.8) { return; }
var key = location.pathname;
var map = load();
if (!map[key]) { map[key] = Date.now(); save(map); }
badge();
}
check();
var map = load();
if (map[location.pathname]) { badge(); }
window.addEventListener('scroll', function () {
clearTimeout(window.__jzSubRead);
window.__jzSubRead = setTimeout(check, 200);
}, { passive: true });
})();
如何使用此示例
- 用上方按钮复制代码。
- 安装 JustZix(2 分钟),在目标页面打开扩展。
- 添加一条匹配该页面的新规则。
- 将代码粘贴到规则的 JavaScript 面板并保存 — 每次访问页面时都会运行。
为此示例评分
暂无评分 — 成为第一个。