Password Input Protector

try to protect your password input!

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Password Input Protector
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  try to protect your password input!
// @author       HeziCyan
// @include      *
// @icon         https://www.google.com/s2/favicons?domain=219.58
// @grant        none
// @license      GPL
// ==/UserScript==

(function() {
    'use strict';

    window.addEventListener('load', function() {
        let inputs = document.getElementsByTagName('input')
        let pass = new Array
        for (let input of inputs) {
            if (input.type === 'password') pass.push(input)
        }

        const callback = function(mutationsList, observer) {
            for (let mutation of mutationsList) {
                if (mutation.type === 'attributes') {
                    let target = mutation.target
                    if (target.type !== 'password') {
                        target.type = 'password'
                        alert('请不要试图修改密码框的 type 属性!')
                    }
                }
            }
        }
        const config = { attributes: true }
        let observer = new MutationObserver(callback)
        for (let ele of pass) observer.observe(ele, config)
    })
})();