Password Length Indicator

Indicate password fields that have a maximum length of characters.

Tendrás que instalar una extensión para tu navegador como Tampermonkey, Greasemonkey o Violentmonkey si quieres utilizar este script.

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

Necesitarás instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Userscripts para instalar este script.

Necesitará instalar una extensión como Tampermonkey para instalar este script.

Necesitarás instalar una extensión para administrar scripts de usuario si quieres instalar este script.

(Ya tengo un administrador de scripts de usuario, déjame instalarlo)

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

(Ya tengo un administrador de estilos de usuario, déjame instalarlo)

// ==UserScript==
// @name         Password Length Indicator
// @namespace    trockenasche
// @version      3.1
// @description  Indicate password fields that have a maximum length of characters.
// @author       trockenasche
// @homepage     https://github.com/trockenasche/US-Password-Length-Indicator
// @supportURL   https://github.com/trockenasche/US-Password-Length-Indicator/issues
// @include      *
// @icon         https://upload.wikimedia.org/wikipedia/commons/thumb/0/0a/Three_asterisks.svg/32px-Three_asterisks.svg.png
// @grant        none
// @run-at       document-idle
// @license      MIT
// ==/UserScript==

function addGlobalStyle(css) {
    var head, style;
    head = document.getElementsByTagName('head')[0];
    if (!head) {
        return;
    }
    style = document.createElement('style');
    style.innerHTML = css;
    head.appendChild(style);
}

function removeMaxLength() {
    var passFields = document.querySelectorAll("input[type='password']");
    [].forEach.call(passFields, function (passField) {
        passField.removeAttribute("maxLength");
        passField.style.border = "0px";
    })
    var divs = document.querySelectorAll("div.us-pli-div");
    [].forEach.call(divs, function (div) {
        div.remove();
    });
}

(function () {
    'use strict';
    var passFields = document.querySelectorAll("input[type='password']");

    if (passFields.length == 0) {
        // Couldn't find any password fields, leaving function.
        return;
    }

    addGlobalStyle(`div.us-pli {
                    position: relative;
                    display: flex;
                    flex-direction: row;
                    width: 100%;
                    align-content: flex-end;
                    }`);
    addGlobalStyle(`div.us-pli>div {
                    padding: 0px 1px;
                    background: coral;
                    border: 1px solid coral;
                    justify-content: center;
                    display: flex;
                    border-radius: 0px 5px 5px 0px;
                    }`);
    addGlobalStyle(`a.us-pli-button {
                    color: white;
                    font-family: Verdana, Arial, Helvetica, sans-serif;
                    font-size: 0.9em;
                    text-decoration: none;
                    align-self: center;
                    }`);
    addGlobalStyle(`a.us-pli-button:hover {
                    color: red;
                    text-decoration: line-through;
                    }`);

    [].forEach.call(passFields, function (passField) {
        if (passField.maxLength > 0) {
            passField.style.border = "2px solid coral";

            // Add the div before the input field.
            var wrapper = document.createElement('div');
            wrapper.classList.add('us-pli');
            passField.parentNode.insertBefore(wrapper, passField);
            // And move the input field inside the div element.
            wrapper.appendChild(passField);

            // Add the div element with the maxLength value at the end of the input element.
            passField.insertAdjacentHTML('afterend', '<div class="us-pli-div"><a href="javascript:void\(0\)" class="us-pli-button" title="remove limit!"> ' + passField.maxLength + '</a></div>');
        }
    });

    var usPliButtons = document.querySelectorAll("a.us-pli-button");
    if (usPliButtons.length > 0) {
        [].forEach.call(usPliButtons, function (usPliButton) {
            usPliButton.addEventListener("click", removeMaxLength);
        });
    }

    return;
})

();