Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cptpiepmatz/300d1267f3a73f1f92cbb1d97dd7d80b to your computer and use it in GitHub Desktop.
Save cptpiepmatz/300d1267f3a73f1f92cbb1d97dd7d80b to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Nexus Mods - right/left arrow pagination
// @match https://www.nexusmods.com/*
// @grant none
// @version 1.0
// @author Tim 'Piepmatz' Hesse
// @description Add event listeners to the right and left buttons for the pagination to allow to page with the arrow keys
// ==/UserScript==
const ARROW_KEYS = {
left: 37,
up: 38,
right: 39,
down: 40
}
document.addEventListener("keyup", event => {
let nextButton = document.querySelector(".pagination .next a");
let prevButton = document.querySelector(".pagination .prev a");
let leftKeyUp = event.keyCode === ARROW_KEYS.left;
let rightKeyUp = event.keyCode === ARROW_KEYS.right;
if ((leftKeyUp || rightKeyUp) && (nextButton || prevButton)) window.scrollTo({
top: 0,
behavior: "smooth"
});
if (rightKeyUp) nextButton?.click();
if (leftKeyUp) prevButton?.click();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment