Clean-up diff

This commit is contained in:
Cohee 2024-04-27 21:11:41 +03:00
parent 4521dde455
commit c49b37f968

View File

@ -1,9 +1,18 @@
import {callPopup, event_types, eventSource, getRequestHeaders, reloadCurrentChat, saveSettingsDebounced, substituteParams, updateMessageBlock,} from '../../../script.js';
import {extension_settings, getContext} from '../../extensions.js';
import {findSecret, secret_state, writeSecret} from '../../secrets.js';
import {splitRecursive} from '../../utils.js';
export { translate };
export {translate};
import {
callPopup,
event_types,
eventSource,
getRequestHeaders,
reloadCurrentChat,
saveSettingsDebounced,
substituteParams,
updateMessageBlock,
} from '../../../script.js';
import { extension_settings, getContext } from '../../extensions.js';
import { findSecret, secret_state, writeSecret } from '../../secrets.js';
import { splitRecursive } from '../../utils.js';
export const autoModeOptions = {
NONE: 'none',
@ -157,14 +166,11 @@ function loadSettings() {
}
}
$(`#translation_provider option[value="${
extension_settings.translate.provider}"]`)
$(`#translation_provider option[value="${extension_settings.translate.provider}"]`)
.attr('selected', true);
$(`#translation_target_language option[value="${
extension_settings.translate.target_language}"]`)
$(`#translation_target_language option[value="${extension_settings.translate.target_language}"]`)
.attr('selected', true);
$(`#translation_auto_mode option[value="${
extension_settings.translate.auto_mode}"]`)
$(`#translation_auto_mode option[value="${extension_settings.translate.auto_mode}"]`)
.attr('selected', true);
showKeysButton();
}
@ -205,7 +211,7 @@ async function translateProviderOneRing(text, lang) {
const response = await fetch('/api/translate/onering', {
method: 'POST',
headers: getRequestHeaders(),
body: JSON.stringify({text: text, from_lang: from_lang, to_lang: lang}),
body: JSON.stringify({ text: text, from_lang: from_lang, to_lang: lang }),
});
if (response.ok) {
@ -226,7 +232,7 @@ async function translateProviderLibre(text, lang) {
const response = await fetch('/api/translate/libre', {
method: 'POST',
headers: getRequestHeaders(),
body: JSON.stringify({text: text, lang: lang}),
body: JSON.stringify({ text: text, lang: lang }),
});
if (response.ok) {
@ -247,7 +253,7 @@ async function translateProviderGoogle(text, lang) {
const response = await fetch('/api/translate/google', {
method: 'POST',
headers: getRequestHeaders(),
body: JSON.stringify({text: text, lang: lang}),
body: JSON.stringify({ text: text, lang: lang }),
});
if (response.ok) {
@ -268,7 +274,7 @@ async function translateProviderLingva(text, lang) {
const response = await fetch('/api/translate/lingva', {
method: 'POST',
headers: getRequestHeaders(),
body: JSON.stringify({text: text, lang: lang}),
body: JSON.stringify({ text: text, lang: lang }),
});
if (response.ok) {
@ -293,7 +299,7 @@ async function translateProviderDeepl(text, lang) {
const response = await fetch('/api/translate/deepl', {
method: 'POST',
headers: getRequestHeaders(),
body: JSON.stringify({text: text, lang: lang}),
body: JSON.stringify({ text: text, lang: lang }),
});
if (response.ok) {
@ -314,7 +320,7 @@ async function translateProviderDeepLX(text, lang) {
const response = await fetch('/api/translate/deeplx', {
method: 'POST',
headers: getRequestHeaders(),
body: JSON.stringify({text: text, lang: lang}),
body: JSON.stringify({ text: text, lang: lang }),
});
if (response.ok) {
@ -335,7 +341,7 @@ async function translateProviderBing(text, lang) {
const response = await fetch('/api/translate/bing', {
method: 'POST',
headers: getRequestHeaders(),
body: JSON.stringify({text: text, lang: lang}),
body: JSON.stringify({ text: text, lang: lang }),
});
if (response.ok) {
@ -442,7 +448,7 @@ function createEventHandler(translateFunction, shouldTranslateFunction) {
async function onTranslateInputMessageClick() {
const ta = document.querySelector('#send_textarea');
toastr.info(`Input Message is translating`, 'Please wait...');
toastr.info('Input Message is translating', 'Please wait...');
const translatedText =
await translate(ta.value, extension_settings.translate.internal_language);
$('#send_textarea').val(translatedText);
@ -637,8 +643,7 @@ jQuery(() => {
'oneringtranslator': 'http://127.0.0.1:4990/translate',
'deeplx': 'http://127.0.0.1:1188/translate',
};
const popupText = `<h3>${optionText} API URL</h3><i>Example: <tt>${
String(exampleURLs[extension_settings.translate.provider])}</tt></i>`;
const popupText = `<h3>${optionText} API URL</h3><i>Example: <tt>${String(exampleURLs[extension_settings.translate.provider])}</tt></i>`;
const secretKey = extension_settings.translate.provider + '_url';
const savedUrl = secret_state[secretKey] ? await findSecret(secretKey) : '';