forked from dj1yfk/lcwo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbabel.js
87 lines (73 loc) · 2.12 KB
/
babel.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
<script>
function babel(name, content) {
var be = document.getElementById('babeledit');
var bn = document.getElementById('babelname');
var bi = document.getElementById('babelinput');
be.style.visibility = 'visible';
bn.innerHTML = name;
bi.value = content;
bi.focus();
}
function babeltx (k,v) {
var encodedv = '';
var lang = 0;
var inpage;
if (k.indexOf("-") == -1) { /* no - so it's from inpage translate */
k = k.substr(6); /* remove babel_ prefix */
inpage = true;
}
else { /* normal babelfish, format NAME-LANG */
var tmp = k.split("-");
lang = tmp[1];
k = tmp[0];
inpage = false;
}
/* utf8 - not needed anymore
for (i=0;i<v.length;i++) {
c = v.charCodeAt(i);
if (!c) continue;
if (c > 122) {
encodedv += '&#' + c + ';';
}
else {
encodedv += v.charAt(i);
}
}
*/
encodedv = v;
if( typeof XMLHttpRequest == "undefined" ) XMLHttpRequest = function() {
try { return new ActiveXObject("Msxml2.XMLHTTP.6.0") } catch(e) {}
try { return new ActiveXObject("Msxml2.XMLHTTP.3.0") } catch(e) {}
try { return new ActiveXObject("Msxml2.XMLHTTP") } catch(e) {}
try { return new ActiveXObject("Microsoft.XMLHTTP") } catch(e) {}
throw new Error( "This browser does not support XMLHttpRequest." )
};
var posturl = "/babelfish.php";
if (inpage) {
var babel_response = document.getElementById('babelresponse');
}
else {
var babel_response = document.getElementById('babelresponse-'+k+'-'+lang);
}
var request = new XMLHttpRequest();
request.open("POST", posturl, true);
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
request.onreadystatechange = function() {
var done = 4, ok = 200;
if (request.readyState == done && request.status == ok) {
if (request.responseText) {
babel_response.innerHTML = request.responseText;
/* changes on the website */
var edited = document.getElementsByName('babel_'+k);
for (var x=0; x < edited.length; x++) {
edited[x].innerHTML = encodedv;
}
}
else {
babel_response.innerHTML = "<b>ERROR: fail.</b>";
}
}
};
request.send('ajax=1&l='+lang+'&k='+k+'&v='+encodeURIComponent(encodedv));
}
</script>