pietro.giucastro / Show passwords in asterisks (*) pressing ALT key

// ==UserScript==
// @name         Show passwords in asterisks (*) pressing ALT key
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  This script lets you see the passwords hidden by asterisks. It's useful if you don't remember the passwords autocompleted by your browser, or if you want to be sure you typed it correctly.
// @author       pietrogiucastro@alice.it
// @match        https://*
// @match        http://*
// @match        https://*/*
// @match        http://*/*
// ==/UserScript==

var keycode = 18;
var classname = 'tms-showpass';

(function() {
    'use strict';

    var css = '.tms-showpass { background: rgba(255, 184, 25, 0.7) !important; border: 1px solid orange !important; }',
        head = document.head || document.getElementsByTagName('head')[0],
        style = document.createElement('style');

    style.type = 'text/css';
    if (style.styleSheet){
        style.styleSheet.cssText = css;
    } else {
        style.appendChild(document.createTextNode(css));
    }

    head.appendChild(style);


    var keypressed = false;

    onkeydown = function(e) {
        e = e || event; // to deal with IE
        if (e.keyCode == 18) {
            keypressed = true;
            var els = document.querySelectorAll( ":hover" );
            var el = els[els.length -1];
            checkThenShow(el);
        }
    }, onkeyup = function(e) {
        e = e || event; // IE??
        if (e.keyCode == 18) {
            keypressed = false;
            initPassInputs();
        }
    }, onmousemove = function(e) {
        checkThenShow(e.target);
    };

    function initPassInputs() {
        var inputs = document.getElementsByClassName(classname);
        if (!inputs.length) return;

        for (var i = 0; i<inputs.length; i++) {
            var el = inputs[i];
            el.type = 'password';
            el.classList.remove(classname);
        }
    }

    function checkThenShow(el) {
        if (!keypressed) return;
        if (el instanceof HTMLInputElement && el.type == 'password') { // input password target
            el.className += ' ' + classname;
            el.type = 'text';
        }
    }

})();