Skip to content

Commit b33959d

Browse files
committed
feat: add option jump to vocabulary.com for toast clicking
1 parent d6ce592 commit b33959d

File tree

8 files changed

+49
-18
lines changed

8 files changed

+49
-18
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module.exports = {
2121
'no-unused-vars': 'off',
2222
'no-new': 'off',
2323
'no-undef': 'off',
24+
'comma-dangle': 'off',
2425
// allow debugger during development
2526
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
2627
},

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dadda-translate",
3-
"version": "1.2.16",
3+
"version": "1.2.17",
44
"description": "translate and remember",
55
"scripts": {
66
"dev": "node_modules/.bin/webpack --progress --config build/webpack.dev.js",

src/api/host.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const SHANBAY_HOST = 'http://www.shanbay.com/api/v1'
66

77
// dictionary.com 查询 HOST
88
export const DICTIONARY_HOST = 'http://fanyi.sogou.com/#auto/zh-CHS/'
9+
export const VOCABULARY_HOST = 'https://www.vocabulary.com/dictionary/'
910

1011
// 词根字典查询 HOST
1112
export const CGDICT_HOST = 'http://www.cgdict.com/index.php?app=cigen&ac=word&w='

src/changelog-breif.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@
2727
"1.2.13": "修复 '+' 号无法翻译的问题",
2828
"1.2.14": "暂时:无法呼出时弹出搜狗验证窗口,下个版本更换翻译源 🤪",
2929
"1.2.15": "当搜狗不可用时降级为谷歌",
30-
"1.2.16": "修复谷歌只翻译一句话的问题"
30+
"1.2.16": "修复谷歌只翻译一句话的问题",
31+
"1.2.17": "新增点击吐司跳转到 vocabulary.com 查看释义的选项,建议开启"
3132
}

src/chrome/background/background.js

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Toast from '@/chrome/toast'
99
import setNewAlarm from '@/chrome/alarm'
1010

1111
import { _removeTRId, _hasTRId, _wrapTRId, _sleep } from '@/utils'
12-
import { DICTIONARY_HOST, SOGOU_HOST } from '@/api/host'
12+
import { DICTIONARY_HOST, SOGOU_HOST, VOCABULARY_HOST } from '@/api/host'
1313
import {
1414
DELAY_MINS_IN_EVERY_STAGE,
1515
TR_SETTING_HAS_TOAST_KEY,
@@ -27,7 +27,8 @@ import {
2727
TR_SETTING_LASTING_TOAST,
2828
TR_SETTING_CALLOUT_INPUT,
2929
TR_SETTING_HIDE_CONTEXT_MENU_OPTION,
30-
TR_SETTING_CLOSE_ALL_TOAST_KEY
30+
TR_SETTING_CLOSE_ALL_TOAST_KEY,
31+
TR_SETTING_USE_VOCABULARYCOM,
3132
} from '@/utils/constant'
3233

3334
import HotReload from './hot-reload'
@@ -49,7 +50,7 @@ const detectGo = () => {
4950
Storage.get(TR_SETTING_IS_DIRECTLY_KEY, false).then(isDirectly => {
5051
chrome.browserAction.setBadgeText({ text: isDirectly ? 'go' : '' })
5152
chrome.browserAction.setBadgeBackgroundColor({
52-
color: isDirectly ? '#ed559d' : '#fff'
53+
color: isDirectly ? '#ed559d' : '#fff',
5354
})
5455
})
5556
}
@@ -88,7 +89,7 @@ chrome.runtime.onInstalled.addListener(async reason => {
8889
message: require('@/changelog-breif.json')[version] || '点击查看更新内容',
8990
requireInteraction: true,
9091
priority: 2,
91-
eventTime: Date.now() + 100000
92+
eventTime: Date.now() + 100000,
9293
})
9394
detectGo()
9495
}
@@ -186,7 +187,7 @@ chrome.runtime.onMessage.addListener((request, sender, sendRes) => {
186187
case 'jumpToSogou': {
187188
// Request is considered as a spider
188189
chrome.tabs.create({
189-
url: 'https://fanyi.sogou.com'
190+
url: 'https://fanyi.sogou.com',
190191
})
191192
return true
192193
}
@@ -209,7 +210,12 @@ chrome.alarms.onAlarm.addListener(async alarm => {
209210
if (_hasTRId(alarm.name) && toastLock) {
210211
const word = _removeTRId(alarm.name)
211212

212-
Toast(word, 'Look the meanings in Sougou')
213+
const useVocabularyCom = await Storage.get(
214+
TR_SETTING_USE_VOCABULARYCOM,
215+
false
216+
)
217+
218+
Toast(word, `Click to see more`)
213219
}
214220
})
215221

@@ -271,14 +277,27 @@ chrome.notifications.onButtonClicked.addListener(async (notiId, btnId) => {
271277
*/
272278
chrome.notifications.onClicked.addListener(async notiId => {
273279
if (notiId === 'updateInfo') {
280+
const path = chrome.runtime.getURL(`options/options.html#link=setting`)
281+
274282
chrome.tabs.create({
275-
url: 'https://github.com/waynecz/dadda-translate-crx/releases'
283+
url: path,
276284
})
277285
}
278286

279287
if (_hasTRId(notiId)) {
280288
const word = _removeTRId(notiId)
281-
chrome.tabs.create({ url: `${DICTIONARY_HOST}${encodeURI(word)}` })
289+
290+
const useVocabularyCom = await Storage.get(
291+
TR_SETTING_USE_VOCABULARYCOM,
292+
false
293+
)
294+
295+
if (useVocabularyCom) {
296+
chrome.tabs.create({ url: `${VOCABULARY_HOST}${encodeURI(word)}` })
297+
} else {
298+
chrome.tabs.create({ url: `${DICTIONARY_HOST}${encodeURI(word)}` })
299+
}
300+
282301
moveWord2NextStage(word)
283302
const isLasting = await Storage.get(TR_SETTING_LASTING_TOAST, false)
284303

@@ -303,10 +322,10 @@ Storage.get(TR_SETTING_HIDE_CONTEXT_MENU_OPTION, false).then(value => {
303322
code:
304323
"document.dispatchEvent(new CustomEvent('contextMenuClick', { bubbles: true, detail: { text: \"" +
305324
info.selectionText +
306-
'" } }))'
325+
'" } }))',
307326
})
308327
}
309-
}
328+
},
310329
})
311330
}
312331
})
@@ -346,8 +365,8 @@ chrome.webRequest.onBeforeSendHeaders.addListener(
346365
{
347366
urls: [
348367
'https://fanyi.sogou.com/reventondc/translate',
349-
'https://fanyi.sogou.com/logtrace'
350-
]
368+
'https://fanyi.sogou.com/logtrace',
369+
],
351370
},
352371
['requestHeaders', 'blocking', 'extraHeaders']
353372
)

src/components/react/Setting.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import {
1919
TR_SETTING_CALLOUT_INPUT,
2020
TR_SETTING_ONLY_OXFORD,
2121
TR_SETTING_HIDE_CONTEXT_MENU_OPTION,
22-
TR_SETTING_LASTING_TOAST
22+
TR_SETTING_LASTING_TOAST,
23+
TR_SETTING_USE_VOCABULARYCOM,
2324
} from '@/utils/constant'
2425

2526
@withView
@@ -122,9 +123,14 @@ class Setting extends Component {
122123
{
123124
key: TR_SETTING_HIDE_CONTEXT_MENU_OPTION,
124125
label: '隐藏右键菜单选项',
125-
isNew: true,
126126
tip: <small className="setting_tip">开启后右键菜单内将不存在达达划词翻译</small>
127-
}
127+
},
128+
{
129+
key: TR_SETTING_USE_VOCABULARYCOM,
130+
isNew: true,
131+
label: 'vocabulary.com 作为吐司目的地',
132+
tip: <small className="setting_tip">开启后点击吐司一律跳转到<br/> vocabulary.com,纯英英解释,加强记忆</small>
133+
},
128134
]
129135
}
130136

src/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"description": "划词翻译、生词本、吐司弹词、与扇贝同步",
33
"name": "达达划词翻译",
44
"manifest_version": 2,
5-
"version": "1.2.16",
5+
"version": "1.2.17",
66
"author": "Waynecz <[email protected]>",
77
"homepage_url": "https://github.com/waynecz/dadda-translate-crx",
88
"content_security_policy": "font-src 'self' https://fonts.googleapis.com; script-src 'self' 'unsafe-eval'; object-src 'self'",

src/utils/constant.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ export const TR_SETTING_CLOSE_ALL_TOAST_KEY = '__TR_SETTING_CLOSE_ALL_TOAST_KEY_
3939
// 是否注册右键菜单
4040
export const TR_SETTING_HIDE_CONTEXT_MENU_OPTION = '__TR_SETTING_HIDE_CONTEXT_MENU_OPTION__'
4141

42+
// 点击吐司时跳转到 vocabualry.com 而不是 sogou.com
43+
export const TR_SETTING_USE_VOCABULARYCOM = '__TR_SETTING_USE_VOCABULARYCOM__'
44+
4245
// 导出内容
4346
export const TR_SETTING_EXPORT_ALL_WORDS = '__TR_SETTING_EXPORT_ALL_WORDS__'
4447

0 commit comments

Comments
 (0)