-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
52 lines (45 loc) · 1.24 KB
/
main.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
// Note: some code in this file has been borrowed from
//Replaces all the text in the webpage
function replaceText(fromString, toString){
getTextNodes().forEach(function(node){
//Converts to lowercase
node.nodeValue = node.nodeValue.replace(new RegExp(fromString.toLowerCase(), 'g'), toString.toLowerCase());
});
//Gets a list of words
function getTextNodes(){
var listOfNodes = [];
(function scan(node){
if(node.nodeType == Node.TEXT_NODE) {
listOfNodes.push(node);
} else if(node.childNodes.length)
for(var i = 0; i < node.childNodes.length; i++) {
scan(node.childNodes[i]);
}
}
)(document);
return listOfNodes;
}
}
//Selects a random languages
//Changes the language
//Timesout after 5 seconds
setTimeout(function () {
var rndNum = Math.floor((Math.random() * 4) + 1);
if (rndNum == 1) {
for (let key in dutch) {
replaceText(dutch[key], key);
}
} else if (rndNum == 2) {
for (let key in greek) {
replaceText(greek[key], key);
}
} else if (rndNum == 3) {
for (let key in japanese) {
replaceText(japanese[key], key);
}
} else {
for (let key in arabic) {
replaceText(arabic[key], key);
}
}
}, 5000);