Add message that plugin doesn't work in user region.
This commit is contained in:
AlexeyMatveev686
2023-12-08 15:21:12 +03:00
parent 711a3724e1
commit e6352a04b3
8 changed files with 206 additions and 200 deletions

View File

@ -17,215 +17,214 @@
*/
(function(window, undefined){
try {
var isInit = false;
var ifr;
const isIE = checkInternetExplorer(); //check IE
var message = "This plugin doesn't work in Internet Explorer."
var txt;
var paste_done = true;
var translated = '';
window.Asc.plugin.init = function(text)
{
if (isIE) {
document.getElementById("iframe_parent").innerHTML = "<h4 id='h4' style='margin:5px'>" + message + "</h4>";
return;
}
if (window.Asc.plugin.info.editorType === 'word') {
window.Asc.plugin.executeMethod("GetSelectedText", [{Numbering:false}], function(data) {
txt = (!data) ? "" : ProcessText(data);
ExecPlugin();
});
} else {
txt = ProcessText(text);
var isInit = false;
var ifr;
const isIE = checkInternetExplorer(); //check IE
var txt;
var paste_done = true;
var translated = '';
window.Asc.plugin.init = function(text)
{
if (isIE) {
showMessage("This plugin doesn't work in Internet Explorer.");
return;
}
if (window.Asc.plugin.info.editorType === 'word') {
window.Asc.plugin.executeMethod("GetSelectedText", [{Numbering:false}], function(data) {
txt = (!data) ? "" : ProcessText(data);
ExecPlugin();
}
};
});
} else {
txt = ProcessText(text);
ExecPlugin();
}
};
function ExecPlugin() {
if (!isInit) {
document.getElementById("iframe_parent").innerHTML = "";
ifr = document.createElement("iframe");
ifr.position = "fixed";
ifr.name = "google_name";
ifr.id = "google_id";
ifr.src = "./index_widget.html";//?text=" + encodeURIComponent(text);
ifr.style.top = "0px";
ifr.style.left = "0px";
ifr.style.width = "100%";
ifr.style.height = "100%";
ifr.setAttribute("frameBorder", "0");
document.getElementById("iframe_parent").appendChild(ifr);
isInit = true;
ifr.onload = function() {
if (ifr.contentWindow.document.readyState == 'complete')
window.Asc.plugin.onThemeChanged(Asc.plugin.theme);
setTimeout(function() {
ifr.contentDocument.getElementById("google_translate_element").innerHTML = escape(txt);
function ExecPlugin() {
if (!isInit) {
document.getElementById("iframe_parent").innerHTML = "";
ifr = document.createElement("iframe");
ifr.position = "fixed";
ifr.name = "google_name";
ifr.id = "google_id";
ifr.src = "./index_widget.html";//?text=" + encodeURIComponent(text);
ifr.style.top = "0px";
ifr.style.left = "0px";
ifr.style.width = "100%";
ifr.style.height = "100%";
ifr.setAttribute("frameBorder", "0");
document.getElementById("iframe_parent").appendChild(ifr);
isInit = true;
ifr.onload = function() {
if (ifr.contentWindow.document.readyState == 'complete')
window.Asc.plugin.onThemeChanged(Asc.plugin.theme);
setTimeout(function() {
let element = ifr.contentDocument.getElementById("google_translate_element");
if (element) {
element.innerHTML = escape(txt);
if (txt.length)
ifr.contentDocument.getElementById("div_btn").classList.remove("hidden");
}, 500);
var selectElement = ifr.contentDocument.getElementsByClassName('goog-te-combo')[0];
if (selectElement) {
console.log('success_1');
} else {
console.log('fail_1')
return;
}
selectElement.addEventListener('change', function(event) {
if (txt || ifr.contentDocument.getElementById("google_translate_element").innerHTML) {
ifr.contentWindow.postMessage("onchange_goog-te-combo", '*');
ifr.contentDocument.getElementById("google_translate_element").style.opacity = 0;
}
});
ifr.contentDocument.getElementById("google_translate_element").style.height = "fit-content";
var btn = ifr.contentDocument.createElement("button");
var btnReplace = ifr.contentDocument.createElement("button");
var div = ifr.contentDocument.createElement("div");
var select = ifr.contentDocument.createElement("select");
select.id = "select_lang";
select.classList.add("select-lang");
select.classList.add("goog-te-combo");
div.appendChild(btn);
if (!window.Asc.plugin.info.isViewMode)
div.appendChild(btnReplace);
div.id = "div_btn";
div.classList.add("skiptranslate");
div.classList.add("div_btn");
div.classList.add("hidden");
btn.innerHTML = window.Asc.plugin.tr("Copy");
btn.id = "btn_copy";
btn.classList.add("btn-text-default");
btnReplace.classList.add("btn-text-default");
btnReplace.innerHTML = window.Asc.plugin.tr("Insert");
btnReplace.id = "btn_replace";
setTimeout(function() {
ifr.contentDocument.getElementById("body").appendChild(div);
ifr.contentDocument.getElementById(":0.targetLanguage").appendChild(select);
}, 100);
}, 500);
setTimeout(function() {
btnReplace.onclick = function () {
if (!paste_done)
return;
else
paste_done = false;
var selectElement = ifr.contentDocument.getElementsByClassName('goog-te-combo')[0];
if (!selectElement) {
// in this case plugin won't work (it can be problem with region)
showMessage(window.Asc.plugin.tr("This plugin doesn't work in your region."));
return;
}
selectElement.addEventListener('change', function(event) {
if (txt || ifr.contentDocument.getElementById("google_translate_element").innerHTML) {
ifr.contentWindow.postMessage("onchange_goog-te-combo", '*');
ifr.contentDocument.getElementById("google_translate_element").style.opacity = 0;
}
});
ifr.contentDocument.getElementById("google_translate_element").style.height = "fit-content";
var btn = ifr.contentDocument.createElement("button");
var btnReplace = ifr.contentDocument.createElement("button");
var div = ifr.contentDocument.createElement("div");
var select = ifr.contentDocument.createElement("select");
select.id = "select_lang";
select.classList.add("select-lang");
select.classList.add("goog-te-combo");
div.appendChild(btn);
if (!window.Asc.plugin.info.isViewMode)
div.appendChild(btnReplace);
div.id = "div_btn";
div.classList.add("skiptranslate");
div.classList.add("div_btn");
div.classList.add("hidden");
btn.innerHTML = window.Asc.plugin.tr("Copy");
btn.id = "btn_copy";
btn.classList.add("btn-text-default");
btnReplace.classList.add("btn-text-default");
btnReplace.innerHTML = window.Asc.plugin.tr("Insert");
btnReplace.id = "btn_replace";
setTimeout(function() {
ifr.contentDocument.getElementById("body").appendChild(div);
ifr.contentDocument.getElementById(":0.targetLanguage").appendChild(select);
}, 100);
var translatedTxt = ifr.contentDocument.getElementById("google_translate_element").outerText;
var allParasTxt = translatedTxt.split(/\n/);
var allParsedParas = [];
setTimeout(function() {
btnReplace.onclick = function () {
if (!paste_done)
return;
else
paste_done = false;
for (var nStr = 0; nStr < allParasTxt.length; nStr++) {
if (allParasTxt[nStr].search(/ /) === 0) {
allParsedParas.push("");
allParasTxt[nStr] = allParasTxt[nStr].replace(/ /, "");
}
var sSplited = allParasTxt[nStr].split(/ /);
var translatedTxt = ifr.contentDocument.getElementById("google_translate_element").outerText;
var allParasTxt = translatedTxt.split(/\n/);
var allParsedParas = [];
sSplited.forEach(function(item, i, sSplited) {
allParsedParas.push(item);
});
for (var nStr = 0; nStr < allParasTxt.length; nStr++) {
if (allParasTxt[nStr].search(/ /) === 0) {
allParsedParas.push("");
allParasTxt[nStr] = allParasTxt[nStr].replace(/ /, "");
}
Asc.scope.arr = allParsedParas;
window.Asc.plugin.executeMethod("GetVersion", [], function(version) {
if (version === undefined) {
window.Asc.plugin.executeMethod("PasteText", [ifr.contentDocument.getElementById("google_translate_element").outerText], function(result) {
paste_done = true;
});
}
else {
window.Asc.plugin.executeMethod("GetSelectionType", [], function(sType) {
switch (sType) {
case "none":
case "drawing":
window.Asc.plugin.executeMethod("PasteText", [ifr.contentDocument.getElementById("google_translate_element").outerText], function(result) {
paste_done = true;
});
break;
case "text":
window.Asc.plugin.callCommand(function() {
Api.ReplaceTextSmart(Asc.scope.arr);
}, undefined, undefined, function(result) {
paste_done = true;
});
break;
}
});
}
var sSplited = allParasTxt[nStr].split(/ /);
sSplited.forEach(function(item, i, sSplited) {
allParsedParas.push(item);
});
}
});
ifr.contentWindow.postMessage("update_scroll", '*');
ifr.contentWindow.postMessage({type: 'translate', text: translated}, '*')
}
} else {
ifr.contentWindow.postMessage(txt, '*');
ifr.contentDocument.getElementById("google_translate_element").style.opacity = 0;
Asc.scope.arr = allParsedParas;
window.Asc.plugin.executeMethod("GetVersion", [], function(version) {
if (version === undefined) {
window.Asc.plugin.executeMethod("PasteText", [ifr.contentDocument.getElementById("google_translate_element").outerText], function(result) {
paste_done = true;
});
}
else {
window.Asc.plugin.executeMethod("GetSelectionType", [], function(sType) {
switch (sType) {
case "none":
case "drawing":
window.Asc.plugin.executeMethod("PasteText", [ifr.contentDocument.getElementById("google_translate_element").outerText], function(result) {
paste_done = true;
});
break;
case "text":
window.Asc.plugin.callCommand(function() {
Api.ReplaceTextSmart(Asc.scope.arr);
}, undefined, undefined, function(result) {
paste_done = true;
});
break;
}
});
}
});
}
});
ifr.contentWindow.postMessage("update_scroll", '*');
ifr.contentWindow.postMessage({type: 'translate', text: translated}, '*')
}
};
function ProcessText(sText) {
return sText.replace(/ /gi, '\n').replace(/ /gi, '\n');
};
} else {
ifr.contentWindow.postMessage(txt, '*');
ifr.contentDocument.getElementById("google_translate_element").style.opacity = 0;
}
};
function ProcessText(sText) {
return sText.replace(/ /gi, '\n').replace(/ /gi, '\n');
};
function checkInternetExplorer(){
var rv = -1;
if (window.navigator.appName == 'Microsoft Internet Explorer') {
const ua = window.navigator.userAgent;
const re = new RegExp('MSIE ([0-9]{1,}[\.0-9]{0,})');
if (re.exec(ua) != null) {
rv = parseFloat(RegExp.$1);
}
} else if (window.navigator.appName == 'Netscape') {
const ua = window.navigator.userAgent;
const re = new RegExp('Trident/.*rv:([0-9]{1,}[\.0-9]{0,})');
if (re.exec(ua) != null) {
rv = parseFloat(RegExp.$1);
}
function checkInternetExplorer(){
var rv = -1;
if (window.navigator.appName == 'Microsoft Internet Explorer') {
const ua = window.navigator.userAgent;
const re = new RegExp('MSIE ([0-9]{1,}[\.0-9]{0,})');
if (re.exec(ua) != null) {
rv = parseFloat(RegExp.$1);
}
return rv !== -1;
};
} else if (window.navigator.appName == 'Netscape') {
const ua = window.navigator.userAgent;
const re = new RegExp('Trident/.*rv:([0-9]{1,}[\.0-9]{0,})');
window.Asc.plugin.button = function(id)
{
this.executeCommand("close", "");
};
window.onresize = function()
{
ifr && ifr.contentWindow.postMessage("update_scroll", '*');
};
window.Asc.plugin.onExternalMouseUp = function()
{
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("mouseup", true, true, window, 1, 0, 0, 0, 0,
false, false, false, false, 0, null);
document.dispatchEvent(evt);
};
window.Asc.plugin.onTranslate = function()
{
if (isIE) {
var field = document.getElementById("h4");
if (field)
field.innerHTML = message = window.Asc.plugin.tr(message);
if (re.exec(ua) != null) {
rv = parseFloat(RegExp.$1);
}
translated = window.Asc.plugin.tr('Select Language');
};
window.Asc.plugin.onThemeChanged = function(theme)
{
window.Asc.plugin.onThemeChangedBase(theme);
var style = document.getElementsByTagName('head')[0].lastChild;
if (ifr && ifr.contentWindow)
setTimeout( function() { ifr.contentWindow.postMessage({type: 'themeChanged', theme: theme, style: style.innerHTML}, '*' ) } ,600 );
};
} catch (error) {
console.log('Some problem')
}
}
return rv !== -1;
};
function showMessage(message) {
document.getElementById("iframe_parent").innerHTML = "<h4 id='h4' style='margin:5px'>" + message + "</h4>";
};
window.Asc.plugin.button = function(id)
{
this.executeCommand("close", "");
};
window.onresize = function()
{
ifr && ifr.contentWindow.postMessage("update_scroll", '*');
};
window.Asc.plugin.onExternalMouseUp = function()
{
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("mouseup", true, true, window, 1, 0, 0, 0, 0,
false, false, false, false, 0, null);
document.dispatchEvent(evt);
};
window.Asc.plugin.onTranslate = function()
{
var field = document.getElementById("h4");
if (field)
field.innerHTML = window.Asc.plugin.tr(field.innerText);
translated = window.Asc.plugin.tr('Select Language');
};
window.Asc.plugin.onThemeChanged = function(theme)
{
window.Asc.plugin.onThemeChangedBase(theme);
var style = document.getElementsByTagName('head')[0].lastChild;
if (ifr && ifr.contentWindow)
setTimeout( function() { ifr.contentWindow.postMessage({type: 'themeChanged', theme: theme, style: style.innerHTML}, '*' ) } ,600 );
};
})(window, undefined);

View File

@ -2,5 +2,6 @@
"Copy" : "Kopie",
"Insert": "Vložit",
"Select Language": "Vyberte jazyk",
"This plugin doesn't work in Internet Explorer." : "Tento plugin nefunguje v aplikaci Internet Explorer."
"This plugin doesn't work in Internet Explorer." : "Tento plugin nefunguje v aplikaci Internet Explorer.",
"This plugin doesn't work in your region." : "Tento plugin nefunguje ve vaší oblasti."
}

View File

@ -2,5 +2,6 @@
"Copy" : "Kopieren",
"Insert": "Einfügen",
"Select Language": "Sprache auswählen",
"This plugin doesn't work in Internet Explorer." : "Dieses plugin funktioniert nicht im Internet Explorer."
"This plugin doesn't work in Internet Explorer." : "Dieses plugin funktioniert nicht im Internet Explorer.",
"This plugin doesn't work in your region." : "Dieses Plugin funktioniert in Ihrer Region nicht."
}

View File

@ -2,5 +2,6 @@
"Copy" : "Copia",
"Insert": "Insertar",
"Select Language": "Seleccione Idioma",
"This plugin doesn't work in Internet Explorer." : "Este complemento no funciona en Internet Explorer."
"This plugin doesn't work in Internet Explorer." : "Este complemento no funciona en Internet Explorer.",
"This plugin doesn't work in your region." : "Este complemento no funciona en su región."
}

View File

@ -2,5 +2,6 @@
"Copy" : "Copie",
"Insert": "Insérer",
"Select Language": "Sélectionnez La Langue",
"This plugin doesn't work in Internet Explorer." : "Ce plugin ne fonctionne pas dans Internet Explorer."
"This plugin doesn't work in Internet Explorer." : "Ce plugin ne fonctionne pas dans Internet Explorer.",
"This plugin doesn't work in your region." : "Ce plugin ne fonctionne pas dans votre région."
}

View File

@ -2,5 +2,6 @@
"Copy" : "コピー",
"Insert": "貼り付け",
"Select Language": "言語を選択する",
"This plugin doesn't work in Internet Explorer." : "このプラグインは、Internet Explorerでは動作しません。"
"This plugin doesn't work in Internet Explorer." : "このプラグインは、Internet Explorerでは動作しません。",
"This plugin doesn't work in your region." : "このプラグインは、お住まいの地域では動作しません。"
}

View File

@ -2,5 +2,6 @@
"Copy" : "Копировать",
"Insert": "Вставить",
"Select Language": "Выберите язык",
"This plugin doesn't work in Internet Explorer." : "Этот плагин не работает в Internet Explorer."
"This plugin doesn't work in Internet Explorer." : "Этот плагин не работает в Internet Explorer.",
"This plugin doesn't work in your region." : "Этот плагин не работает в вашем регионе."
}

View File

@ -2,5 +2,6 @@
"Copy" : "复制",
"Insert": "插入",
"Select Language": "选择语言",
"This plugin doesn't work in Internet Explorer." : "此插件无法在 Internet Explorer 中工作。"
"This plugin doesn't work in Internet Explorer." : "此插件无法在 Internet Explorer 中工作。",
"This plugin doesn't work in your region." : "此插件在您所在的地区不起作用。"
}