Show Password on Double Click

Double click toggles password to text field and back

  1. // ==UserScript==
  2. // @name Show Password on Double Click
  3. // @namespace myfonj
  4. // @description Double click toggles password to text field and back
  5. // @include *
  6. // @grant none
  7. // @license CC0
  8. // @version 2.0.3
  9. // ==/UserScript==
  10.  
  11. // https://greasyfork.org/en/scripts/431017/versions/new
  12.  
  13. if(!document.body || !document.body.addEventListener || !WeakSet) {
  14. return
  15. }
  16.  
  17. const swapped = new WeakSet();
  18.  
  19. document.body.addEventListener('dblclick', swap, true);
  20.  
  21. function swap(e) {
  22. const tgt = e.target;
  23. if( swapped.has(tgt) ) {
  24. tgt.type = 'password';
  25. swapped.delete(tgt);
  26. return
  27. }
  28. if ('INPUT' != tgt.tagName || 'password' != tgt.type) {
  29. return
  30. }
  31. tgt.type = 'text';
  32. swapped.add(tgt);
  33. }