Reddit: salta tra i post con i tasti J e K
Aggiunge le scorciatoie J e K che scorrono il feed in modo fluido al post successivo o precedente.
Codice da copiare
// Jump between feed posts with the J and K keys
function posts() {
return Array.prototype.slice.call(document.querySelectorAll('shreddit-post'));
}
function current(list) {
return list.findIndex(function (p) {
const r = p.getBoundingClientRect();
return r.top >= -2 && r.top < window.innerHeight / 2;
});
}
document.addEventListener('keydown', function (e) {
if (e.ctrlKey || e.metaKey || e.altKey) { return; }
const tag = (e.target.tagName || '').toLowerCase();
if (tag === 'input' || tag === 'textarea' || e.target.isContentEditable) { return; }
if (e.key !== 'j' && e.key !== 'k') { return; }
const list = posts();
if (!list.length) { return; }
let i = current(list);
if (i < 0) { i = 0; }
i += (e.key === 'j' ? 1 : -1);
i = Math.max(0, Math.min(list.length - 1, i));
list[i].scrollIntoView({ behavior: 'smooth', block: 'start' });
});
Come usare questo esempio
- Copia il codice con il pulsante qui sopra.
- Installa JustZix (2 minuti) e apri l'estensione sulla pagina di destinazione.
- Aggiungi una nuova regola corrispondente a quella pagina.
- Incolla il codice nel pannello JavaScript della regola e salva — viene eseguito a ogni visita della pagina.
Valuta questo esempio
Nessuna valutazione — sii il primo.