-
Notifications
You must be signed in to change notification settings - Fork 0
/
now-to-meow.js
35 lines (32 loc) · 1.02 KB
/
now-to-meow.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
31
32
33
34
35
var forms = document.getElementsByTagName('form');
for (var i = 0; i < forms.length; i++) {
var old_submit = forms[i].onsubmit;
var new_submit = (function(f, os) {
return function(event) {
try {
replaceNows(f);
} catch(error) {
if (window.console) console.log(error);
}
if (os) return os.call(f);
};
})(forms[i], old_submit);
forms[i].onsubmit = new_submit;
}
function replaceNows(par_elt) {
if (!par_elt || !par_elt.hasOwnProperty('children')) return;
for (var j = 0; j < par_elt.children.length; j++) {
var curr_elt = par_elt.children[j];
if (curr_elt.hasOwnProperty('tagName') &&
((curr_elt.tagName == "INPUT" && curr_elt.type.match(/text/i) != null) || curr_elt.tagName == "TEXTAREA")) {
var newstr = curr_elt.value.replace(/ now/g, " meow").replace(/ Now/g, " Meow");
if (newstr.substring(0,4) == "now " || newstr.substring(0,4) == "Now ") {
newstr = "Meow " + newstr.slice(3);
}
curr_elt.value = newstr;
}
if (curr_elt.children.length > 0) {
replaceNows(curr_elt);
}
}
}