Added translate tor support #32

This commit is contained in:
ManeraKai 2022-02-23 19:48:04 +03:00
parent 880d62a2c8
commit ae29c4c70a
No known key found for this signature in database
GPG Key ID: 5ABC31FFD562E337
8 changed files with 300 additions and 111 deletions

View File

@ -100,8 +100,8 @@ let protocol;
const getProtocol = () => protocol;
function setProtocol(val) {
protocol = val;
browser.storage.local.set({ mediumProtocol: val })
console.log("mediumProtocol: ", val)
browser.storage.local.set({ mediumProtocol: val });
console.log("mediumProtocol: ", val);
}
function isMedium(url, initiator) {

View File

@ -9,31 +9,13 @@ const targets = [
let redirects = {
"simplyTranslate": {
"normal": [
"https://simplytranslate.org",
"https://st.alefvanoon.xyz",
"https://translate.josias.dev",
"https://translate.namazso.eu",
"https://translate.riverside.rocks",
"https://manerakai.asuscomm.com:447",
"https://translate.bus-hit.me",
"https://simplytranslate.pussthecat.org",
"https://translate.northboot.xyz"
],
"tor": [
"http://fyng2tsmzmvxmojzbbwmfnsn2lrcyftf4cw6rk5j2v2huliazud3fjid.onion",
"http://xxtbwyb5z5bdvy2f6l2yquu5qilgkjeewno4qfknvb3lkg3nmoklitid.onion"
]
"normal": [],
"tor": []
},
"lingva": {
"normal": [
"https://lingva.ml",
"https://translate.alefvanoon.xyz",
"https://translate.igna.rocks",
"https://lingva.pussthecat.org",
"https://translate.datatunnel.xyz",
]
"normal": [],
"tor": []
}
};
@ -42,10 +24,12 @@ const getRedirects = () => redirects;
const getCustomRedirects = function () {
return {
"simplyTranslate": {
"normal": [...simplyTranslateNormalRedirectsChecks, ...simplyTranslateNormalCustomRedirects]
"normal": [...simplyTranslateNormalRedirectsChecks, ...simplyTranslateNormalCustomRedirects],
"tor": [...simplyTranslateTorRedirectsChecks, ...simplyTranslateTorCustomRedirects]
},
"lingva": {
"normal": [...lingvaNormalRedirectsChecks, ...lingvaNormalCustomRedirects]
"normal": [...lingvaNormalRedirectsChecks, ...lingvaNormalCustomRedirects],
"tor": [...lingvaTorRedirectsChecks, ...lingvaTorCustomRedirects]
}
};
};
@ -60,6 +44,13 @@ function setSimplyTranslateRedirects(val) {
if (index !== -1) simplyTranslateNormalRedirectsChecks.splice(index, 1);
}
setSimplyTranslateNormalRedirectsChecks(simplyTranslateNormalRedirectsChecks);
for (const item of simplyTranslateTorRedirectsChecks)
if (!redirects.simplyTranslate.normal.includes(item)) {
var index = simplyTranslateTorRedirectsChecks.indexOf(item);
if (index !== -1) simplyTranslateTorRedirectsChecks.splice(index, 1);
}
setSimplyTranslateTorRedirectsChecks(simplyTranslateTorRedirectsChecks);
}
let simplyTranslateNormalRedirectsChecks;
@ -70,6 +61,14 @@ function setSimplyTranslateNormalRedirectsChecks(val) {
console.log("simplyTranslateNormalRedirectsChecks: ", val)
}
let simplyTranslateTorRedirectsChecks;
const getSimplyTranslateTorRedirectsChecks = () => simplyTranslateTorRedirectsChecks;
function setSimplyTranslateTorRedirectsChecks(val) {
simplyTranslateTorRedirectsChecks = val;
browser.storage.local.set({ simplyTranslateTorRedirectsChecks })
console.log("simplyTranslateTorRedirectsChecks: ", val)
}
let simplyTranslateNormalCustomRedirects = [];
const getSimplyTranslateNormalCustomRedirects = () => simplyTranslateNormalCustomRedirects;
function setSimplyTranslateNormalCustomRedirects(val) {
@ -78,6 +77,14 @@ function setSimplyTranslateNormalCustomRedirects(val) {
console.log("simplyTranslateNormalCustomRedirects: ", val)
}
let simplyTranslateTorCustomRedirects = [];
const getSimplyTranslateTorCustomRedirects = () => simplyTranslateTorCustomRedirects;
function setSimplyTranslateTorCustomRedirects(val) {
simplyTranslateTorCustomRedirects = val;
browser.storage.local.set({ simplyTranslateTorCustomRedirects })
console.log("simplyTranslateTorCustomRedirects: ", val)
}
function setLingvaRedirects(val) {
redirects.lingva = val;
browser.storage.local.set({ translateRedirects: redirects })
@ -88,6 +95,13 @@ function setLingvaRedirects(val) {
if (index !== -1) lingvaNormalRedirectsChecks.splice(index, 1);
}
setLingvaNormalRedirectsChecks(lingvaNormalRedirectsChecks);
for (const item of lingvaTorRedirectsChecks)
if (!redirects.lingva.normal.includes(item)) {
var index = lingvaTorRedirectsChecks.indexOf(item);
if (index !== -1) lingvaTorRedirectsChecks.splice(index, 1);
}
setLingvaTorRedirectsChecks(lingvaTorRedirectsChecks);
}
let lingvaNormalRedirectsChecks;
@ -98,6 +112,14 @@ function setLingvaNormalRedirectsChecks(val) {
console.log("lingvaNormalRedirectsChecks: ", val)
}
let lingvaTorRedirectsChecks;
const getLingvaTorRedirectsChecks = () => lingvaTorRedirectsChecks;
function setLingvaTorRedirectsChecks(val) {
lingvaTorRedirectsChecks = val;
browser.storage.local.set({ lingvaTorRedirectsChecks })
console.log("lingvaTorRedirectsChecks: ", val)
}
let lingvaNormalCustomRedirects = [];
const getLingvaNormalCustomRedirects = () => lingvaNormalCustomRedirects;
function setLingvaNormalCustomRedirects(val) {
@ -106,6 +128,14 @@ function setLingvaNormalCustomRedirects(val) {
console.log("lingvaNormalCustomRedirects: ", val)
}
let lingvaTorCustomRedirects = [];
const getLingvaTorCustomRedirects = () => lingvaTorCustomRedirects;
function setLingvaTorCustomRedirects(val) {
lingvaTorCustomRedirects = val;
browser.storage.local.set({ lingvaTorCustomRedirects })
console.log("lingvaTorCustomRedirects: ", val)
}
let disable;
const getDisable = () => disable;
function setDisable(val) {
@ -122,6 +152,14 @@ function setFrontend(val) {
console.log("translateFrontend: ", frontend)
}
let protocol;
const getProtocol = () => protocol;
function setProtocol(val) {
protocol = val;
browser.storage.local.set({ translateProtocol: val })
console.log("translateProtocol: ", val)
}
let from;
const getFrom = () => from;
function setFrom(val) {
@ -152,17 +190,26 @@ function redirect(url) {
myMap[pair[0]] = pair[1];
}
if (frontend == 'simplyTranslate') {
let instancesList = [...simplyTranslateNormalRedirectsChecks, ...simplyTranslateNormalCustomRedirects];
let instancesList;
if (protocol == 'normal') instancesList = [...simplyTranslateNormalRedirectsChecks, ...simplyTranslateNormalCustomRedirects];
if (protocol == 'tor') instancesList = [...simplyTranslateTorRedirectsChecks, ...simplyTranslateTorCustomRedirects];
if (instancesList.length === 0) return null;
let randomInstance = commonHelper.getRandomInstance(instancesList)
if (myMap.sl && myMap.tl && myMap.text)
return `${randomInstance}/${url.search}`;
else
return `${randomInstance}/?sl=${from}&tl=${to}`
else {
if (from != "DEFAULT") url.searchParams.append("sl", from);
if (to != "DEFAULT") url.searchParams.append("tl", to);
return `${randomInstance}/${url.search}`
}
}
else if (frontend == 'lingva') {
let instancesList = [...lingvaNormalRedirectsChecks, ...lingvaNormalCustomRedirects];
let instancesList;
if (protocol == 'normal') instancesList = [...lingvaNormalRedirectsChecks, ...lingvaNormalCustomRedirects];
if (protocol == 'tor') instancesList = [...lingvaTorRedirectsChecks, ...lingvaTorCustomRedirects];
if (instancesList.length === 0) return null;
let randomInstance = commonHelper.getRandomInstance(instancesList)
@ -175,37 +222,56 @@ function redirect(url) {
async function init() {
return new Promise((resolve) => {
browser.storage.local.get(
[
"translateDisable",
"translateFrontend",
"translateRedirects",
"simplyTranslateNormalRedirectsChecks",
"simplyTranslateNormalCustomRedirects",
"lingvaNormalRedirectsChecks",
"lingvaNormalCustomRedirects",
"translateFrom",
"translateTo",
],
(result) => {
disable = result.translateDisable ?? false;
frontend = result.translateFrontend ?? "simplyTranslate";
fetch('/instances/data.json').then(response => response.text()).then(data => {
let dataJson = JSON.parse(data);
browser.storage.local.get(
[
"translateDisable",
"translateFrontend",
"translateProtocol",
"translateRedirects",
from = result.translateFrom ?? "auto";
to = result.translateTo ?? 'en';
"simplyTranslateNormalRedirectsChecks",
"simplyTranslateNormalCustomRedirects",
"simplyTranslateTorRedirectsChecks",
"simplyTranslateTorCustomRedirects",
if (result.translateRedirects) redirects = result.translateRedirects
"lingvaNormalRedirectsChecks",
"lingvaNormalCustomRedirects",
"lingvaTorRedirectsChecks",
"lingvaTorCustomRedirects",
simplyTranslateNormalRedirectsChecks = result.simplyTranslateNormalRedirectsChecks ?? [...redirects.simplyTranslate.normal];
simplyTranslateNormalCustomRedirects = result.simplyTranslateNormalCustomRedirects ?? [];
"translateFrom",
"translateTo",
],
(result) => {
disable = result.translateDisable ?? false;
frontend = result.translateFrontend ?? "simplyTranslate";
protocol = result.translateProtocol ?? 'normal';
lingvaNormalRedirectsChecks = result.lingvaNormalRedirectsChecks ?? [...redirects.lingva.normal];
lingvaNormalCustomRedirects = result.lingvaNormalCustomRedirects ?? [];
from = result.translateFrom ?? "DEFAULT";
to = result.translateTo ?? 'DEFAULT';
resolve();
});
redirects.simplyTranslate = dataJson.simplyTranslate;
redirects.lingva = dataJson.lingva;
if (result.translateRedirects) redirects = result.translateRedirects;
simplyTranslateNormalRedirectsChecks = result.simplyTranslateNormalRedirectsChecks ?? [...redirects.simplyTranslate.normal];
simplyTranslateNormalCustomRedirects = result.simplyTranslateNormalCustomRedirects ?? [];
simplyTranslateTorRedirectsChecks = result.simplyTranslateTorRedirectsChecks ?? [...redirects.simplyTranslate.tor];
simplyTranslateTorCustomRedirects = result.simplyTranslateTorCustomRedirects ?? [];
lingvaNormalRedirectsChecks = result.lingvaNormalRedirectsChecks ?? [...redirects.lingva.normal];
lingvaNormalCustomRedirects = result.lingvaNormalCustomRedirects ?? [];
lingvaTorRedirectsChecks = result.lingvaTorRedirectsChecks ?? [...redirects.lingva.tor];
lingvaTorCustomRedirects = result.lingvaTorCustomRedirects ?? [];
resolve();
});
});
});
}
export default {
@ -222,6 +288,9 @@ export default {
getFrontend,
setFrontend,
getProtocol,
setProtocol,
getFrom,
setFrom,
getTo,
@ -229,15 +298,23 @@ export default {
getSimplyTranslateNormalRedirectsChecks,
setSimplyTranslateNormalRedirectsChecks,
getSimplyTranslateTorRedirectsChecks,
setSimplyTranslateTorRedirectsChecks,
getSimplyTranslateNormalCustomRedirects,
setSimplyTranslateNormalCustomRedirects,
getSimplyTranslateTorCustomRedirects,
setSimplyTranslateTorCustomRedirects,
getLingvaNormalRedirectsChecks,
setLingvaNormalRedirectsChecks,
getLingvaTorRedirectsChecks,
setLingvaTorRedirectsChecks,
getLingvaNormalCustomRedirects,
setLingvaNormalCustomRedirects,
getLingvaTorCustomRedirects,
setLingvaTorCustomRedirects,
redirect,
init,

View File

@ -134,7 +134,6 @@ function setDisable(val) {
console.log("disableYoutube: ", disable)
}
let protocol;
const getProtocol = () => protocol;
function setProtocol(val) {
@ -511,7 +510,6 @@ async function init() {
redirects.invidious = dataJson.invidious;
if (result.youtubeRedirects) redirects = result.youtubeRedirects;
disable = result.disableYoutube ?? false;
protocol = result.youtubeProtocol ?? 'normal';
frontend = result.youtubeFrontend ?? 'piped';

View File

@ -64,7 +64,6 @@
"https://nitter.cutelab.space",
"https://nitter.nl",
"https://nitter.mint.lgbt",
"https://nitter.tokhmi.xyz",
"https://nitter.bus-hit.me",
"https://fuckthesacklers.network",
"https://nitter.govt.land",
@ -186,7 +185,8 @@
"https://lingva.pussthecat.org",
"https://translate.datatunnel.xyz",
"https://lingva.esmailelbob.xyz"
]
],
"tor": []
},
"searx": {
"normal": [

View File

@ -134,6 +134,7 @@ r = requests.get(
rJson = json.loads(r.text)
lingvaList = {}
lingvaList['normal'] = []
lingvaList['tor'] = []
for item in rJson:
lingvaList['normal'].append(item)
mightyList['lingva'] = lingvaList

View File

@ -57,7 +57,6 @@ function changeProtocolSettings(protocol) {
}
}
redditHelper.init().then(() => {
disableRedditElement.checked = !redditHelper.getDisableReddit();

View File

@ -120,12 +120,21 @@
</select>
</div>
<div class="some-block option-block">
<h4>Protocol</h4>
<select id="protocol">
<option value="normal">Normal</option>
<option value="tor">Tor</option>
</select>
</div>
<hr>
<div id="simplyTranslate-lingva">
<div class="some-block option-block">
<h4>From</h4>
<select id="from">
<option value="DEFAULT">Default</option>
<option value="auto">Auto</option>
<option value="af">Afrikaans</option>
<option value="sq">Albanian</option>
@ -237,10 +246,10 @@
<option value="zu">Zulu</option>
</select>
</div>
<div class="some-block option-block">
<h4>To</h4>
<select id="to">
<option value="DEFAULT">Default</option>
<option value="af">Afrikaans</option>
<option value="sq">Albanian</option>
<option value="am">Amharic</option>
@ -354,54 +363,107 @@
</div>
<div id="simplyTranslate">
<div class="some-block option-block">
<h4>Default Instances</h4>
</div>
<div class="checklist" id="simplyTranslate-normal-checklist">
</div>
<hr>
<div class="some-block option-block">
<h4>Custom Instances</h4>
</div>
<form id="custom-simplyTranslate-normal-instance-form">
<div id="simplyTranslate-normal">
<div class="some-block option-block">
<input id="simplyTranslate-normal-custom-instance" placeholder="https://simplyTranslate.com"
type="url" />
<button type="submit" class="add" id="simplyTranslate-normal-add-instance">
<svg xmlns="http://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px"
fill="currentColor">
<path d="M0 0h24v24H0V0z" fill="none" />
<path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z" />
</svg>
</button>
<h4>Default Instances</h4>
</div>
</form>
<div class="checklist" id="simplyTranslate-normal-custom-checklist"></div>
<div class="checklist" id="simplyTranslate-normal-checklist">
</div>
<hr>
<div class="some-block option-block">
<h4>Custom Instances</h4>
</div>
<form id="custom-simplyTranslate-normal-instance-form">
<div class="some-block option-block">
<input id="simplyTranslate-normal-custom-instance" placeholder="https://simplyTranslate.com"
type="url" />
<button type="submit" class="add" id="simplyTranslate-normal-add-instance">
<svg xmlns="http://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px"
fill="currentColor">
<path d="M0 0h24v24H0V0z" fill="none" />
<path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z" />
</svg>
</button>
</div>
</form>
<div class="checklist" id="simplyTranslate-normal-custom-checklist"></div>
</div>
<div id="simplyTranslate-tor">
<div class="some-block option-block">
<h4>Default Instances</h4>
</div>
<div class="checklist" id="simplyTranslate-tor-checklist">
</div>
<hr>
<div class="some-block option-block">
<h4>Custom Instances</h4>
</div>
<form id="custom-simplyTranslate-tor-instance-form">
<div class="some-block option-block">
<input id="simplyTranslate-tor-custom-instance" placeholder="https://simplyTranslate.com"
type="url" />
<button type="submit" class="add" id="simplyTranslate-tor-add-instance">
<svg xmlns="http://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px"
fill="currentColor">
<path d="M0 0h24v24H0V0z" fill="none" />
<path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z" />
</svg>
</button>
</div>
</form>
<div class="checklist" id="simplyTranslate-tor-custom-checklist"></div>
</div>
</div>
<div id="lingva">
<div class="some-block option-block">
<h4>Default Instances</h4>
</div>
<div class="checklist" id="lingva-normal-checklist">
</div>
<hr>
<div class="some-block option-block">
<h4>Custom Instances</h4>
</div>
<form id="custom-lingva-normal-instance-form">
<div id="lingva-normal">
<div class="some-block option-block">
<input id="lingva-normal-custom-instance" placeholder="https://lingva.com" type="url" />
<button type="submit" class="add" id="lingva-normal-add-instance">
<svg xmlns="http://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px"
fill="currentColor">
<path d="M0 0h24v24H0V0z" fill="none" />
<path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z" />
</svg>
</button>
<h4>Default Instances</h4>
</div>
</form>
<div class="checklist" id="lingva-normal-custom-checklist"></div>
<div class="checklist" id="lingva-normal-checklist">
</div>
<hr>
<div class="some-block option-block">
<h4>Custom Instances</h4>
</div>
<form id="custom-lingva-normal-instance-form">
<div class="some-block option-block">
<input id="lingva-normal-custom-instance" placeholder="https://lingva.com" type="url" />
<button type="submit" class="add" id="lingva-normal-add-instance">
<svg xmlns="http://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px"
fill="currentColor">
<path d="M0 0h24v24H0V0z" fill="none" />
<path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z" />
</svg>
</button>
</div>
</form>
<div class="checklist" id="lingva-normal-custom-checklist"></div>
</div>
<div id="lingva-tor">
<div class="some-block option-block">
<h4>Default Instances</h4>
</div>
<div class="checklist" id="lingva-tor-checklist">
</div>
<hr>
<div class="some-block option-block">
<h4>Custom Instances</h4>
</div>
<form id="custom-lingva-tor-instance-form">
<div class="some-block option-block">
<input id="lingva-tor-custom-instance" placeholder="https://lingva.com" type="url" />
<button type="submit" class="add" id="lingva-tor-add-instance">
<svg xmlns="http://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px"
fill="currentColor">
<path d="M0 0h24v24H0V0z" fill="none" />
<path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z" />
</svg>
</button>
</div>
</form>
<div class="checklist" id="lingva-tor-custom-checklist"></div>
</div>
</div>
</section>

View File

@ -32,27 +32,56 @@ translateFrontendElement.addEventListener("change",
}
);
let protocolElement = document.getElementById("protocol")
protocolElement.addEventListener("change",
(event) => {
let protocol = event.target.options[protocolElement.selectedIndex].value
translateHelper.setProtocol(protocol);
changeProtocolSettings(protocol);
}
);
function changeProtocolSettings(protocol) {
let normalSimplyTranslateDiv = document.getElementById("simplyTranslate-normal");
let torSimplyTranslateDiv = document.getElementById("simplyTranslate-tor");
let normalLingvaDiv = document.getElementById("lingva-normal");
let torLingvaDiv = document.getElementById("lingva-tor");
if (protocol == 'normal') {
normalSimplyTranslateDiv.style.display = 'block';
normalLingvaDiv.style.display = 'block';
torLingvaDiv.style.display = 'none';
torSimplyTranslateDiv.style.display = 'none';
}
else if (protocol == 'tor') {
normalSimplyTranslateDiv.style.display = 'none';
normalLingvaDiv.style.display = 'none';
torLingvaDiv.style.display = 'block';
torSimplyTranslateDiv.style.display = 'block';
}
}
let fromElement = document.getElementById("from");
fromElement.addEventListener("change",
(event) => {
let from = event.target.options[fromElement.selectedIndex].value;
translateHelper.setFrom(from);
}
event => translateHelper.setFrom(event.target.options[fromElement.selectedIndex].value)
);
let toElement = document.getElementById("to");
toElement.addEventListener("change",
(event) => {
let to = event.target.options[toElement.selectedIndex].value;
translateHelper.setTo(to);
}
event => translateHelper.setTo(event.target.options[toElement.selectedIndex].value)
);
translateHelper.init().then(() => {
disableElement.checked = !translateHelper.getDisable();
let frontend = translateHelper.getFrontend();
translateFrontendElement.value = frontend;
changeFrontendsSettings(frontend);
let protocol = translateHelper.getProtocol();
protocolElement.value = protocol;
changeProtocolSettings(protocol);
fromElement.value = translateHelper.getFrom();
toElement.value = translateHelper.getTo();
@ -65,7 +94,19 @@ translateHelper.init().then(() => {
translateHelper.setSimplyTranslateNormalRedirectsChecks,
translateHelper.getSimplyTranslateNormalCustomRedirects,
translateHelper.setSimplyTranslateNormalCustomRedirects
)
);
commonHelper.processDefaultCustomInstances(
'simplyTranslate',
'tor',
translateHelper,
document,
translateHelper.getSimplyTranslateTorRedirectsChecks,
translateHelper.setSimplyTranslateTorRedirectsChecks,
translateHelper.getSimplyTranslateTorCustomRedirects,
translateHelper.setSimplyTranslateTorCustomRedirects
);
commonHelper.processDefaultCustomInstances(
'lingva',
@ -76,5 +117,16 @@ translateHelper.init().then(() => {
translateHelper.setLingvaNormalRedirectsChecks,
translateHelper.getLingvaNormalCustomRedirects,
translateHelper.setLingvaNormalCustomRedirects
);
commonHelper.processDefaultCustomInstances(
'lingva',
'tor',
translateHelper,
document,
translateHelper.getLingvaTorRedirectsChecks,
translateHelper.setLingvaTorRedirectsChecks,
translateHelper.getLingvaTorCustomRedirects,
translateHelper.setLingvaTorCustomRedirects
)
});