-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfast-translate.js
More file actions
28 lines (28 loc) · 865 Bytes
/
fast-translate.js
File metadata and controls
28 lines (28 loc) · 865 Bytes
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
javascript:
function openSubTranslator(){
var h = 400;
var w = 1280;
function detectRUorENG(str) {
if (!str) {
return '';
} else {
var full = str.split(/\s+/).length;
var eng = str.split(/\W+/);
var fromTo;
if (eng[0] === '') {
eng.shift();
}
if (eng[eng.length-1] === '') {
eng.pop();
}
if (full/2 <= eng.length) {
fromTo = '#en/ru/';
} else {
fromTo = '#ru/en/';
}
return fromTo + encodeURIComponent(str);
};
};
var x = window.open('https://translate.google.ru/' + detectRUorENG(window.getSelection().toString()), 'standalone', 'toolbar=no,location=no,scrollbars=yes,height=' + Math.min(h, screen.availHeight) + ',width=' + screen.availWidth + ',left=' + Math.max(0, (screen.availWidth - w) / 2) + ',top=' + Math.min(screen.availHeight - h - 65, screen.availHeight / 8 * 5));
};
openSubTranslator();