Print Own Code on $

Print the code of this user script when you press the $ key

  1. // ==UserScript==
  2. // @name Print Own Code on $
  3. // @namespace your-namespace
  4. // @version 1.0
  5. // @description Print the code of this user script when you press the $ key
  6. // @match *://*/*
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10. (function() {
  11. 'use strict';
  12.  
  13. // Function to print the script code
  14. function printScriptCode() {
  15. const scriptElements = document.querySelectorAll('script');
  16. for (const script of scriptElements) {
  17. if (script.src === '' && script.textContent.includes('// ==UserScript==')) {
  18. console.log(script.textContent);
  19. }
  20. }
  21. }
  22.  
  23. // Function to handle the keyboard event
  24. function handleKeyPress(event) {
  25. if (event.key === '$') {
  26. printScriptCode();
  27. }
  28. }
  29.  
  30. // Add a keyboard event listener
  31. document.addEventListener('keydown', handleKeyPress);
  32. })();