-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
44 lines (41 loc) · 1.34 KB
/
script.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
const isla = [65, 90, 89, 88, 69, 87, 86, 84, 73, 83, 82, 76, 80, 78, 79, 77, 81, 75, 74, 72, 85, 71, 70, 68, 67, 66];
const BIG_A = 65;
const LITTLE_A = 97;
const LENGTH = 26;
function translatecurrent() {
var input = document.getElementById("input").value;
if(input != undefined) {
document.getElementById("output").innerHTML = translate(input);
}
};
window.addEventListener('load', function() {
var result = findGetParameter("translate");
if(result != null) {
document.getElementById("input").value = result;
translatecurrent();
}
});
function findGetParameter(parameter) {
var tmp = [];
var result = null;
location.search.substr(1).split("&").forEach(function (item) {
tmp = item.split("=");
if(tmp.length > 1 && tmp[0] == parameter) result = decodeURIComponent(tmp[1]);
});
return result;
}
function translate(english) {
if(english.length < 1) return "type something to translate";
var builder = "";
for(var i = 0; i < english.length; i++) {
var c = english.charCodeAt(i);
if(c >= BIG_A && c <= BIG_A+LENGTH) {
builder = builder + String.fromCharCode(isla[c-BIG_A]);
} else if(c >= LITTLE_A && c <= LITTLE_A+LENGTH) {
builder = builder + String.fromCharCode(isla[c-LITTLE_A]-BIG_A+LITTLE_A);
} else {
builder = builder + String.fromCharCode(c);
}
}
return builder;
};