-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththere.js
65 lines (59 loc) · 1.66 KB
/
there.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
var theres = ['there', 'their', 'they\'re', 'theyre']
var Theres = ['There', 'Their', 'They\'re', 'Theyre']
var correctLowerTheres = ['there', 'their', 'they\'re']
var correctUpperTheres = ['There', 'Their', 'They\'re']
function isLowerThere(string) {
for (var i = 0; i < theres.length; i++) {
if (string === theres[i]) {
return true;
}
}
return false
}
function isUpperThere(string) {
for (var i = 0; i < Theres.length; i++) {
if (string === Theres[i]) {
return true;
}
}
return false
}
function randomLowerThere(string) {
var there = string;
while (there === string) {
there = correctLowerTheres[Math.floor(Math.random() * correctLowerTheres.length)];
}
return there
}
function randomUpperThere(string) {
var there = string;
while (there === string) {
there = correctUpperTheres[Math.floor(Math.random() * correctUpperTheres.length)];
}
return there
}
function replaceThere(string) {
var tokens = string.split(" ");
var newstring = []
for (var i = 0; i < tokens.length; i++) {
var next = tokens[i]
if (isLowerThere(next)) {
var newthere = randomLowerThere(next);
next = newthere
}
else if (isUpperThere(next)) {
var newthere = randomUpperThere(next);
next = newthere
}
newstring[newstring.length] = next
}
return newstring.join(" ")
}
$("tt,i,b,big,small,em,strong,kbd,var,cite,abbr,acronym,sub,sup,span,bdo,address,a,p,h1,h2,h3,h4,h5,h6,pre,q,ins,del,dt,dd,li,label,option,button,caption,td,th,div,code").each(function() {
var contents = $(this).contents();
if (contents.length > 0) {
if (contents.get(0).nodeType == Node.TEXT_NODE) {
$(this).html(replaceThere($(this).html()))
}
}
});