Etsy: keyboard arrows for photo gallery
Lets you flip through product photos with the left and right arrow keys, no mouse needed.
Code to copy
// Browse the listing photo gallery with the left/right arrow keys
function thumbs() {
return Array.from(document.querySelectorAll(
'[data-component="listing-page-image-carousel"] '
+ 'button, .listing-page-image-carousel-component li button'));
}
document.addEventListener('keydown', function (e) {
if (e.target.matches('input, textarea')) { return; }
const list = thumbs();
if (!list.length) { return; }
let idx = list.findIndex(function (b) {
return b.getAttribute('aria-current') === 'true'
|| b.classList.contains('is-selected');
});
if (e.key === 'ArrowRight') { (list[idx + 1] || list[0]).click(); }
if (e.key === 'ArrowLeft') {
(list[idx - 1] || list[list.length - 1]).click();
}
});
How to use this example
- Copy the code with the button above.
- Install JustZix (2 minutes) and open the extension on the target page.
- Add a new rule matching that page.
- Paste the code into the rule's JavaScript panel and save — it runs on every page visit.
Rate this example
No ratings yet — be the first.