Skip to content

Instantly share code, notes, and snippets.

@pjstadig
Last active February 20, 2023 21:05
Show Gist options
  • Save pjstadig/6361fda0885ded9182740a2d0885710a to your computer and use it in GitHub Desktop.
Save pjstadig/6361fda0885ded9182740a2d0885710a to your computer and use it in GitHub Desktop.
Focus MFA: if a page has a single text or password field (usually an MFA page), then focus on it
// ==UserScript==
// @name Focus MFA
// @namespace http://paul.stadig.name/
// @version 0.5
// @description if a page has a single text or password field (usually an MFA page), then focus on it
// @author Paul Stadig
// @match *://*/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=google.com
// @grant none
// ==/UserScript==
(function() {
'use strict';
if (document.querySelectorAll('input').length <= 2) {
if (document.querySelectorAll('input[type="text"]').length == 1) {
document.querySelectorAll('input[type="text"]')[0].focus();
} else if (document.querySelectorAll('input[type="tel"]').length == 1) {
document.querySelectorAll('input[type="tel"]')[0].focus();
} else if (document.querySelectorAll('input[type="password"]').length == 1) {
document.querySelectorAll('input[type="password"]')[0].focus();
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment