Last active
July 16, 2023 10:35
-
-
Save cptpiepmatz/300d1267f3a73f1f92cbb1d97dd7d80b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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