Greasy Fork is available in English.

Show Password on MouseOver

Show password when mouseover a password field

  1. // ==UserScript==
  2. // @name Show Password on MouseOver
  3. // @namespace MickyFoley
  4. // @description Show password when mouseover a password field
  5. // @version 1.1
  6. // @author MickyFoley
  7. // @license free
  8. // @include *
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. function showPassword(event) {
  14. const target = event.target;
  15. if (target.matches('input[type="password"]')) {
  16. target.type = 'text';
  17.  
  18. // Use MutationObserver to prevent interference
  19. const observer = new MutationObserver(mutations => {
  20. for (const mutation of mutations) {
  21. if (mutation.attributeName === 'type' && target.type !== 'text') {
  22. target.type = 'text';
  23. }
  24. }
  25. });
  26.  
  27. observer.observe(target, { attributes: true });
  28.  
  29. const restoreType = () => {
  30. observer.disconnect();
  31. target.type = 'password';
  32. target.removeEventListener('mouseleave', restoreType);
  33. };
  34.  
  35. target.addEventListener('mouseleave', restoreType, { once: true });
  36. }
  37. }
  38.  
  39. document.addEventListener('mouseover', showPassword, true);
  40. })();