Skip to content

Commit

Permalink
Added engine setting for SimplyTranslate #63
Browse files Browse the repository at this point in the history
  • Loading branch information
ManeraKai committed Feb 25, 2022
1 parent a5415d3 commit e6fe9fb
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
14 changes: 14 additions & 0 deletions src/assets/javascripts/helpers/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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}`
}

Expand Down Expand Up @@ -283,6 +292,7 @@ async function init() {

"translateFrom",
"translateTo",
"simplyTranslateEngine",
],
(result) => {
disable = result.translateDisable ?? false;
Expand All @@ -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;
Expand Down Expand Up @@ -336,6 +347,9 @@ export default {
getTo,
setTo,

getSimplyTranslateEngine,
setSimplyTranslateEngine,

getSimplyTranslateNormalRedirectsChecks,
setSimplyTranslateNormalRedirectsChecks,
getSimplyTranslateTorRedirectsChecks,
Expand Down
6 changes: 3 additions & 3 deletions src/pages/options/general/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
15 changes: 12 additions & 3 deletions src/pages/options/translate/translate.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ <h4>Protocol</h4>

<hr>

<div id="simplyTranslate-lingva">
<div id="simplyTranslate">
<div class="some-block option-block">
<h4>From</h4>
<select id="from">
Expand Down Expand Up @@ -364,9 +364,18 @@ <h4>To</h4>
<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>
Expand Down
9 changes: 6 additions & 3 deletions src/pages/options/translate/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down Expand Up @@ -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();

Expand All @@ -84,6 +86,7 @@ translateHelper.init().then(() => {

fromElement.value = translateHelper.getFrom();
toElement.value = translateHelper.getTo();
simplyTranslateEngineElement.value = translateHelper.getSimplyTranslateEngine();

commonHelper.processDefaultCustomInstances(
'simplyTranslate',
Expand Down

0 comments on commit e6fe9fb

Please sign in to comment.