Last active
February 9, 2021 10:46
-
-
Save gray/4050798 to your computer and use it in GitHub Desktop.
Autcomplete On - Greasemonkey extension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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