Skip to content
This repository was archived by the owner on Aug 16, 2024. It is now read-only.

Commit 653c060

Browse files
committed
Merge branch 'dev'
2 parents ee4e7bf + 72d66da commit 653c060

File tree

17 files changed

+2396
-2028
lines changed

17 files changed

+2396
-2028
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/build
2+
/release

.eslintrc.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ module.exports = {
44
node: true,
55
},
66
extends: [
7-
'prettier',
8-
'prettier/@typescript-eslint',
97
'plugin:react/recommended',
108
'plugin:react-hooks/recommended',
119
'plugin:@typescript-eslint/recommended',
10+
'plugin:prettier/recommended',
1211
],
1312
parser: '@typescript-eslint/parser',
1413
parserOptions: {
14+
project: './tsconfig.eslint.json',
1515
sourceType: 'module',
1616
},
1717
plugins: ['@typescript-eslint'],
@@ -24,4 +24,9 @@ module.exports = {
2424
'@typescript-eslint/no-var-requires': 0,
2525
'react/prop-types': 0,
2626
},
27+
settings: {
28+
react: {
29+
version: 'detect',
30+
},
31+
},
2732
}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# a-translator-chrome-extension
1+
# DeepL Translate for Chrome
22

3-
一个支持 DeepL 翻译的 Chrome 插件(需自己购买 DeepL API 计划)。
3+
Chrome DeepL 翻译插件 (需自己购买 DeepL API 计划)。
44

55
## 安装
66

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
2-
"name": "a-translator-chrome-extension",
2+
"name": "deepl-chrome-extension",
33
"version": "0.3.1",
44
"description": "DeepL translate for Chrome",
55
"license": "MIT",
66
"repository": {
77
"type": "git",
8-
"url": "https://github.com/geekdada/a-translator-chrome-extension"
8+
"url": "https://github.com/geekdada/deepl-chrome-extension"
99
},
1010
"scripts": {
1111
"start": "cross-env NODE_ENV=development node scripts/webserver.js",
1212
"build": "cross-env NODE_ENV=production webpack",
1313
"release": "run-s build && sh scripts/build.sh",
1414
"prettier": "prettier --write '**/*.{js,jsx,ts,tsx,css,html}'",
15-
"lint": "eslint --ext .ts,.tsx,.js,.jsx",
15+
"lint": "eslint . --ext .ts,.tsx,.js,.jsx",
1616
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
1717
"pub": "np --no-publish --no-release-draft",
1818
"version": "npm run changelog && git add ."
@@ -34,7 +34,7 @@
3434
"@hot-loader/react-dom": "^17.0.1",
3535
"@material-ui/core": "^4.11.2",
3636
"@tailwindcss/forms": "^0.2.1",
37-
"@types/chrome": "0.0.128",
37+
"@types/chrome": "0.0.145",
3838
"@types/crypto-js": "^4.0.1",
3939
"@types/fs-extra": "^9.0.6",
4040
"@types/lodash-es": "^4.17.4",
@@ -65,7 +65,8 @@
6565
"css-loader": "^5.0.1",
6666
"dotenv": "^8.2.0",
6767
"eslint": "^7.16.0",
68-
"eslint-config-prettier": "^7.1.0",
68+
"eslint-config-prettier": "^8.3.0",
69+
"eslint-plugin-prettier": "^3.4.0",
6970
"eslint-plugin-react": "^7.20.6",
7071
"eslint-plugin-react-hooks": "^4.1.2",
7172
"file-loader": "^6.2.0",
@@ -94,7 +95,7 @@
9495
"react-dom": "^17.0.1",
9596
"react-draggable": "^4.4.3",
9697
"react-hot-loader": "^4.13.0",
97-
"react-resizable": "^1.11.0",
98+
"react-resizable": "^3.0.4",
9899
"react-scroll-to-bottom": "^4.1.0",
99100
"sass-loader": "^10.1.0",
100101
"scrollparent": "^2.0.1",

scripts/webserver.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
process.env.ASSET_PATH = '/'
22

3-
const WebpackDevServer = require('webpack-dev-server'),
4-
webpack = require('webpack'),
5-
config = require('../webpack.config'),
6-
env = require('./env'),
7-
path = require('path')
3+
const WebpackDevServer = require('webpack-dev-server')
4+
const webpack = require('webpack')
5+
const config = require('../webpack.config')
6+
const env = require('./env')
7+
const path = require('path')
88

99
const options = {
1010
notHotReload: ['contentScript'],

src/common/api.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Client {
1717
if (error.response) {
1818
const { data, status } = error.response
1919

20-
if (data.message) {
20+
if (data?.message) {
2121
error.message = `${data.message} (${status})`
2222
}
2323
}
@@ -49,6 +49,8 @@ class Client {
4949

5050
private getAPI(): string {
5151
switch (this.region) {
52+
case 'free':
53+
return 'https://api-free.deepl.com'
5254
default:
5355
return 'https://api.deepl.com'
5456
}

src/common/constant.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
11
export const supportedLanguages = {
22
ZH: '中文',
3-
'EN-US': 'English (American)',
4-
'EN-GB': 'English (British)',
5-
JA: '日本語',
3+
BG: 'Bulgarian',
4+
CS: 'Czech',
5+
DA: 'Danish',
66
DE: 'German',
7-
FR: 'French',
7+
EL: 'Greek',
8+
'EN-GB': 'English (British)',
9+
'EN-US': 'English (American)',
810
ES: 'Spanish',
9-
'PT-PT': 'Portuguese',
10-
'PT-BR': 'Portuguese (Brazilian)',
11+
ET: 'Estonian',
12+
FI: 'Finnish',
13+
FR: 'French',
14+
HU: 'Hungarian',
1115
IT: 'Italian',
16+
JA: 'Japanese',
17+
LT: 'Lithuanian',
18+
LV: 'Latvian',
1219
NL: 'Dutch',
1320
PL: 'Polish',
21+
'PT-PT': 'Portuguese',
22+
'PT-BR': 'Portuguese (Brazilian)',
23+
RO: 'Romanian',
1424
RU: 'Russian',
25+
SK: 'Slovak',
26+
SL: 'Slovenian',
27+
SV: 'Swedish',
28+
}
29+
30+
export const supportedRegions = {
31+
default: 'DeepL Pro',
32+
free: '免费',
1533
}

src/pages/Background/common/ocr-client.ts renamed to src/common/ocr-client.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@ import defaultsDeep from 'lodash-es/defaultsDeep'
22
import { SHA256, HmacSHA256, enc } from 'crypto-js'
33
import axios from 'axios'
44

5+
export const OcrRegions = {
6+
'ap-shanghai': '华东地区(上海)',
7+
'ap-beijing': '华北地区(北京)',
8+
'ap-guangzhou': '华南地区(广州)',
9+
'ap-hongkong': '港澳台地区(中国香港)',
10+
'ap-seoul': '亚太东北(首尔)',
11+
'ap-singapore': '亚太东南(新加坡)',
12+
'na-toronto': '北美地区(多伦多)',
13+
}
14+
export type OcrRegionKeys = keyof typeof OcrRegions
15+
516
export class TcRequestError extends Error {
617
code?: string
718

@@ -16,7 +27,7 @@ export class OcrClient {
1627
private config: {
1728
secretId: string
1829
secretKey: string
19-
region: string
30+
region: OcrRegionKeys
2031
}
2132
private requestConfig = {
2233
host: 'ocr.tencentcloudapi.com',
@@ -31,7 +42,11 @@ export class OcrClient {
3142
signedHeaders: 'content-type;host',
3243
}
3344

34-
constructor(config: { secretId: string; secretKey: string; host?: string }) {
45+
constructor(config: {
46+
secretId: string
47+
secretKey: string
48+
region?: OcrRegionKeys
49+
}) {
3550
this.config = defaultsDeep({}, config, {
3651
region: 'ap-shanghai',
3752
})
@@ -94,9 +109,10 @@ export class OcrClient {
94109
})
95110
}
96111

97-
private signPayload(
98-
payload: Record<string, any>,
99-
): { authorization: string; timestamp: number } {
112+
private signPayload(payload: Record<string, any>): {
113+
authorization: string
114+
timestamp: number
115+
} {
100116
const hashedRequestPayload = SHA256(JSON.stringify(payload))
101117
const canonicalRequest = [
102118
this.requestConfig.httpRequestMethod,

src/common/types.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
import { supportedLanguages } from './constant'
1+
import { supportedLanguages, supportedRegions } from './constant'
2+
import { OcrRegionKeys } from './ocr-client'
23

34
export interface Config {
45
token: string
56
targetLang: SupportLanguageKeys
67
region: APIRegions
78
ocrSecretId?: string
89
ocrSecretKey?: string
10+
ocrRegion?: OcrRegionKeys
911
hoverButton?: boolean
1012
}
1113

1214
export type SupportLanguageKeys = keyof typeof supportedLanguages
15+
export type SupportRegionKeys = keyof typeof supportedRegions
1316

14-
export type APIRegions = 'default'
17+
export type APIRegions = 'default' | 'free'
1518

1619
export type TranslateResult = {
1720
translations: Array<{

src/manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "A Translator",
2+
"name": "DeepL Translate",
33
"permissions": [
44
"http://*/*",
55
"https://*/*",
@@ -19,7 +19,7 @@
1919
"default_icon": {
2020
"128": "icon-128.png"
2121
},
22-
"default_title": "A Translator"
22+
"default_title": "DeepL Translate"
2323
},
2424
"icons": {
2525
"128": "icon-128.png"

src/pages/Background/common/server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createServer } from 'connect.io'
44
import Client from '../../../common/api'
55
import logger from '../../../common/logger'
66
import { Config } from '../../../common/types'
7-
import { OcrClient } from './ocr-client'
7+
import { OcrClient } from '../../../common/ocr-client'
88
import { Handler } from './types'
99
import { cropImage } from './utils'
1010

@@ -107,6 +107,7 @@ const onOCR: Handler<{
107107
const client = new OcrClient({
108108
secretId: config.ocrSecretId,
109109
secretKey: config.ocrSecretKey,
110+
region: config.ocrRegion,
110111
})
111112
const data = await client.request({ dataUrl: payload.dataUrl })
112113

src/pages/Background/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ chrome.commands.onCommand.addListener(function (command) {
6868

6969
chrome.contextMenus.create({
7070
id: 'ate',
71-
title: 'A Translator',
71+
title: 'DeepL Translate',
7272
contexts: ['page'],
7373
})
7474

src/pages/Content/components/App/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ const App: React.FC = () => {
189189
<div
190190
className="ate_App__header"
191191
tw="bg-purple-800 px-5 py-3 text-white font-bold text-lg cursor-move flex justify-between items-center">
192-
<span>A Translator</span>
192+
<span>DeepL Translate</span>
193193
<span tw="flex space-x-3">
194194
{enableOCR ? (
195195
<IconButton

src/pages/Content/components/TranslationItem/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { useSnackbar } from 'notistack'
44
import { Collapse } from 'react-collapse'
55
import scrollParent from 'scrollparent'
66
import tw, { css } from 'twin.macro'
7-
import { supportedLanguages } from '../../../../common/constant'
87

8+
import { supportedLanguages } from '../../../../common/constant'
99
import logger from '../../../../common/logger'
1010
import { SupportLanguageKeys, TranslateResult } from '../../../../common/types'
1111
import IconButton from '../../../../components/IconButton'

0 commit comments

Comments
 (0)