Skip to content

Commit

Permalink
fix Nodename error, remove addWord, update REAME
Browse files Browse the repository at this point in the history
  • Loading branch information
naoyeye committed Nov 24, 2020
1 parent ee4b6f3 commit 56e3daf
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 41 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
- 按住(meta/ctrl)键 + 划词时翻译
- 双击划词翻译
- 快捷键`ctrl+q`打开右上角浮层,用于搜索单词
- 搜索成功的单词可以快速加入到扇贝生词本(词库,oauth接入,需要你有扇贝的帐号)中,用于复习
- <del>搜索成功的单词可以快速加入到扇贝生词本(词库,oauth接入,需要你有扇贝的帐号)中,用于复习</del> **因为扇贝网关闭了 API,此功能不再提供。**

## 功能介绍

Expand All @@ -39,7 +39,7 @@ chrome store上已经有很多其他词典来满足一般的英文词语意义

改扩展的数据源来源于[有道词典](http://dict.youdao.com/),但并没有通过api访问,而是直接获取页面内容再加工,理论上也就不会被api访问上线次数限制。

### 4. 接入扇贝生词本(词库)
### 4. <del>接入扇贝生词本(词库)</del>**因为扇贝网关闭了 API,此功能不再提供。**

市面上英语学习的软件不少,扇贝是其中之一。但我个人觉得扇贝是少数在探索如何将软件技术和语言学习有效地结合起来的产品之一,也是这个应用最后选择接入扇贝生词本的重要原因(虽然扇贝的“清空词库”功能是已经实现的功能,但却严格限制用户使用这一点,会让我这样只使用其中部分功能的用户非常费解)。通过生词本,我们每天多花一点时间复习今天碰到的单词。这让这个软件在教育、学习的层面上多了不少价值。

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "youdao-collins-chrome-extension",
"version": "1.2.2",
"version": "1.2.3",
"description": "A chrome extension to help you search english words in collins dict.",
"main": "index.js",
"scripts": {
Expand Down
27 changes: 7 additions & 20 deletions src/components/detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import Audio from './audio'
import AddWord from './add_word'
import icons from './icons'
import Tips from './tips'
import { mainBG, fontS, gapL, gapM, gapS, colorDanger,
Expand Down Expand Up @@ -128,7 +127,6 @@ function renderWordBasic(
synonyms: ?SynonymsType,
search: ?(word: string) => void,
showWordsPage: boolean,
showNotebook: boolean,
flash: () => {},
) {
const { word, pronunciation, frequence, rank, additionalPattern } = wordInfo
Expand Down Expand Up @@ -174,15 +172,7 @@ function renderWordBasic(
<span style={styles.infoItem}>
<Audio word={word} />
</span>
{showNotebook ? (
<span style={styles.infoItem}>
<AddWord
word={word}
showWordsPage={showWordsPage}
flash={flash}
/>
</span>
) : null}

{frequence ? (
<span style={Object.assign({}, styles.infoItem, { color: colorWarning })}>
{renderFrequence(frequence)}
Expand Down Expand Up @@ -259,7 +249,7 @@ function renderChoices(response: ChoiceResponseType, searchWord) {
function renderNonCollins(
currentWord, navigate,
response?: NonCollinsExplainsResponseType,
showWordsPage?: boolean, showNotebook?: boolean,
showWordsPage?: boolean,
flash: () => {},
) {
const wordBasic = (response && response)
Expand All @@ -268,7 +258,6 @@ function renderNonCollins(
null,
null,
Boolean(showWordsPage),
Boolean(showNotebook),
flash,
) : null

Expand Down Expand Up @@ -336,11 +325,10 @@ class Detail extends Component {
renderContent() {
const { flash } = this
const { search, currentWord, explain: wordResponse,
openLink, showWordsPage, showNotebook } = this.props
openLink, showWordsPage } = this.props
const openCurrentWord = openLink.bind(null, currentWord)
const renderErr = renderNonCollins.bind(null, currentWord,
openCurrentWord, undefined, showWordsPage,
showNotebook, flash,
openCurrentWord, undefined, showWordsPage, flash,
)

if (!wordResponse) {
Expand All @@ -350,13 +338,13 @@ class Detail extends Component {
const { response, type } = wordResponse

if (type === 'explain') {
return renderExplain(response, showWordsPage, showNotebook, search, flash)
return renderExplain(response, showWordsPage, search, flash)
} else if (type === 'choices') {
return renderChoices(response, search)
} else if (type === 'non_collins_explain') {
return renderNonCollins(
currentWord, openCurrentWord, response,
showWordsPage, showNotebook, flash,
showWordsPage, flash,
)
} else if (type === 'machine_translation') {
return renderMachineTranslation(response)
Expand Down Expand Up @@ -386,8 +374,7 @@ Detail.propTypes = {
explain: object,
search: func.isRequired,
openLink: func.isRequired,
showWordsPage: bool.isRequired,
showNotebook: bool.isRequired,
showWordsPage: bool.isRequired
}

// $FlowFixMe
Expand Down
13 changes: 8 additions & 5 deletions src/components/options_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ class App extends Component {

return (
<div style={styles.container}>
<div style={styles.item}>
<div
style={Object.assign({}, styles.item, {
display: 'none'
})}>
<div style={styles.itemTitle}>扇贝单词本设置:</div>
{hasClearToken ? (
<div style={styles.saveTips}>
Expand Down Expand Up @@ -184,7 +187,7 @@ class App extends Component {
name="showNotebook"
type="radio"
style={styles.radio}
checked={showNotebook}
defaultChecked={showNotebook}
/>
<span style={styles.label}>开启</span>
</div>
Expand All @@ -196,7 +199,7 @@ class App extends Component {
name="showNotebook"
type="radio"
style={styles.radio}
checked={!showNotebook}
defaultChecked={!showNotebook}
/>
<span style={styles.label}>关闭</span>
</div>
Expand All @@ -217,7 +220,7 @@ class App extends Component {
name="activeType"
type="radio"
style={styles.radio}
checked={activeType === type}
defaultChecked={activeType === type}
/>
<span style={styles.label}>{ACTIVE_TYPES[type]}</span>
</div>
Expand All @@ -237,7 +240,7 @@ class App extends Component {
name="showContainChinese"
type="radio"
style={styles.radio}
checked={showContainChinese}
defaultChecked={showContainChinese}
/>
<span style={styles.label}>包含中文时显示翻译</span>
</div>
Expand Down
30 changes: 17 additions & 13 deletions src/content_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,28 @@ function getPosition(selection) {
}

const elem = range.startContainer.firstElementChild
if (elem !== undefined) {
if (elem.nodeName === 'INPUT' || elem.nodeName === 'TEXTAREA') {
const { top, left } = elem.getBoundingClientRect()
const rectStart = getCaretCoordinates(elem, elem.selectionStart)
const rectEnd = getCaretCoordinates(elem, elem.selectionEnd)
if (!rectEnd) {
return null
}
rect = {
top: top + rectEnd.top,
left: left + rectEnd.left,
width: rectEnd.left - rectStart.left,
}

if (elem && elem !== undefined && elem.nodeName && (elem.nodeName === 'INPUT' || elem.nodeName === 'TEXTAREA')) {
const { top, left } = elem.getBoundingClientRect()
const rectStart = getCaretCoordinates(elem, elem.selectionStart)
const rectEnd = getCaretCoordinates(elem, elem.selectionEnd)

if (!rectEnd) {
return null
}
rect = {
top: top + rectEnd.top,
left: left + rectEnd.left,
width: rectEnd.left - rectStart.left,
}
} else {
rect = range.getBoundingClientRect()
}

if (!rect) {
return null
}

const { top, left, width } = rect

return {
Expand Down

0 comments on commit 56e3daf

Please sign in to comment.