Trigger debug on hotkey for any site

Messing with hard-to-catch events again? Trigger debug at any site by pressing hotkey combination (default is for ctrl+q), then inspect anything you want!

当前为 2024-03-28 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Trigger debug on hotkey for any site
  3. // @namespace K33p_Qu13t's Weird Scripts
  4. // @match *://*/*
  5. // @grant none
  6. // @version 1.1
  7. // @author K33p_Qu13t
  8. // @license MIT
  9. // @description Messing with hard-to-catch events again? Trigger debug at any site by pressing hotkey combination (default is for ctrl+q), then inspect anything you want!
  10. // ==/UserScript==
  11.  
  12. /** Char to trigger Debug with ctrl+char pressed*/
  13. const hotkeyChar = 'q';
  14.  
  15. let millisecondsHolded = 0;
  16. let holdStartTime;
  17. let timeoutId;
  18.  
  19. const onKeyDown = (e) => {
  20. if (!e.repeat && e.ctrlKey && e.key === hotkeyChar) {
  21. clearTimeout(timeoutId);
  22. // Set when started to hold hotkey
  23. holdStartTime = Date.now();
  24.  
  25. document.addEventListener('keyup', onKeyUp);
  26. }
  27. }
  28.  
  29. const onKeyUp = () => {
  30. millisecondsHolded = Date.now() - holdStartTime;
  31. timeoutId = setTimeout(() => {
  32. // Stop any code flow
  33. debugger;
  34. }, millisecondsHolded);
  35.  
  36. document.removeEventListener('keyup', onKeyUp);
  37. }
  38.  
  39. document.addEventListener('keydown', onKeyDown);