From 56e3dafeac2521720f2d68675330a06476695845 Mon Sep 17 00:00:00 2001 From: naoyeye Date: Tue, 24 Nov 2020 17:45:07 +0800 Subject: [PATCH] fix Nodename error, remove addWord, update REAME --- README.md | 4 ++-- package.json | 2 +- src/components/detail.js | 27 +++++++-------------------- src/components/options_app.js | 13 ++++++++----- src/content_script.js | 30 +++++++++++++++++------------- 5 files changed, 35 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index fa35492..6161377 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ - 按住(meta/ctrl)键 + 划词时翻译 - 双击划词翻译 - 快捷键`ctrl+q`打开右上角浮层,用于搜索单词 -- 搜索成功的单词可以快速加入到扇贝生词本(词库,oauth接入,需要你有扇贝的帐号)中,用于复习 +- 搜索成功的单词可以快速加入到扇贝生词本(词库,oauth接入,需要你有扇贝的帐号)中,用于复习 **因为扇贝网关闭了 API,此功能不再提供。** ## 功能介绍 @@ -39,7 +39,7 @@ chrome store上已经有很多其他词典来满足一般的英文词语意义 改扩展的数据源来源于[有道词典](http://dict.youdao.com/),但并没有通过api访问,而是直接获取页面内容再加工,理论上也就不会被api访问上线次数限制。 -### 4. 接入扇贝生词本(词库) +### 4. 接入扇贝生词本(词库)**因为扇贝网关闭了 API,此功能不再提供。** 市面上英语学习的软件不少,扇贝是其中之一。但我个人觉得扇贝是少数在探索如何将软件技术和语言学习有效地结合起来的产品之一,也是这个应用最后选择接入扇贝生词本的重要原因(虽然扇贝的“清空词库”功能是已经实现的功能,但却严格限制用户使用这一点,会让我这样只使用其中部分功能的用户非常费解)。通过生词本,我们每天多花一点时间复习今天碰到的单词。这让这个软件在教育、学习的层面上多了不少价值。 diff --git a/package.json b/package.json index 231c8d8..c091c67 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/components/detail.js b/src/components/detail.js index fd97995..3352bc9 100644 --- a/src/components/detail.js +++ b/src/components/detail.js @@ -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, @@ -128,7 +127,6 @@ function renderWordBasic( synonyms: ?SynonymsType, search: ?(word: string) => void, showWordsPage: boolean, - showNotebook: boolean, flash: () => {}, ) { const { word, pronunciation, frequence, rank, additionalPattern } = wordInfo @@ -174,15 +172,7 @@ function renderWordBasic( - {showNotebook ? ( - - - - ) : null} + {frequence ? ( {renderFrequence(frequence)} @@ -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) @@ -268,7 +258,6 @@ function renderNonCollins( null, null, Boolean(showWordsPage), - Boolean(showNotebook), flash, ) : null @@ -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) { @@ -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) @@ -386,8 +374,7 @@ Detail.propTypes = { explain: object, search: func.isRequired, openLink: func.isRequired, - showWordsPage: bool.isRequired, - showNotebook: bool.isRequired, + showWordsPage: bool.isRequired } // $FlowFixMe diff --git a/src/components/options_app.js b/src/components/options_app.js index 5c6b1bf..f8196fc 100644 --- a/src/components/options_app.js +++ b/src/components/options_app.js @@ -138,7 +138,10 @@ class App extends Component { return (
-
+
扇贝单词本设置:
{hasClearToken ? (
@@ -184,7 +187,7 @@ class App extends Component { name="showNotebook" type="radio" style={styles.radio} - checked={showNotebook} + defaultChecked={showNotebook} /> 开启
@@ -196,7 +199,7 @@ class App extends Component { name="showNotebook" type="radio" style={styles.radio} - checked={!showNotebook} + defaultChecked={!showNotebook} /> 关闭
@@ -217,7 +220,7 @@ class App extends Component { name="activeType" type="radio" style={styles.radio} - checked={activeType === type} + defaultChecked={activeType === type} /> {ACTIVE_TYPES[type]}
@@ -237,7 +240,7 @@ class App extends Component { name="showContainChinese" type="radio" style={styles.radio} - checked={showContainChinese} + defaultChecked={showContainChinese} /> 包含中文时显示翻译
diff --git a/src/content_script.js b/src/content_script.js index d1eb998..21b22fd 100644 --- a/src/content_script.js +++ b/src/content_script.js @@ -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 {