Mastodon:J / K 键盘导航
用 J 和 K 键在时间线嘟文间跳转,并高亮当前选中的状态。
可复制的代码
// Navigate timeline posts with J / K keys
(function () {
function posts() {
return Array.from(document.querySelectorAll('.columns-area__panels__main article, .columns-area__panels__main .status'));
}
let idx = -1;
function go(step) {
const list = posts();
if (!list.length) { return; }
idx = Math.max(0, Math.min(list.length - 1, idx + step));
const el = list[idx];
if (el) {
el.scrollIntoView({ behavior: 'smooth', block: 'center' });
el.style.outline = '2px solid #6364ff';
setTimeout(function () { el.style.outline = ''; }, 700);
}
}
document.addEventListener('keydown', function (e) {
if (e.target && /^(INPUT|TEXTAREA)$/.test(e.target.tagName)) { return; }
if (e.target && e.target.isContentEditable) { return; }
if (e.key === 'j') { go(1); }
else if (e.key === 'k') { go(-1); }
});
})();
如何使用此示例
- 用上方按钮复制代码。
- 安装 JustZix(2 分钟),在目标页面打开扩展。
- 添加一条匹配该页面的新规则。
- 将代码粘贴到规则的 JavaScript 面板并保存 — 每次访问页面时都会运行。
为此示例评分
暂无评分 — 成为第一个。