Show/Hide Password

Show/Hide Password when hovering over the input password

当前为 2023-06-27 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Show/Hide Password
  3. // @version 1.1
  4. // @description Show/Hide Password when hovering over the input password
  5. // @icon https://cdn-icons-png.flaticon.com/512/312/312404.png
  6. // @match *://*/*
  7. // @grant none
  8. // @license MIT
  9. // @unwrap
  10. // @namespace https://greasyfork.org/users/821661
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // Define a function to show the password
  17. function showPassword(field) {
  18. field.type = 'text';
  19. }
  20.  
  21. // Define a function to hide the password
  22. function hidePassword(field) {
  23. field.type = 'password';
  24. }
  25.  
  26. // Select all password input fields on the page
  27. const passwordFields = document.querySelectorAll('input[type="password"]');
  28.  
  29. // Loop through each password field and add the show/hide password events
  30. passwordFields.forEach(field => {
  31. // Show password on mouseover and focus
  32. field.addEventListener('mouseover', () => {
  33. showPassword(field);
  34. });
  35. field.addEventListener('focus', () => {
  36. showPassword(field);
  37. });
  38.  
  39. // Hide password on mouseout and blur
  40. field.addEventListener('mouseout', () => {
  41. hidePassword(field);
  42. });
  43. field.addEventListener('blur', () => {
  44. hidePassword(field);
  45. });
  46. });
  47. })();