GitLab: salta tra i file diff con J/K
Aggiunge le scorciatoie J e K per scorrere rapidamente tra i file modificati di una merge request.
Codice da copiare
// Use J and K keys to jump between diff files in a merge request
function files() {
return Array.prototype.slice.call(document.querySelectorAll('.diff-file'));
}
function jump(dir) {
const list = files();
if (!list.length) { return; }
const y = window.scrollY + 80;
let idx = list.findIndex(function (f) { return f.offsetTop > y; });
if (dir < 0) { idx = idx <= 0 ? 0 : idx - 1; }
else if (idx === -1) { idx = list.length - 1; }
const target = list[Math.max(0, Math.min(idx, list.length - 1))];
if (target) { window.scrollTo({ top: target.offsetTop - 60, behavior: 'smooth' }); }
}
document.addEventListener('keydown', function (e) {
const tag = (e.target.tagName || '').toLowerCase();
if (tag === 'input' || tag === 'textarea' || e.target.isContentEditable) { return; }
if (e.key === 'j') { jump(1); }
else if (e.key === 'k') { jump(-1); }
});
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.