Skip to content

Instantly share code, notes, and snippets.

@gray
Last active February 9, 2021 10:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gray/4050798 to your computer and use it in GitHub Desktop.
Save gray/4050798 to your computer and use it in GitHub Desktop.
Autcomplete On - Greasemonkey extension
// ==UserScript==
// @name Autocomplete On
// @namespace http://gist.github.com/gray
// @description Undo the disabling of autocomplete on forms and inputs.
// @include *
// ==/UserScript==
// Note: other solutions on userscripts.org don't properly handle dynamically
// inserted widgets. This solution uses the new MutationObserver DOM API.
function fixAutocomplete (elem) {
var tags = ['form', 'input'];
for (var i = tags.length - 1; i >= 0; i--) {
var elems = elem.getElementsByTagName(tags[i]);
if (! elems) next;
for (var j = elems.length - 1; j >= 0; j--) {
var attr = elems[j].autocomplete;
if (attr && 'off' == attr) {
elems[j].removeAttribute('autocomplete');
}
}
}
}
fixAutocomplete(document);
var observer = new MutationObserver(function(mutations) {
mutations.forEach( function (mutation) {
fixAutocomplete(mutation.target);
});
});
observer.observe(document, {
subtree: true,
childList: true,
attributes: true,
attributeFilter: ['autocomplete']
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment