added deepl translations
This commit is contained in:
parent
ad204ee4e5
commit
89d351c6e3
@ -26,6 +26,22 @@ const searchEngines = {
|
||||
},
|
||||
};
|
||||
|
||||
const translationPrefixes = [
|
||||
"t",
|
||||
"translation",
|
||||
]
|
||||
|
||||
|
||||
function getDeepLUrl(s) {
|
||||
const parts = s.split("-")
|
||||
if (parts.length != 3) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
return `https://www.deepl.com/en/translator?/#${encodeURIComponent(parts[0].trim())}/${encodeURIComponent(parts[1].trim())}/${encodeURIComponent(parts[2].trim())}`;
|
||||
}
|
||||
|
||||
|
||||
form.addEventListener("submit", event => {
|
||||
event.preventDefault();
|
||||
|
||||
@ -37,6 +53,25 @@ form.addEventListener("submit", event => {
|
||||
return
|
||||
}
|
||||
|
||||
// deepl translations
|
||||
let doTranslation = false;
|
||||
for (const value of translationPrefixes) {
|
||||
const prefix = `!${value} `;
|
||||
if (s.startsWith(prefix)) {
|
||||
doTranslation = true;
|
||||
s = s.slice(prefix.length); // Remove the !{key} prefix
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (doTranslation) {
|
||||
const url = getDeepLUrl(s);
|
||||
if (url) {
|
||||
window.open(url.toString(), "_self");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the string starts with ! followed by a key from searchEngines
|
||||
let selectedEngine = {
|
||||
action: form.getAttribute("action"),
|
||||
|
Loading…
x
Reference in New Issue
Block a user