Added engine setting for SimplyTranslate #63

This commit is contained in:
ManeraKai 2022-02-26 01:58:35 +03:00
parent a5415d34bc
commit e6fe9fb1cb
No known key found for this signature in database
GPG Key ID: 5ABC31FFD562E337
4 changed files with 35 additions and 9 deletions

View File

@ -176,6 +176,14 @@ function setTo(val) {
console.log("to: ", to)
}
let simplyTranslateEngine;
const getSimplyTranslateEngine = () => simplyTranslateEngine;
function setSimplyTranslateEngine(val) {
simplyTranslateEngine = val;
browser.storage.local.set({ simplyTranslateEngine: val })
console.log("simplyTranslateEngine: ", val)
}
function isTranslate(url, initiator) {
if (disable) return false;
return targets.includes(url.host)
@ -201,6 +209,7 @@ function redirect(url) {
else {
if (from != "DEFAULT") url.searchParams.append("sl", from);
if (to != "DEFAULT") url.searchParams.append("tl", to);
if (simplyTranslateEngine != "DEFAULT") url.searchParams.append("engine", simplyTranslateEngine);
return `${randomInstance}/${url.search}`
}
@ -283,6 +292,7 @@ async function init() {
"translateFrom",
"translateTo",
"simplyTranslateEngine",
],
(result) => {
disable = result.translateDisable ?? false;
@ -291,6 +301,7 @@ async function init() {
from = result.translateFrom ?? "DEFAULT";
to = result.translateTo ?? 'DEFAULT';
simplyTranslateEngine = result.simplyTranslateEngine ?? 'DEFAULT';
redirects.simplyTranslate = dataJson.simplyTranslate;
redirects.lingva = dataJson.lingva;
@ -336,6 +347,9 @@ export default {
getTo,
setTo,
getSimplyTranslateEngine,
setSimplyTranslateEngine,
getSimplyTranslateNormalRedirectsChecks,
setSimplyTranslateNormalRedirectsChecks,
getSimplyTranslateTorRedirectsChecks,

View File

@ -32,9 +32,9 @@ document.querySelector("#update-instances").addEventListener("click", () => {
document.querySelector("#update-instances").innerHTML = 'Failed Miserabely';
});
document.querySelector("#export-settings").addEventListener("click", () => {
browser.storage.local.get(null, result => console.log(result))
});
// document.querySelector("#export-settings").addEventListener("click", () => {
// browser.storage.local.get(null, result => console.log(result))
// });
let nameCustomInstanceInput = document.getElementById("exceptions-custom-instance");
let instanceTypeElement = document.getElementById("exceptions-custom-instance-type");

View File

@ -134,7 +134,7 @@
<hr>
<div id="simplyTranslate-lingva">
<div id="simplyTranslate">
<div class="some-block option-block">
<h4>From</h4>
<select id="from">
@ -364,9 +364,18 @@
<option value="zu">Zulu</option>
</select>
</div>
</div>
<div id="simplyTranslate">
<div class="some-block option-block">
<h4>Engine</h4>
<select id="simplyTranslate-engine">
<option value="DEFAULT">Default</option>
<option value="google">Google</option>
<option value="libre">Libre</option>
<option value="deepl">Deepl</option>
<option value="iciba">ICIBA</option>
<option value="reverso">Reverso</option>
</select>
</div>
<div id="simplyTranslate-normal">
<div class="some-block option-block">
<h4>Default Instances</h4>

View File

@ -6,19 +6,16 @@ disableElement.addEventListener("change",
(event) => translateHelper.setDisable(!event.target.checked)
);
let simplyTranslateLingvaDivElement = document.getElementById("simplyTranslate-lingva")
let simplyTranslateDivElement = document.getElementById("simplyTranslate")
let lingvaDivElement = document.getElementById("lingva")
function changeFrontendsSettings(frontend) {
if (frontend == 'simplyTranslate') {
simplyTranslateLingvaDivElement.style.display = 'block';
simplyTranslateDivElement.style.display = 'block';
lingvaDivElement.style.display = 'none';
}
else if (frontend == 'lingva') {
simplyTranslateLingvaDivElement.style.display = 'block';
simplyTranslateDivElement.style.display = 'none';
lingvaDivElement.style.display = 'block';
}
@ -71,6 +68,11 @@ toElement.addEventListener("change",
event => translateHelper.setTo(event.target.options[toElement.selectedIndex].value)
);
let simplyTranslateEngineElement = document.getElementById("simplyTranslate-engine");
simplyTranslateEngineElement.addEventListener("change",
event => translateHelper.setSimplyTranslateEngine(event.target.options[simplyTranslateEngineElement.selectedIndex].value)
);
translateHelper.init().then(() => {
disableElement.checked = !translateHelper.getDisable();
@ -84,6 +86,7 @@ translateHelper.init().then(() => {
fromElement.value = translateHelper.getFrom();
toElement.value = translateHelper.getTo();
simplyTranslateEngineElement.value = translateHelper.getSimplyTranslateEngine();
commonHelper.processDefaultCustomInstances(
'simplyTranslate',