GitHub Network graph Intercept arrow keys

Stops the arrow keys from scrolling the page, because GitHub forgot to use "e.preventDefault();" when they made the keyboard shortcuts for the Network graph.

  1. // ==UserScript==
  2. // @name GitHub Network graph Intercept arrow keys
  3. // @namespace Violentmonkey Scripts
  4. // @match https://github.com/*
  5. // @grant none
  6. // @version 1.0
  7. // @description Stops the arrow keys from scrolling the page, because GitHub forgot to use "e.preventDefault();" when they made the keyboard shortcuts for the Network graph.
  8. // @license MIT
  9. // @inject-into content
  10. // ==/UserScript==
  11. const regex = /^https:\/\/github\.com\/\S+\/network$/;
  12. document.addEventListener("keydown", function(e){
  13. if (e.keyCode==37 || e.keyCode==38 || e.keyCode==39 || e.keyCode==40){
  14. if (document.location.href.match(regex)){
  15. if(document.activeElement.tagName!="INPUT"){
  16. e.preventDefault();
  17. }
  18. }
  19. }
  20. });