diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..67e07b8 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +/build +/release diff --git a/.eslintrc.js b/.eslintrc.js index 5a9a66e..acd44a3 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -4,14 +4,14 @@ module.exports = { node: true, }, extends: [ - 'prettier', - 'prettier/@typescript-eslint', 'plugin:react/recommended', 'plugin:react-hooks/recommended', 'plugin:@typescript-eslint/recommended', + 'plugin:prettier/recommended', ], parser: '@typescript-eslint/parser', parserOptions: { + project: './tsconfig.eslint.json', sourceType: 'module', }, plugins: ['@typescript-eslint'], @@ -24,4 +24,9 @@ module.exports = { '@typescript-eslint/no-var-requires': 0, 'react/prop-types': 0, }, + settings: { + react: { + version: 'detect', + }, + }, } diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..6c2e554 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: geekdada diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 62695e9..08dc6a1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,7 +11,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - node-version: [14] + node-version: [16] steps: - name: Fetch repository uses: actions/checkout@v2 diff --git a/.node-version b/.node-version new file mode 100644 index 0000000..b6a7d89 --- /dev/null +++ b/.node-version @@ -0,0 +1 @@ +16 diff --git a/CHANGELOG.md b/CHANGELOG.md index ccffd10..62a4630 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,154 +1,197 @@ -# [0.2.0](https://github.com/geekdada/a-translator-chrome-extension/compare/v0.2.0-5...v0.2.0) (2021-01-22) +## [0.4.2](https://github.com/geekdada/deepl-chrome-extension/compare/v0.4.1...v0.4.2) (2023-02-25) + + +### Bug Fixes + +* pipeline ([6e08697](https://github.com/geekdada/deepl-chrome-extension/commit/6e086978705479ee7e741e11378f0e0f5241bbf5)) + + + +## [0.4.1](https://github.com/geekdada/deepl-chrome-extension/compare/v0.4.0...v0.4.1) (2023-02-25) + + +### Bug Fixes + +* DeepL API authorization ([38486d0](https://github.com/geekdada/deepl-chrome-extension/commit/38486d0acec2e75a77c23c794999a97a6a753251)) + + + +# [0.4.0](https://github.com/geekdada/deepl-chrome-extension/compare/v0.3.1...v0.4.0) (2021-07-03) + + +### Features + +* add support for DeepL free ([beac66c](https://github.com/geekdada/deepl-chrome-extension/commit/beac66c78250240fd911dad65458bbe029bf44d7)) +* change name ([c47f4f2](https://github.com/geekdada/deepl-chrome-extension/commit/c47f4f2726533da75a16d288cf39602d07bee567)) +* support multiple tencent ocr regions ([2bd674c](https://github.com/geekdada/deepl-chrome-extension/commit/2bd674c3857b89439b5c4eaccc2f61ff33b8a3cc)) +* support new deepl languages ([72d66da](https://github.com/geekdada/deepl-chrome-extension/commit/72d66dabc211f453398e866afa9b397432a32e3e)) + + + +## [0.3.1](https://github.com/geekdada/deepl-chrome-extension/compare/v0.3.0...v0.3.1) (2021-02-14) + + + +# [0.3.0](https://github.com/geekdada/deepl-chrome-extension/compare/v0.2.0...v0.3.0) (2021-02-14) + + +### Features + +* remove support for a translator ([3eee95a](https://github.com/geekdada/deepl-chrome-extension/commit/3eee95aafb6543052a492734b806dba1907cb701)) + + + +# [0.2.0](https://github.com/geekdada/deepl-chrome-extension/compare/v0.2.0-5...v0.2.0) (2021-01-22) ### Features -* remove window.alert ([1a5048c](https://github.com/geekdada/a-translator-chrome-extension/commit/1a5048c2d45dc321afc0bb9cfec3dd9bf470f675)) +* remove window.alert ([1a5048c](https://github.com/geekdada/deepl-chrome-extension/commit/1a5048c2d45dc321afc0bb9cfec3dd9bf470f675)) -# [0.2.0-5](https://github.com/geekdada/a-translator-chrome-extension/compare/v0.2.0-4...v0.2.0-5) (2021-01-22) +# [0.2.0-5](https://github.com/geekdada/deepl-chrome-extension/compare/v0.2.0-4...v0.2.0-5) (2021-01-22) ### Bug Fixes -* use chinese ([b3b6188](https://github.com/geekdada/a-translator-chrome-extension/commit/b3b61880af68cae845f4c83f12f23c503b49f3b2)) +* use chinese ([b3b6188](https://github.com/geekdada/deepl-chrome-extension/commit/b3b61880af68cae845f4c83f12f23c503b49f3b2)) ### Features -* add config for hover button ([477de29](https://github.com/geekdada/a-translator-chrome-extension/commit/477de29b86033267db3acb95f042bdbbc1425786)) -* add context menus ([ccf87a5](https://github.com/geekdada/a-translator-chrome-extension/commit/ccf87a512664d45c236e0017ccd613ef39d8352e)) -* keyboard shortcuts ([c26cf83](https://github.com/geekdada/a-translator-chrome-extension/commit/c26cf83fc92225367cf676e736e773d66f7ed075)) +* add config for hover button ([477de29](https://github.com/geekdada/deepl-chrome-extension/commit/477de29b86033267db3acb95f042bdbbc1425786)) +* add context menus ([ccf87a5](https://github.com/geekdada/deepl-chrome-extension/commit/ccf87a512664d45c236e0017ccd613ef39d8352e)) +* keyboard shortcuts ([c26cf83](https://github.com/geekdada/deepl-chrome-extension/commit/c26cf83fc92225367cf676e736e773d66f7ed075)) -# [0.2.0-4](https://github.com/geekdada/a-translator-chrome-extension/compare/v0.2.0-3...v0.2.0-4) (2021-01-21) +# [0.2.0-4](https://github.com/geekdada/deepl-chrome-extension/compare/v0.2.0-3...v0.2.0-4) (2021-01-21) ### Features -* ocr text for translating ([72b58ed](https://github.com/geekdada/a-translator-chrome-extension/commit/72b58ede93a68032d2b4979e46ae32f35803a9ea)) -* turn off ocr tool when the selection is too small ([0e13070](https://github.com/geekdada/a-translator-chrome-extension/commit/0e130708c7c87d1e3e6929509e65abbccff3db8b)) +* ocr text for translating ([72b58ed](https://github.com/geekdada/deepl-chrome-extension/commit/72b58ede93a68032d2b4979e46ae32f35803a9ea)) +* turn off ocr tool when the selection is too small ([0e13070](https://github.com/geekdada/deepl-chrome-extension/commit/0e130708c7c87d1e3e6929509e65abbccff3db8b)) -# [0.2.0-3](https://github.com/geekdada/a-translator-chrome-extension/compare/v0.2.0-2...v0.2.0-3) (2021-01-20) +# [0.2.0-3](https://github.com/geekdada/deepl-chrome-extension/compare/v0.2.0-2...v0.2.0-3) (2021-01-20) ### Features -* change target language directly in webpage ([fdb574b](https://github.com/geekdada/a-translator-chrome-extension/commit/fdb574b8210ce6914f64f2a8cfecdde13cdf7ad6)) -* retry button ([2b287d3](https://github.com/geekdada/a-translator-chrome-extension/commit/2b287d3fec67c01f25a8a8d7b57c3c0e02962b29)) +* change target language directly in webpage ([fdb574b](https://github.com/geekdada/deepl-chrome-extension/commit/fdb574b8210ce6914f64f2a8cfecdde13cdf7ad6)) +* retry button ([2b287d3](https://github.com/geekdada/deepl-chrome-extension/commit/2b287d3fec67c01f25a8a8d7b57c3c0e02962b29)) -# [0.2.0-2](https://github.com/geekdada/a-translator-chrome-extension/compare/v0.2.0-1...v0.2.0-2) (2021-01-18) +# [0.2.0-2](https://github.com/geekdada/deepl-chrome-extension/compare/v0.2.0-1...v0.2.0-2) (2021-01-18) ### Bug Fixes -* conflict with emotion 10 application ([699948e](https://github.com/geekdada/a-translator-chrome-extension/commit/699948e1c1f93f43b4e939b4b4652213d1973423)) -* style typo ([4e46590](https://github.com/geekdada/a-translator-chrome-extension/commit/4e4659034f871b25ed7a64d24147eec04c542b6e)) +* conflict with emotion 10 application ([699948e](https://github.com/geekdada/deepl-chrome-extension/commit/699948e1c1f93f43b4e939b4b4652213d1973423)) +* style typo ([4e46590](https://github.com/geekdada/deepl-chrome-extension/commit/4e4659034f871b25ed7a64d24147eec04c542b6e)) -# [0.2.0-1](https://github.com/geekdada/a-translator-chrome-extension/compare/v0.2.0-0...v0.2.0-1) (2021-01-18) +# [0.2.0-1](https://github.com/geekdada/deepl-chrome-extension/compare/v0.2.0-0...v0.2.0-1) (2021-01-18) -# [0.2.0-0](https://github.com/geekdada/a-translator-chrome-extension/compare/v0.1.6...v0.2.0-0) (2021-01-17) +# [0.2.0-0](https://github.com/geekdada/deepl-chrome-extension/compare/v0.1.6...v0.2.0-0) (2021-01-17) ### Features -* add polyfill for old browsers ([0e38a77](https://github.com/geekdada/a-translator-chrome-extension/commit/0e38a77ea2fe224ae5086d2930ce9d17cc89530a)) -* optimize string selection ([7ea8ac7](https://github.com/geekdada/a-translator-chrome-extension/commit/7ea8ac71fb88146e46b6608bc5eeacae659762ac)) +* add polyfill for old browsers ([0e38a77](https://github.com/geekdada/deepl-chrome-extension/commit/0e38a77ea2fe224ae5086d2930ce9d17cc89530a)) +* optimize string selection ([7ea8ac7](https://github.com/geekdada/deepl-chrome-extension/commit/7ea8ac71fb88146e46b6608bc5eeacae659762ac)) -## [0.1.6](https://github.com/geekdada/a-translator-chrome-extension/compare/v0.1.5...v0.1.6) (2021-01-10) +## [0.1.6](https://github.com/geekdada/deepl-chrome-extension/compare/v0.1.5...v0.1.6) (2021-01-10) ### Bug Fixes -* app positioning ([7bbb68b](https://github.com/geekdada/a-translator-chrome-extension/commit/7bbb68bc475234679277c400476e3ee0c3440cf9)) +* app positioning ([7bbb68b](https://github.com/geekdada/deepl-chrome-extension/commit/7bbb68bc475234679277c400476e3ee0c3440cf9)) -## [0.1.5](https://github.com/geekdada/a-translator-chrome-extension/compare/v0.1.4...v0.1.5) (2021-01-08) +## [0.1.5](https://github.com/geekdada/deepl-chrome-extension/compare/v0.1.4...v0.1.5) (2021-01-08) ### Bug Fixes -* close button becomes white on some occasions ([b5c22eb](https://github.com/geekdada/a-translator-chrome-extension/commit/b5c22ebb2520c35cb3ba79fe22dbe052470ed0d4)) -* remove tabs permission ([5ad6bd5](https://github.com/geekdada/a-translator-chrome-extension/commit/5ad6bd55e34e508373fb99f42d77f7f7e4b51d1b)) +* close button becomes white on some occasions ([b5c22eb](https://github.com/geekdada/deepl-chrome-extension/commit/b5c22ebb2520c35cb3ba79fe22dbe052470ed0d4)) +* remove tabs permission ([5ad6bd5](https://github.com/geekdada/deepl-chrome-extension/commit/5ad6bd55e34e508373fb99f42d77f7f7e4b51d1b)) -## [0.1.4](https://github.com/geekdada/a-translator-chrome-extension/compare/v0.1.3...v0.1.4) (2021-01-06) +## [0.1.4](https://github.com/geekdada/deepl-chrome-extension/compare/v0.1.3...v0.1.4) (2021-01-06) -## [0.1.3](https://github.com/geekdada/a-translator-chrome-extension/compare/v0.1.2...v0.1.3) (2021-01-06) +## [0.1.3](https://github.com/geekdada/deepl-chrome-extension/compare/v0.1.2...v0.1.3) (2021-01-06) ### Bug Fixes -* scroll bug ([f9204ba](https://github.com/geekdada/a-translator-chrome-extension/commit/f9204ba32b8f20f7388d7501e885cf7fabad49b8)) +* scroll bug ([f9204ba](https://github.com/geekdada/deepl-chrome-extension/commit/f9204ba32b8f20f7388d7501e885cf7fabad49b8)) ### Features -* add link to dashboard ([8c48313](https://github.com/geekdada/a-translator-chrome-extension/commit/8c48313f7e9d2f378398d35f8a7887645cb54de7)) +* add link to dashboard ([8c48313](https://github.com/geekdada/deepl-chrome-extension/commit/8c48313f7e9d2f378398d35f8a7887645cb54de7)) -## [0.1.2](https://github.com/geekdada/a-translator-chrome-extension/compare/v0.1.1...v0.1.2) (2021-01-05) +## [0.1.2](https://github.com/geekdada/deepl-chrome-extension/compare/v0.1.1...v0.1.2) (2021-01-05) ### Bug Fixes -* style issue ([becf98e](https://github.com/geekdada/a-translator-chrome-extension/commit/becf98eb50bbc1f6db0a7117203ca15fead89fe5)) +* style issue ([becf98e](https://github.com/geekdada/deepl-chrome-extension/commit/becf98eb50bbc1f6db0a7117203ca15fead89fe5)) ### Features -* add notification ([ca78404](https://github.com/geekdada/a-translator-chrome-extension/commit/ca784049d4e0a70d8ee598988df690e51bdf1f8b)) +* add notification ([ca78404](https://github.com/geekdada/deepl-chrome-extension/commit/ca784049d4e0a70d8ee598988df690e51bdf1f8b)) -## [0.1.1](https://github.com/geekdada/a-translator-chrome-extension/compare/v0.1.0...v0.1.1) (2021-01-05) +## [0.1.1](https://github.com/geekdada/deepl-chrome-extension/compare/v0.1.0...v0.1.1) (2021-01-05) ### Bug Fixes -* setting value becomes undefined during the first time use ([2cfbf26](https://github.com/geekdada/a-translator-chrome-extension/commit/2cfbf26e2b836821ae339af51a1c18dc2ee7e469)) +* setting value becomes undefined during the first time use ([2cfbf26](https://github.com/geekdada/deepl-chrome-extension/commit/2cfbf26e2b836821ae339af51a1c18dc2ee7e469)) -# [0.1.0](https://github.com/geekdada/a-translator-chrome-extension/compare/9aa9d4392aedb375fe540fe9f64a0a8732b1c8cc...v0.1.0) (2021-01-05) +# [0.1.0](https://github.com/geekdada/deepl-chrome-extension/compare/9aa9d4392aedb375fe540fe9f64a0a8732b1c8cc...v0.1.0) (2021-01-05) ### Bug Fixes -* should not fire icon within app ([1d0c484](https://github.com/geekdada/a-translator-chrome-extension/commit/1d0c484b2fd3d21b29575230aa22b35660d44e8f)) -* show err object ([92c1aef](https://github.com/geekdada/a-translator-chrome-extension/commit/92c1aefd54140c19f73cd309918e1c34672b47ae)) +* should not fire icon within app ([1d0c484](https://github.com/geekdada/deepl-chrome-extension/commit/1d0c484b2fd3d21b29575230aa22b35660d44e8f)) +* show err object ([92c1aef](https://github.com/geekdada/deepl-chrome-extension/commit/92c1aefd54140c19f73cd309918e1c34672b47ae)) ### Features -* add close button to App ([e43c057](https://github.com/geekdada/a-translator-chrome-extension/commit/e43c057ad46564c535ccae3c3da9532497ac009f)) -* add copy button ([b9ff17e](https://github.com/geekdada/a-translator-chrome-extension/commit/b9ff17e676e09cf37abb67da2be10033eec72156)) -* add feedback ([3cd3ad3](https://github.com/geekdada/a-translator-chrome-extension/commit/3cd3ad3de43b3bf70a98f73d6f79b56fae3dcbd6)) -* add notification ([ee01fd7](https://github.com/geekdada/a-translator-chrome-extension/commit/ee01fd7b4cdcf11e94b2357a601240205bb69f53)) -* collapse the original ([ea7a335](https://github.com/geekdada/a-translator-chrome-extension/commit/ea7a33573345618021b0da67ddd8edae9c6adb72)) -* custom logger ([d30f3d5](https://github.com/geekdada/a-translator-chrome-extension/commit/d30f3d51f25501496fba67bbd1a733e415e1f196)) -* options page ([9aa9d43](https://github.com/geekdada/a-translator-chrome-extension/commit/9aa9d4392aedb375fe540fe9f64a0a8732b1c8cc)) -* paragraph margin ([09abfd0](https://github.com/geekdada/a-translator-chrome-extension/commit/09abfd0f169f6f5c24be92bf44e82336f96ceec7)) -* reset app position ([9632247](https://github.com/geekdada/a-translator-chrome-extension/commit/9632247e23bf44c1165649f2a84fa6bbae7a8f1d)) -* select to translate ([942d35f](https://github.com/geekdada/a-translator-chrome-extension/commit/942d35f5db43271aaf57a0e1e44e49c0bf4f35b9)) -* tranlsation list ([c8a80f4](https://github.com/geekdada/a-translator-chrome-extension/commit/c8a80f4f2641f41a481f6d32931c8546d0a94b62)) +* add close button to App ([e43c057](https://github.com/geekdada/deepl-chrome-extension/commit/e43c057ad46564c535ccae3c3da9532497ac009f)) +* add copy button ([b9ff17e](https://github.com/geekdada/deepl-chrome-extension/commit/b9ff17e676e09cf37abb67da2be10033eec72156)) +* add feedback ([3cd3ad3](https://github.com/geekdada/deepl-chrome-extension/commit/3cd3ad3de43b3bf70a98f73d6f79b56fae3dcbd6)) +* add notification ([ee01fd7](https://github.com/geekdada/deepl-chrome-extension/commit/ee01fd7b4cdcf11e94b2357a601240205bb69f53)) +* collapse the original ([ea7a335](https://github.com/geekdada/deepl-chrome-extension/commit/ea7a33573345618021b0da67ddd8edae9c6adb72)) +* custom logger ([d30f3d5](https://github.com/geekdada/deepl-chrome-extension/commit/d30f3d51f25501496fba67bbd1a733e415e1f196)) +* options page ([9aa9d43](https://github.com/geekdada/deepl-chrome-extension/commit/9aa9d4392aedb375fe540fe9f64a0a8732b1c8cc)) +* paragraph margin ([09abfd0](https://github.com/geekdada/deepl-chrome-extension/commit/09abfd0f169f6f5c24be92bf44e82336f96ceec7)) +* reset app position ([9632247](https://github.com/geekdada/deepl-chrome-extension/commit/9632247e23bf44c1165649f2a84fa6bbae7a8f1d)) +* select to translate ([942d35f](https://github.com/geekdada/deepl-chrome-extension/commit/942d35f5db43271aaf57a0e1e44e49c0bf4f35b9)) +* tranlsation list ([c8a80f4](https://github.com/geekdada/deepl-chrome-extension/commit/c8a80f4f2641f41a481f6d32931c8546d0a94b62)) diff --git a/README.md b/README.md index 9545a9a..9ad2a05 100755 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ -# a-translator-chrome-extension +# DeepL Translate for Chrome + +Chrome DeepL 翻译插件 (需自己购买 DeepL API 计划)。 ## 安装 @@ -14,7 +16,7 @@ ## 配置 -请在插件配置页面填入 A Translator 的 [API Token](https://a-translator.royli.dev/dashboard/profile)。 +请在插件配置页面填入 DeepL 的 API Token。 ## 使用 @@ -22,6 +24,8 @@ ![](./assets/screenshot.png) +更详尽的使用文档请前往 [这里](https://www.notion.so/geekdada/Chrome-95ba478ceca745f8b98b4a1d06c0f8dd) + ## License [MIT](./LICENSE) diff --git a/package.json b/package.json index 0cb104d..75b4870 100755 --- a/package.json +++ b/package.json @@ -1,18 +1,18 @@ { - "name": "a-translator-chrome-extension", - "version": "0.2.0", - "description": "A Chrome extension for A Translator", + "name": "deepl-chrome-extension", + "version": "0.4.2", + "description": "DeepL translate for Chrome", "license": "MIT", "repository": { "type": "git", - "url": "https://github.com/geekdada/a-translator-chrome-extension" + "url": "https://github.com/geekdada/deepl-chrome-extension" }, "scripts": { "start": "cross-env NODE_ENV=development node scripts/webserver.js", "build": "cross-env NODE_ENV=production webpack", "release": "run-s build && sh scripts/build.sh", "prettier": "prettier --write '**/*.{js,jsx,ts,tsx,css,html}'", - "lint": "eslint --ext .ts,.tsx,.js,.jsx", + "lint": "eslint . --ext .ts,.tsx,.js,.jsx", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0", "pub": "np --no-publish --no-release-draft", "version": "npm run changelog && git add ." @@ -32,13 +32,13 @@ "@emotion/server": "^11.0.0", "@emotion/styled": "^11.0.0", "@hot-loader/react-dom": "^17.0.1", - "@material-ui/core": "^4.11.2", + "@mui/material": "^5.9.3", "@tailwindcss/forms": "^0.2.1", - "@types/chrome": "0.0.128", + "@types/chrome": "0.0.193", "@types/crypto-js": "^4.0.1", "@types/fs-extra": "^9.0.6", "@types/lodash-es": "^4.17.4", - "@types/node": "^14", + "@types/node": "^16", "@types/pino": "^6.3.4", "@types/rangy": "^0.0.33", "@types/react": "^17.0.0", @@ -50,7 +50,6 @@ "@typescript-eslint/parser": "^4.5.0", "autoprefixer": "^10.1.0", "axios": "^0.21.1", - "babel-eslint": "^10.1.0", "babel-loader": "^8.2.2", "babel-plugin-macros": "^3.0.1", "babel-plugin-transform-inline-environment-variables": "^0.4.3", @@ -65,7 +64,8 @@ "css-loader": "^5.0.1", "dotenv": "^8.2.0", "eslint": "^7.16.0", - "eslint-config-prettier": "^7.1.0", + "eslint-config-prettier": "^8.3.0", + "eslint-plugin-prettier": "^3.4.0", "eslint-plugin-react": "^7.20.6", "eslint-plugin-react-hooks": "^4.1.2", "file-loader": "^6.2.0", @@ -76,8 +76,7 @@ "lint-staged": "^10.5.3", "lodash-es": "^4.17.20", "mini-css-extract-plugin": "^1.3.3", - "node-sass": "^5.0.0", - "notistack": "^1.0.3", + "notistack": "^2.0.5", "np": "^7.2.0", "npm-run-all": "^4.1.5", "pino": "^6.9.0", @@ -94,8 +93,9 @@ "react-dom": "^17.0.1", "react-draggable": "^4.4.3", "react-hot-loader": "^4.13.0", - "react-resizable": "^1.11.0", + "react-resizable": "^3.0.4", "react-scroll-to-bottom": "^4.1.0", + "sass": "^1.54.3", "sass-loader": "^10.1.0", "scrollparent": "^2.0.1", "semver": "^7.3.4", @@ -105,7 +105,7 @@ "tailwindcss": "^2.0.2", "terser-webpack-plugin": "^5.0.3", "twin.macro": "^2.0.7", - "typescript": "^4.1.3", + "typescript": "4.7.4", "uuid": "^8.3.2", "webpack": "^5.10.1", "webpack-cli": "^4.2.0", @@ -122,5 +122,8 @@ "*.jsx": "eslint", "*.ts": "eslint --ext .ts", "*.tsx": "eslint --ext .tsx" + }, + "engines": { + "node": ">=16.0.0" } } diff --git a/scripts/webserver.js b/scripts/webserver.js index 56cc7c4..b6496e7 100755 --- a/scripts/webserver.js +++ b/scripts/webserver.js @@ -1,10 +1,10 @@ process.env.ASSET_PATH = '/' -const WebpackDevServer = require('webpack-dev-server'), - webpack = require('webpack'), - config = require('../webpack.config'), - env = require('./env'), - path = require('path') +const WebpackDevServer = require('webpack-dev-server') +const webpack = require('webpack') +const config = require('../webpack.config') +const env = require('./env') +const path = require('path') const options = { notHotReload: ['contentScript'], diff --git a/src/common/api.ts b/src/common/api.ts index d4d54a7..36e3fc1 100644 --- a/src/common/api.ts +++ b/src/common/api.ts @@ -17,7 +17,7 @@ class Client { if (error.response) { const { data, status } = error.response - if (data.message) { + if (data?.message) { error.message = `${data.message} (${status})` } } @@ -31,7 +31,6 @@ class Client { .post( '/v2/translate', qs.stringify({ - auth_key: this.apiToken, target_lang: targetLang, split_sentences: '1', preserve_formatting: '0', @@ -39,7 +38,8 @@ class Client { }), { headers: { - 'content-type': 'application/x-www-form-urlencoded;charset=utf-8', + 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8', + Authorization: `DeepL-Auth-Key ${this.apiToken}`, }, responseType: 'json', }, @@ -49,12 +49,10 @@ class Client { private getAPI(): string { switch (this.region) { - case 'global': - return 'https://a-translator-api-cf.nerdynerd.org' - case 'dev': - return 'http://localhost:1337' + case 'free': + return 'https://api-free.deepl.com' default: - return 'https://a-translator-api.nerdynerd.org' + return 'https://api.deepl.com' } } } diff --git a/src/common/constant.ts b/src/common/constant.ts index f99245b..877e053 100644 --- a/src/common/constant.ts +++ b/src/common/constant.ts @@ -1,15 +1,33 @@ export const supportedLanguages = { ZH: '中文', - 'EN-US': 'English (American)', - 'EN-GB': 'English (British)', - JA: '日本語', + BG: 'Bulgarian', + CS: 'Czech', + DA: 'Danish', DE: 'German', - FR: 'French', + EL: 'Greek', + 'EN-GB': 'English (British)', + 'EN-US': 'English (American)', ES: 'Spanish', - 'PT-PT': 'Portuguese', - 'PT-BR': 'Portuguese (Brazilian)', + ET: 'Estonian', + FI: 'Finnish', + FR: 'French', + HU: 'Hungarian', IT: 'Italian', + JA: 'Japanese', + LT: 'Lithuanian', + LV: 'Latvian', NL: 'Dutch', PL: 'Polish', + 'PT-PT': 'Portuguese', + 'PT-BR': 'Portuguese (Brazilian)', + RO: 'Romanian', RU: 'Russian', + SK: 'Slovak', + SL: 'Slovenian', + SV: 'Swedish', +} + +export const supportedRegions = { + default: 'DeepL Pro', + free: '免费', } diff --git a/src/pages/Background/common/ocr-client.ts b/src/common/ocr-client.ts similarity index 86% rename from src/pages/Background/common/ocr-client.ts rename to src/common/ocr-client.ts index 944defe..ebe256f 100644 --- a/src/pages/Background/common/ocr-client.ts +++ b/src/common/ocr-client.ts @@ -2,6 +2,17 @@ import defaultsDeep from 'lodash-es/defaultsDeep' import { SHA256, HmacSHA256, enc } from 'crypto-js' import axios from 'axios' +export const OcrRegions = { + 'ap-shanghai': '华东地区(上海)', + 'ap-beijing': '华北地区(北京)', + 'ap-guangzhou': '华南地区(广州)', + 'ap-hongkong': '港澳台地区(中国香港)', + 'ap-seoul': '亚太东北(首尔)', + 'ap-singapore': '亚太东南(新加坡)', + 'na-toronto': '北美地区(多伦多)', +} +export type OcrRegionKeys = keyof typeof OcrRegions + export class TcRequestError extends Error { code?: string @@ -16,7 +27,7 @@ export class OcrClient { private config: { secretId: string secretKey: string - region: string + region: OcrRegionKeys } private requestConfig = { host: 'ocr.tencentcloudapi.com', @@ -31,7 +42,11 @@ export class OcrClient { signedHeaders: 'content-type;host', } - constructor(config: { secretId: string; secretKey: string; host?: string }) { + constructor(config: { + secretId: string + secretKey: string + region?: OcrRegionKeys + }) { this.config = defaultsDeep({}, config, { region: 'ap-shanghai', }) @@ -94,9 +109,10 @@ export class OcrClient { }) } - private signPayload( - payload: Record, - ): { authorization: string; timestamp: number } { + private signPayload(payload: Record): { + authorization: string + timestamp: number + } { const hashedRequestPayload = SHA256(JSON.stringify(payload)) const canonicalRequest = [ this.requestConfig.httpRequestMethod, diff --git a/src/common/types.ts b/src/common/types.ts index 2a30ca9..b972b16 100644 --- a/src/common/types.ts +++ b/src/common/types.ts @@ -1,4 +1,5 @@ -import { supportedLanguages } from './constant' +import { supportedLanguages, supportedRegions } from './constant' +import { OcrRegionKeys } from './ocr-client' export interface Config { token: string @@ -6,12 +7,14 @@ export interface Config { region: APIRegions ocrSecretId?: string ocrSecretKey?: string + ocrRegion?: OcrRegionKeys hoverButton?: boolean } export type SupportLanguageKeys = keyof typeof supportedLanguages +export type SupportRegionKeys = keyof typeof supportedRegions -export type APIRegions = 'default' | 'global' | 'dev' +export type APIRegions = 'default' | 'free' export type TranslateResult = { translations: Array<{ diff --git a/src/manifest.json b/src/manifest.json index 9bd5d56..6a86675 100755 --- a/src/manifest.json +++ b/src/manifest.json @@ -1,5 +1,5 @@ { - "name": "A Translator", + "name": "DeepL Translate", "permissions": [ "http://*/*", "https://*/*", @@ -19,7 +19,7 @@ "default_icon": { "128": "icon-128.png" }, - "default_title": "A Translator" + "default_title": "DeepL Translate" }, "icons": { "128": "icon-128.png" diff --git a/src/pages/Background/common/server.ts b/src/pages/Background/common/server.ts index fbf41e3..6b63b65 100644 --- a/src/pages/Background/common/server.ts +++ b/src/pages/Background/common/server.ts @@ -4,7 +4,7 @@ import { createServer } from 'connect.io' import Client from '../../../common/api' import logger from '../../../common/logger' import { Config } from '../../../common/types' -import { OcrClient } from './ocr-client' +import { OcrClient } from '../../../common/ocr-client' import { Handler } from './types' import { cropImage } from './utils' @@ -107,6 +107,7 @@ const onOCR: Handler<{ const client = new OcrClient({ secretId: config.ocrSecretId, secretKey: config.ocrSecretKey, + region: config.ocrRegion, }) const data = await client.request({ dataUrl: payload.dataUrl }) diff --git a/src/pages/Background/index.ts b/src/pages/Background/index.ts index 6257bfd..abd8c32 100644 --- a/src/pages/Background/index.ts +++ b/src/pages/Background/index.ts @@ -68,7 +68,7 @@ chrome.commands.onCommand.addListener(function (command) { chrome.contextMenus.create({ id: 'ate', - title: 'A Translator', + title: 'DeepL Translate', contexts: ['page'], }) diff --git a/src/pages/Content/components/App/index.tsx b/src/pages/Content/components/App/index.tsx index a0b787a..c2698cb 100644 --- a/src/pages/Content/components/App/index.tsx +++ b/src/pages/Content/components/App/index.tsx @@ -189,7 +189,7 @@ const App: React.FC = () => {
- A Translator + DeepL Translate {enableOCR ? ( { const [region, setRegion] = useState('default') const [ocrSecretId, setOCRSecretId] = useState('') const [ocrSecretKey, setOCRSecretKey] = useState('') + const [ocrRegion, setOCRRegion] = useState('ap-shanghai') const [hoverButton, setHoverButton] = useState(true) const { enqueueSnackbar } = useSnackbar() @@ -36,6 +43,7 @@ const Options: React.FC = () => { region, ocrSecretId, ocrSecretKey, + ocrRegion, hoverButton, }) @@ -71,6 +79,7 @@ const Options: React.FC = () => { if (config.ocrSecretId !== undefined) setOCRSecretId(config.ocrSecretId) if (config.ocrSecretKey !== undefined) setOCRSecretKey(config.ocrSecretKey) + if (config.ocrRegion !== undefined) setOCRRegion(config.ocrRegion) if (config.hoverButton !== undefined) setHoverButton(config.hoverButton) }) }, []) @@ -108,9 +117,12 @@ const Options: React.FC = () => { onSubmit={onSubmit} tw="flex flex-col justify-between flex-1 overflow-hidden">
- + - + + + + + { /> - - - -
@@ -168,6 +185,25 @@ const Options: React.FC = () => { />
+
+ +
+
可不填,填入后可使用 OCR 识别文字翻译。
@@ -188,15 +224,6 @@ const Options: React.FC = () => {