diff --git a/README.md b/README.md index 5616a5e..57c55a9 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,20 @@ # Sugoi-web -Chrome extension to translate Japanese web novels with Sugoi Offline Translation Server (https://www.patreon.com/mingshiba) or DeepL API. +Extension for Chromium-based browsers and Firefox to translate Japanese web novels with Sugoi Offline Translation Server (https://www.patreon.com/mingshiba) or DeepL API. -**Installation:** +**Installation for Chromium-based browsers:** 1. Download the *Source code (zip)* archive from Releases 2. Unpack the archive 3. Open extensions page (*chrome://extensions/*) 4. Enable **Developer Mode** -5. Add extension using the "Load Unpacked" button +5. Press "Load Unpacked" button and select folder with *manifest.json* + +**Installation for Firefox:** +1. Download the *Source code (zip)* archive from Releases +2. Unpack the archive +3. Delete *manifest.json* +4. Rename *manifest-firefox.json* to *manifest.json* +5. Open extensions page (*about:debugging#/runtime/this-firefox*) +6. Press "Load Temporary Add-on" button and select *manifest.json* **Using with Sugoi:** 1. Open *{Sugoi folder} / backendServer / Program-Backend / Sugoi-Japanese-Translator / offlineTranslation* diff --git a/js/background.js b/js/background.js index 40a5f03..a65732e 100644 --- a/js/background.js +++ b/js/background.js @@ -61,7 +61,6 @@ class DeepL data += '&text=' + encodeURIComponent(lines[i]); } - /* const response = await fetch(this.url, { method: 'POST', body: data, @@ -70,15 +69,6 @@ class DeepL 'Content-Type': 'application/x-www-form-urlencoded', } }); - */ - const response = await fetch('https://api-free.deepl.com/v2/translate', { - method: 'POST', - body: data, - headers: { - 'Authorization': 'DeepL-Auth-Key 3e598917-623e-c1dc-1163-cad97a555430:fx', - 'Content-Type': 'application/x-www-form-urlencoded', - }, - }); const result = []; @@ -101,7 +91,14 @@ class DeepL function button_toggle(tab_id, enable) { - chrome.action.enable(tab_id); + if (chrome.action) + { + chrome.action.enable(tab_id); + } + else + { + chrome.browserAction.enable(tab_id); + } /* chrome.action.setIcon({ path: enable ? 'images/icon32.png' : 'images/icon32_off.png' @@ -227,12 +224,17 @@ async function processExternalMessage(request, sender) return response; } +function is_firefox() +{ + return typeof browser !== 'undefined'; +} + chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { - processMessage(request, sender).then(sendResponse); - return true; + const promise = processMessage(request, sender).then(sendResponse); + return is_firefox ? promise : true; }); chrome.runtime.onMessageExternal.addListener((request, sender, sendResponse) => { - processExternalMessage(request, sender).then(sendResponse); - return true; + const promise = processExternalMessage(request, sender).then(sendResponse); + return is_firefox ? promise : true; }); \ No newline at end of file diff --git a/js/classes/ChromeApi.js b/js/classes/ChromeApi.js index 01d5b84..5d5e405 100644 --- a/js/classes/ChromeApi.js +++ b/js/classes/ChromeApi.js @@ -78,7 +78,10 @@ class ChromeApi config.deepl_texts_per_request = parseInt(config.deepl_texts_per_request); } - return this.storageSet({config: config}); + // firefox workaround, otherwise saved empty object + const data = JSON.parse(JSON.stringify(config)); + + return this.storageSet({config: data}); } /** diff --git a/js/classes/TranslatorSugoi.js b/js/classes/TranslatorSugoi.js index ad94c2d..1ea8e92 100644 --- a/js/classes/TranslatorSugoi.js +++ b/js/classes/TranslatorSugoi.js @@ -7,7 +7,7 @@ class TranslatorSugoi extends Translator * @type {string} * @private */ - _url = 'http://127.0.0.1'; + _url = 'http://localhost'; /** * diff --git a/manifest-firefox.json b/manifest-firefox.json new file mode 100644 index 0000000..1f0f6b2 --- /dev/null +++ b/manifest-firefox.json @@ -0,0 +1,65 @@ +{ + "name": "Sugoi Web Translation", + "version": "1.0.8", + + "manifest_version": 2, + + "description": "Sugoi/DeepL Web Translation", + "icons": { + "128": "images/s128.png", + "16": "images/s16.png", + "48": "images/s48.png" + }, + + "browser_action": { + "default_icon": { + "32": "images/s32.png" + }, + "default_title": "Sugoi/DeepL Web Translation", + "default_popup": "popup/action.html" + }, + + "permissions": [ + "storage", + "tabs", + "http://localhost/*", + "https://api-free.deepl.com/v2/*", + "https://api.deepl.com/v2/*" + ], + "background": { + "scripts": ["js/background.js"] + }, + + "content_scripts":[ + { + "js": [ + "js/vendor/jquery-3.4.1.min.js", + "js/classes/Utilities.js", + + "js/classes/Translator.js", + "js/classes/TranslatorSugoi.js", + "js/classes/TranslatorDeepL.js", + "js/classes/TranslatorLine.js", + + "js/classes/proxy/Proxy.js", + "js/classes/proxy/ProxySyosetu.js", + "js/classes/proxy/ProxyKakuyomu.js", + "js/classes/proxy/ProxyUnavailable.js", + + "js/classes/ChromeApi.js", + "js/classes/Config.js", + "js/classes/UI.js", + + "js/main.js" + ], + "matches": [ + "*://*.syosetu.com/*", + "*://syosetu.com/*", + "*://*.kakuyomu.jp/*", + "*://kakuyomu.jp/*" + ], + "run_at": "document_end", + "all_frames": true + } + ] +} \ No newline at end of file diff --git a/manifest.json b/manifest.json index f85ab0f..1be8fa6 100644 --- a/manifest.json +++ b/manifest.json @@ -1,11 +1,11 @@ { "name": "Sugoi Web Translation", - "version": "1.0.7", + "version": "1.0.8", "manifest_version": 3, "incognito": "split", - "description": "", + "description": "Sugoi/DeepL Web Translation", "icons": { "128": "images/s128.png", "16": "images/s16.png", @@ -16,7 +16,7 @@ "default_icon": { "32": "images/s32.png" }, - "default_title": "Sugoi Web Translation", + "default_title": "Sugoi/DeepL Web Translation", "default_popup": "popup/action.html" },