Next/Previous navigation with arrow keys!

Use the arrow keys to navigate the next or previous pages of tutorials ;)

当前为 2025-03-05 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Next/Previous navigation with arrow keys!
  3. // @namespace Violentmonkey Scripts
  4. // @match https://www.w3schools.com/*/*
  5. // @grant none
  6. // @version 1.1
  7. // @author AvinashReddy3108 (assisted by ChatGPT)
  8. // @license WTFPL
  9. // @description Use the arrow keys to navigate the next or previous pages of tutorials ;)
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. document.addEventListener('keydown', function(event) {
  16. if (event.target.tagName.toLowerCase() === 'input' || event.target.tagName.toLowerCase() === 'textarea') {
  17. return; // Ignore inputs and textareas
  18. }
  19.  
  20. // Container which has the next/previous buttons
  21. let container = document.querySelector("div.w3-clear.nextprev");
  22. if (!container) return;
  23.  
  24. // The Next/Previous buttons
  25. let prevButton = container.querySelector("a.w3-left.w3-btn");
  26. let nextButton = container.querySelector("a.w3-right.w3-btn");
  27.  
  28. if (event.key === 'ArrowLeft' && prevButton) {
  29. window.location.href = prevButton.href;
  30. } else if (event.key === 'ArrowRight' && nextButton) {
  31. window.location.href = nextButton.href;
  32. }
  33. });
  34. })();