X: scorri i tweet con i tasti J/K
Permette di spostarti agevolmente tra i tweet con i tasti J (giù) e K (su) senza usare il mouse.
Codice da copiare
// Smoothly scroll tweet-by-tweet with the J and K keys
function tweets() {
return Array.prototype.slice.call(document.querySelectorAll('[data-testid="tweet"]'));
}
function current(list) {
for (let i = 0; i < list.length; i++) {
if (list[i].getBoundingClientRect().top > 60) { return i; }
}
return list.length - 1;
}
document.addEventListener('keydown', function (e) {
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 = tweets();
if (!list.length) { return; }
let idx = current(list);
idx += (e.key === 'j') ? 1 : -1;
idx = Math.max(0, Math.min(list.length - 1, idx));
list[idx].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.