Password Revealer

Shows passwords on mouse hover or focus

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name           Password Revealer
// @namespace      http://userscripts.org/users/23652
// @description    Shows passwords on mouse hover or focus
// @include        http://*
// @include        https://*
// @include        file:///*
// @exclude        file:///*/perf.html*
// @copyright      JoeSimmons
// @version        1.0.51
// @license        GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
// ==/UserScript==
(function() {




    var show_only_on_click = false; // only show passwords when you click on the field





    var handlers = [];

    function toText(e) {
        e = e.target;

        if (e.tagName === 'INPUT' && e.type === 'password') {
            // save the cursor position
            e.caretStart = e.selectionStart;
            e.caretEnd = e.selectionEnd;

            // switch it to text, but make it remember it was a password type
            e.type = 'text';
            e.oldType = 'password';

            // the selection range gets reset when we switch its type, so let's fix it
            e.setSelectionRange(e.caretStart, e.caretEnd);
        }
    }

    function toPassword(e) {
        e = e.target;

        if (e.tagName === 'INPUT' && e.oldType === 'password') {
            // save the cursor position
            e.caretStart = e.selectionStart;
            e.caretEnd = e.selectionEnd;

            // switch it to a password field
            e.type = 'password';

            // the selection range gets reset when we switch its type, so let's fix it
            e.setSelectionRange(e.caretStart, e.caretEnd);
            e.setSelectionRange(e.caretStart, e.caretEnd);

            // let's clean up our now-unused properties
            delete e.caretStart;
            delete e.caretEnd;
            delete e.oldType;
        }
    }

    function addHandlers() {
        var fields = document.querySelectorAll('input[type="password"]'), i, field;

        for (i = 0; field = fields[i]; i += 1) {
            if (handlers.indexOf(field) === -1) {
                field.addEventListener('focus', toText, false);
                field.addEventListener('blur', toPassword, false);
                handlers.push(field);
            }
        }
    }

    if (show_only_on_click === false) {
        window.addEventListener('mouseover', toText, false);
        window.addEventListener('mouseout', toPassword, false);
    } else {
        window.setInterval(addHandlers, 1000);
    }

}());