-
Notifications
You must be signed in to change notification settings - Fork 1
/
content.js
238 lines (217 loc) · 10.2 KB
/
content.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
var nm1 = ["br","c","cr","dr","g","gh","gr","k","kh","kr","n","q","qh","sc","scr","str","st","t","tr","thr","v","vr","x","z","","","","",""];
var nm2 = ["ae","aa","ai","au","uu","a","e","i","o","u","a","e","i","o","u","a","e","i","o","u","a","e","i","o","u","a","e","i","o","u","a","e","i","o","u"];
var nm3 = ["c","k","n","q","t","v","x","z","c","cc","cr","cz","dr","gr","gn","gm","gv","gz","k","kk","kn","kr","kt","kv","kz","lg","lk","lq","lx","lz","nc","ndr","nkr","ngr","nk","nq","nqr","nz","q","qr","qn","rc","rg","rk","rkr","rq","rqr","sc","sq","str","t","v","vr","x","z","q'","k'","rr","r'","t'","tt","vv","v'","x'","z'","","","","","","","","","","","","","","","","",""];
var nm4 = ["","a","e","i","o","u","a","e","i","o","u","a","e","i","o","u","oi","ie","ai","ei","eo","ui"];
var nm5 = ["d","ds","k","ks","l","ls","n","ns","ts","x"];
var nm6 = ["b","bh","ch","d","dh","f","h","l","m","n","ph","r","s","sh","th","v","y","z","","","","","","","","",""];
var nm7 = ["ae","ai","ee","ei","ie","a","e","i","o","u","a","e","i","o","u","a","e","i","o","u","a","e","i","o","u","a","e","i","o","u","a","e","i","o","u"];
var nm8 = ["c","d","g","h","l","m","n","r","s","v","z","c","ch","d","dd","dh","g","gn","h","hl","hm","hn","hr","l","ld","ldr","lg","lgr","lk","ll","lm","ln","lph","lt","lv","lz","m","mm","mn","mh","mph","n","nd","nn","ng","nk","nph","nz","ph","phr","r","rn","rl","rz","s","ss","sl","sn","st","v","z","s'","l'","n'","m'","f'","h'"];
var nm10 = ["a","e","i","o","u","a","e","i","o","u","oi","ie","ai","ea","ae"];
var nm11 = ["","","","","d","ds","h","l","ll","n","ns","r","rs","s","t","th"];
var nm12 = ["b","bh","br","c","ch","cr","d","dh","dr","f","g","gh","gr","h","k","kh","kr","l","m","n","q","qh","ph","r","s","sc","scr","sh","st","str","t","th","thr","tr","v","vr","y","x","z","","","","","","",""];
var nm13 = ["ae","aa","ai","au","ee","ei","ie","uu","a","e","i","o","u","a","e","i","o","u","a","e","i","o","u","a","e","i","o","u","a","e","i","o","u","a","e","i","o","u"];
var nm14 = ["c","d","g","h","k","l","m","n","q","r","s","t","v","z","c","d","g","h","k","l","m","n","q","r","s","t","v","z","c","cc","ch","cr","cz","d","dd","dh","dr","g","gm","gn","gr","gv","gz","h","hl","hm","hn","hr","k","k'","kk","kn","kr","kt","kv","kz","l","ld","ldr","lg","lgr","lk","ll","lm","ln","lph","lq","lt","lv","lx","lz","m","mh","mm","mn","mph","n","nc","nd","ndr","ng","ngr","nk","nkr","nn","nph","nq","nqr","nz","ph","phr","q","q'","qn","qr","r","r'","rc","rg","rk","rkr","rl","rn","rq","rqr","rr","rz","s","sc","sl","sn","sq","ss","st","str","t","t'","tt","v","v'","vr","vv","x","x'","z","z'","","","","","","","","","","",""];
var nm15 = ["","a","e","i","o","u","a","e","i","o","u","a","e","i","o","u","oi","ie","ai","ea","ae"];
var nm16 = ["d","ds","k","ks","l","ll","ls","n","ns","r","rs","s","t","ts","th","x","","","",""];
console.log("I AM running!!!!")
// make a dictionary that converts the matches into alien words
// eventually we want to do it deterministically, but for now it'll be random
function randomName(){
// returns random name
var n = Math.random() * 3 | 0;
if (n === 0){
rnd = Math.random() * nm1.length | 0;
rnd2 = Math.random() * nm2.length | 0;
rnd3 = Math.random() * nm3.length | 0;
rnd4 = Math.random() * nm4.length | 0;
rnd5 = Math.random() * nm5.length | 0;
while(nm1[rnd] === nm3[rnd3] || nm3[rnd3] === nm5[rnd5]){
rnd3 = Math.random() * nm3.length | 0;
}
if(nm3[rnd3] === ""){
rnd4 = 0;
}
name = nm1[rnd] + nm2[rnd2]+ nm3[rnd3] + nm4[rnd4] + nm5[rnd5];
}
else if (n === 1){
rnd = Math.random() * nm6.length | 0;
rnd2 = Math.random() * nm7.length | 0;
rnd3 = Math.random() * nm8.length | 0;
rnd4 = Math.random() * nm10.length | 0;
rnd5 = Math.random() * nm11.length | 0;
while(nm6[rnd] === nm8[rnd3] || nm8[rnd3] === nm11[rnd5]){
rnd3 = Math.random() * nm8.length | 0;
}
name = nm6[rnd] + nm7[rnd2] + nm8[rnd3] + nm10[rnd4] + nm11[rnd5];
}
else if (n==2){
rnd = Math.random() * nm12.length | 0;
rnd2 = Math.random() * nm13.length | 0;
rnd3 = Math.random() * nm14.length | 0;
rnd4 = Math.random() * nm15.length | 0;
rnd5 = Math.random() * nm16.length | 0;
while(nm12[rnd] === nm14[rnd3] || nm14[rnd3] === nm16[rnd5]){
rnd3 = Math.random() * nm14.length | 0;
}
if(nm14[rnd3] === ""){
rnd4 = 0;
}
name = nm12[rnd] + nm13[rnd2]+ nm14[rnd3] + nm15[rnd4] + nm16[rnd5];
}
else{
console.log("aaaaaahhhhh something went wrong!")
}
const capitalName = name.replace(/^\w/,function(c){
return c.toUpperCase();
});
return capitalName;
}
var charToNum = {'a':23,'b':5,'c':8,'d':11,'e':13,'f':7,'g':10,'h':12,
'i':14,'j':15,'k':17,'l':22,'m':76,'n':9,
'o':16,'p':18,'q':19,'r':26,'s':24,'t':1,'u':2,'v':17,'w':25,'x':26,'y':29,
'z':31,'-':30};
// words i don't want to switch out for alien names
var bannedWords = ['The','It','Had','Then','As','There','Am','And','If','On','Had','Great','Big','Dictator','Revolution','Movement','War','Civil','Coup','World','Duel','Power'];
function wordToNumber(word){
var characters = word.toLowerCase().split('');
// console.log(characters);
var number = 0;
for (const character of characters){
number = number + charToNum[character];
// console.log("number");
// console.log(number);
}
return number;
};
function getAlienName(word){
// returns a deterministic alien name based on name
var nameNumber = wordToNumber(word);
if (nameNumber % 3 === 0){
rnd = nameNumber % nm1.length;// | 0;
rnd2 = nameNumber % nm2.length;// | 0;
rnd3 = nameNumber % nm3.length;// | 0;
rnd4 = nameNumber % nm4.length;// | 0;
rnd5 = nameNumber % nm5.length;// | 0;
if (nm3[rnd3] === ""){
rnd4 = 0;
}
name = nm1[rnd] + nm2[rnd2] + nm3[rnd3] + nm4[rnd4] + nm5[rnd5];
}
else if (nameNumber % 3 === 1){
rnd = (nameNumber+3) % nm6.length;// | 0;
rnd2 = (nameNumber+3) % nm7.length;// | 0;
rnd3 = (nameNumber+3) % nm8.length;// | 0;
rnd4 = (nameNumber+3) % nm10.length;// | 0;
rnd5 = (nameNumber+3) % nm11.length;// | 0;
name = nm6[rnd] + nm7[rnd2] + nm8[rnd3] + nm10[rnd4] + nm11[rnd5];
}
else if (nameNumber % 3 === 2){
rnd = (nameNumber+2) % nm12.length;// | 0;
rnd2 = (nameNumber+13) % nm13.length;// | 0;
rnd3 = (nameNumber+23) % nm14.length;// | 0;
rnd4 = (nameNumber+2) % nm15.length;// | 0;
rnd5 = (nameNumber+12) % nm16.length;// | 0;
if (nm14[rnd3] === ""){
rnd4 = 0;
}
name = nm12[rnd] + nm13[rnd2]+ nm14[rnd3] + nm15[rnd4] + nm16[rnd5];
}
else {
console.log(nameNumber % 3)
// console.log("AAAAAA NOT WORKING!!! NOT WORKING!!!")
}
var capitalName = name.replace(/^\w/,function(c){
return c.toUpperCase();
});
return capitalName;
};
// filters arrays, returns unique array
function onlyUnique(value, index, self) {
return self.indexOf(value) === index;
}
function remove_array_element(array, n){
var index = array.indexOf(n);
if (index > -1) {
// console.log(array)
// console.log(index)
array.splice(index, 1);
}
return array;
}
// still needs some work, make it better...
// make it so that things that are linked also get changed...
function getWordsToReplace(){
var ps = document.getElementsByTagName("p");
var matchesBig = [];
for (var paragraph of ps){
var parContent = paragraph.textContent;
var parInner = paragraph.innerHTML;
var sentenceSplit = parContent.split(".").join("#").split("?").join("#").split("!").join("#").split("#");
var sentencesFirstWordMissing = [];
for (var sentence of sentenceSplit){
allButFirstWord = sentence.split(" ").slice(2).join(" ");
sentencesFirstWordMissing.push(allButFirstWord)
}
var candidates = sentencesFirstWordMissing.join(" ");
var matches = candidates.match(/([A-Z][a-zA-Z-]+)()/g);
matchesBig = matchesBig.concat(matches);
}
matchesBig = matchesBig.filter(function(obj) { return obj });
matchesBig = matchesBig.filter(onlyUnique);
for (var w of bannedWords){
console.log(w);
matchesBig = remove_array_element(matchesBig,w);
}
console.log(matchesBig);
return matchesBig;
}
function alienify(toReplace,alienString){
for (var word of toReplace){
alienString = alienString.replaceAll(word,getAlienName(word));
// alienString = alienString.replaceAll(word.toLowerCase(),getAlienName(word).toLowerCase());
}
return alienString;
}
function replaceWords(){
toReplace = getWordsToReplace();
// replace paragraph
var ps = document.getElementsByTagName("p");
for (var paragraph of ps){
parInner = paragraph.innerHTML;
paragraph.innerHTML = alienify(toReplace,parInner);
}
// replace title
var title = document.getElementById("firstHeading");
titleInner = title.innerHTML;
title.innerHTML = alienify(toReplace,titleInner);
// replace subtitles
var subtitles = document.getElementsByClassName("mw-headline");
for (var subtitle of subtitles){
subtitleInner = subtitle.innerHTML;
subtitle.innerHTML = alienify(toReplace,subtitleInner);
}
// replace summary
var summary = document.getElementsByClassName("summary");
for (var s of summary){
sCont = s.textContent;
s.textContent = alienify(toReplace,sCont);
}
// replace table of contents
toctext = document.getElementsByClassName("toctext");
for (var item of toctext){
itemInner = item.innerHTML;
item.innerHTML = alienify(toReplace,itemInner);
}
// replace fn
var fn = document.getElementsByClassName("fn");
for (var i of fn){
iInner = i.innerHTML;
i.innerHTML = alienify(toReplace,iInner);
}
// // replace welcome!
// var welcome = document.getElementById("mp-welcome");
// welcome.innerHTML = welcome.replace("title=\"Wikipedia\"","title=\"Alien Wikipedia\"");
}
replaceWords();
document.body.style.backgroundColor = "green";
document.getElementById("firstHeading").style.backgroundColor = "yellow";