Skip to content

Instantly share code, notes, and snippets.

@Pierowheelz
Created August 13, 2024 22:26
Show Gist options
  • Save Pierowheelz/a57dccf1ec3f07793a08a9769125353e to your computer and use it in GitHub Desktop.
Save Pierowheelz/a57dccf1ec3f07793a08a9769125353e to your computer and use it in GitHub Desktop.
TamperMonkey script to prevent 'password' field type update
// ==UserScript==
// @name Prevent 'password' field type update
// @namespace http://tampermonkey.net/
// @version 2024-08-13
// @description prevent users or buttons from changing the type of a password field to access the saved password.
// @author Pierowheelz
// @match *://*/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
// @grant none
// ==/UserScript==
(function() {
'use strict';
const passInputs = [];
const findPassInputs = () => {
const foundInputs = document.querySelectorAll("input[type=password]");
foundInputs.forEach( foundInput => {
if( !passInputs.includes(foundInput) ){
console.log("Found password input: ", foundInput);
passInputs.push( foundInput );
}
} );
};
const fixInputs = () => {
passInputs.forEach( passInput => {
if( !passInput ){
return;
}
const inputType = passInput.type ?? 'password';
if( 'password' !== inputType ){
passInput.type = 'password';
console.log("Password input fixed: ", passInput);
}
} );
}
findPassInputs();
setInterval( findPassInputs, 5000 );
setInterval( fixInputs, 500 );
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment