Next or Previous Page Navigation

Press Alt+N to click the "Next" button and Alt+P to click the "Previous" or "Last" button, redirecting to their links if available.

  1. // ==UserScript==
  2. // @name Next or Previous Page Navigation
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Press Alt+N to click the "Next" button and Alt+P to click the "Previous" or "Last" button, redirecting to their links if available.
  6. // @author Sakib Shahariar
  7. // @license MIT
  8. // @match *://*/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. document.addEventListener('keydown', function(event) {
  16. if (event.altKey) {
  17. if (event.key === 'n') {
  18. clickNextButton();
  19. } else if (event.key === 'p') {
  20. clickPreviousButton();
  21. }
  22. }
  23. });
  24.  
  25. function clickNextButton() {
  26. const anchorElements = document.querySelectorAll('a');
  27. for (const anchor of anchorElements) {
  28. const buttonText = anchor.textContent.toLowerCase();
  29. if (buttonText.includes('next')) {
  30. const anchorHref = anchor.getAttribute('href');
  31. if (anchorHref) {
  32. window.location.href = anchorHref;
  33. }
  34. return;
  35. }
  36. }
  37. }
  38.  
  39. function clickPreviousButton() {
  40. const anchorElements = document.querySelectorAll('a');
  41. for (const anchor of anchorElements) {
  42. const buttonText = anchor.textContent.toLowerCase();
  43. if (buttonText.includes('previous') || buttonText.includes('prev')) {
  44. const anchorHref = anchor.getAttribute('href');
  45. if (anchorHref) {
  46. window.location.href = anchorHref;
  47. }
  48. return;
  49. }
  50. }
  51. }
  52. })();