悬浮显示密码

鼠标悬浮在密码输入框上时 临时将密码显示为明文 鼠标移出后恢复为隐藏状态

目前为 2025-04-11 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name 悬浮显示密码
  3. // @description 鼠标悬浮在密码输入框上时 临时将密码显示为明文 鼠标移出后恢复为隐藏状态
  4. // @version 1.0.0
  5. // @icon https://raw.githubusercontent.com/MiPoNianYou/UserScripts/refs/heads/main/Icons/HoverPasswordIcon.svg
  6. // @author 念柚
  7. // @namespace https://github.com/MiPoNianYou/UserScripts
  8. // @license GPL-3.0
  9. // @match *://*/*
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. "use strict";
  15.  
  16. function HandlePasswordInput(input) {
  17. input.addEventListener("mouseover", function () {
  18. this.type = "text";
  19. });
  20. input.addEventListener("mouseout", function () {
  21. this.type = "password";
  22. });
  23. }
  24.  
  25. document
  26. .querySelectorAll('input[type="password"]')
  27. .forEach(HandlePasswordInput);
  28.  
  29. const Observer = new MutationObserver(function (mutations) {
  30. mutations.forEach(function (mutation) {
  31. if (mutation.addedNodes) {
  32. mutation.addedNodes.forEach(function (node) {
  33. if (
  34. node.nodeType === 1 &&
  35. node.tagName === "INPUT" &&
  36. node.type === "password"
  37. ) {
  38. HandlePasswordInput(node);
  39. } else if (node.nodeType === 1) {
  40. node
  41. .querySelectorAll('input[type="password"]')
  42. .forEach(HandlePasswordInput);
  43. }
  44. });
  45. }
  46. });
  47. });
  48.  
  49. Observer.observe(document.body, { childList: true, subtree: true });
  50. })();