From 9397ea7178610df469e18a6b0773dddf21019dee Mon Sep 17 00:00:00 2001 From: vladkryv <83036866+vladkryv@users.noreply.github.com> Date: Tue, 19 Sep 2023 20:51:54 +0300 Subject: [PATCH] Add support deepl pro api --- src/background/translationService.js | 20 ++++++++--------- src/options/options.html | 8 +++---- src/options/options.js | 32 ++++++++++++++-------------- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/background/translationService.js b/src/background/translationService.js index 938cc563..772dc034 100644 --- a/src/background/translationService.js +++ b/src/background/translationService.js @@ -1260,16 +1260,16 @@ const translationService = (function () { }; /** - * Creates the DeepLFreeApi translation service + * Creates the DeepLApi translation service * @param {string} apiKey * @returns {Service} libreService */ - const createDeeplFreeApiService = (apiKey) => { + const createDeeplApiService = (apiKey) => { return new (class extends Service { constructor() { super( "deepl", - "https://api-free.deepl.com/v2/translate", + apiKey.endsWith(":fx") ? "https://api-free.deepl.com/v2/translate" : "https://api.deepl.com/v2/translate", "POST", function cbTransformRequest(sourceArray) { return sourceArray[0]; @@ -1510,12 +1510,12 @@ const translationService = (function () { ); } else if (request.action === "removeLibreService") { serviceList.delete("libre"); - } else if (request.action === "createDeeplFreeApiService") { + } else if (request.action === "createDeeplApiService") { serviceList.set( "deepl", - createDeeplFreeApiService(request.deepl_freeapi.apiKey) + createDeeplApiService(request.deepl_api.apiKey) ); - } else if (request.action === "removeDeeplFreeApiService") { + } else if (request.action === "removeDeeplApiService") { serviceList.set( "deepl", /** @type {Service} */ /** @type {?} */ (deeplService) @@ -1532,12 +1532,12 @@ const translationService = (function () { } if ( - twpConfig.get("customServices").find((cs) => cs.name === "deepl_freeapi") + twpConfig.get("customServices").find((cs) => cs.name === "deepl_api") ) { - const deepl_freeapi = twpConfig + const deepl_api = twpConfig .get("customServices") - .find((cs) => cs.name === "deepl_freeapi"); - serviceList.set("deepl", createDeeplFreeApiService(deepl_freeapi.apiKey)); + .find((cs) => cs.name === "deepl_api"); + serviceList.set("deepl", createDeeplApiService(deepl_api.apiKey)); } }); diff --git a/src/options/options.html b/src/options/options.html index e467b51b..7ca0a799 100644 --- a/src/options/options.html +++ b/src/options/options.html @@ -576,13 +576,13 @@