Show/Hide Password

Show/Hide Password when hovering over the input password

Versão de: 27/06/2023. Veja: a última versão.

// ==UserScript==
// @name            Show/Hide Password
// @version         1
// @description     Show/Hide Password when hovering over the input password
// @icon            https://cdn-icons-png.flaticon.com/512/312/312404.png
// @match           *://*/*
// @grant           none
// @license         MIT
// @unwrap
// @namespace https://gf.zukizuki.org/users/821661
// ==/UserScript==

(function () {
    "use strict";

    function showPassword(node) {
        node.type = "text";
    }

    function hidePassword(node) {
        node.type = "password";
    }

    const observer = new MutationObserver((mutations) => {
        mutations.forEach((mutation) => {
            if (mutation.type === "childList" && mutation.addedNodes.length > 0) {
                mutation.addedNodes.forEach((node) => {
                    if (node.tagName === "INPUT" && node.type === "password") {
                        node.addEventListener("mouseover", () => {
                            showPassword(node);
                        });
                        node.addEventListener("focus", () => {
                            showPassword(node);
                        });

                        node.addEventListener("mouseout", () => {
                            hidePassword(node);
                        });
                        node.addEventListener("blur", () => {
                            hidePassword(node);
                        });
                        console.log("Input do tipo password adicionado:", node);
                    }
                });
            }
        });
    });

    observer.observe(document.body, {
        childList: true,
        subtree: true,
    });
})();