-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfindTextarea.js
30 lines (24 loc) · 931 Bytes
/
findTextarea.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// finds and sets textareas to use monospaced font
var monospaceTextareas = function() {
var textareas = document.getElementsByTagName("textarea");
for (i = 0; i < textareas.length; i++) {
textareas[i].style.fontFamily = "monospace";
}
}
// sets MutationObserver to look for dynamic textareas in the body of html
var setMutationObserver = function() {
// select the target node for mutation observer
var target = document.body;
// create an observer instance
var observer = new MutationObserver(function(mutations) {
monospaceTextareas();
});
// configuration of the observer:
var config = { attributes: true, childList: true, subtree: true, characterData: true };
// pass in the target node, as well as the observer options
observer.observe(target, config);
}
// set textareas to be monospaced on page load
// and then set the mutation observer
monospaceTextareas();
setMutationObserver();