Threads: skróty J/K do nawigacji wpisami
Dodaje skróty klawiszowe J i K, które przewijają kanał kolejno do następnego i poprzedniego wpisu.
Kod do skopiowania
// Keyboard: press J / K to step between posts in the feed
let idx = -1;
function posts() {
return Array.from(document.querySelectorAll('[data-pressable-container]'))
.filter(p => p.offsetParent !== null);
}
document.addEventListener('keydown', e => {
if (e.target.matches('input, textarea, [contenteditable="true"]')) return;
const key = e.key.toLowerCase();
if (key !== 'j' && key !== 'k') return;
const list = posts();
if (!list.length) return;
idx = key === 'j' ? Math.min(idx + 1, list.length - 1) : Math.max(idx - 1, 0);
list[idx].scrollIntoView({ behavior: 'smooth', block: 'center' });
});
Jak użyć tego przykładu
- Skopiuj kod przyciskiem powyżej.
- Zainstaluj JustZix (2 minuty) i otwórz wtyczkę na docelowej stronie.
- Dodaj nową regułę dopasowaną do tej strony.
- Wklej kod w panelu JavaScript reguły i zapisz — uruchomi się przy każdym wejściu na stronę.
Oceń ten przykład
Brak ocen — oceń jako pierwszy.