Password Revealer

Shows passwords on mouse hover or focus

目前为 2014-10-25 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Password Revealer
  3. // @namespace http://userscripts.org/users/23652
  4. // @description Shows passwords on mouse hover or focus
  5. // @include http://*
  6. // @include https://*
  7. // @include file:///*
  8. // @exclude file:///*/perf.html*
  9. // @copyright JoeSimmons
  10. // @version 1.0.5
  11. // @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
  12. // ==/UserScript==
  13. (function() {
  14.  
  15.  
  16.  
  17.  
  18. var show_only_on_click = false; // only show passwords when you click on the field
  19.  
  20.  
  21.  
  22.  
  23.  
  24. var handlers = [];
  25.  
  26. function toText(e) {
  27. e = e.target;
  28.  
  29. if (e.tagName === 'INPUT' && e.type === 'password') {
  30. // save the cursor position
  31. e.caretStart = e.selectionStart;
  32. e.caretEnd = e.selectionEnd;
  33.  
  34. // switch it to text, but make it remember it was a password type
  35. e.type = 'text';
  36. e.oldType = 'password';
  37.  
  38. // the selection range gets reset when we switch its type, so let's fix it
  39. e.setSelectionRange(e.caretStart, e.caretEnd);
  40.  
  41. document.title = e.caretStart + 'x' + e.caretEnd;
  42. }
  43. }
  44.  
  45. function toPassword(e) {
  46. e = e.target;
  47.  
  48. if (e.tagName === 'INPUT' && e.oldType === 'password') {
  49. // save the cursor position
  50. e.caretStart = e.selectionStart;
  51. e.caretEnd = e.selectionEnd;
  52.  
  53. // switch it to a password field
  54. e.type = 'password';
  55.  
  56. // the selection range gets reset when we switch its type, so let's fix it
  57. e.setSelectionRange(e.caretStart, e.caretEnd);
  58. e.setSelectionRange(e.caretStart, e.caretEnd);
  59.  
  60. // let's clean up our now-unused properties
  61. delete e.caretStart;
  62. delete e.caretEnd;
  63. delete e.oldType;
  64. }
  65. }
  66.  
  67. function addHandlers() {
  68. var fields = document.querySelectorAll('input[type="password"]'), i, field;
  69.  
  70. for (i = 0; field = fields[i]; i += 1) {
  71. if (handlers.indexOf(field) === -1) {
  72. field.addEventListener('focus', toText, false);
  73. field.addEventListener('blur', toPassword, false);
  74. handlers.push(field);
  75. }
  76. }
  77. }
  78.  
  79. if (show_only_on_click === false) {
  80. window.addEventListener('mouseover', toText, false);
  81. window.addEventListener('mouseout', toPassword, false);
  82. } else {
  83. window.setInterval(addHandlers, 1000);
  84. }
  85.  
  86. }());