Quora: salta tra le risposte con J/K
Aggiunge le scorciatoie J e K che fanno scorrere dolcemente alla risposta successiva o precedente.
Codice da copiare
// Jump between answers with the J and K keys
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 answers = Array.prototype.slice.call(
document.querySelectorAll('div[class*="puppeteer_test_answer_content"]')
);
if (!answers.length) { return; }
const y = window.scrollY + 80;
let idx = answers.findIndex(function (a) {
return a.getBoundingClientRect().top + window.scrollY > y;
});
if (e.key === 'k') { idx = idx - 2; }
idx = Math.max(0, Math.min(answers.length - 1, idx < 0 ? answers.length - 1 : idx));
answers[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.