Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: more friendly error message & caught rejected promise #317

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = crlf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = false
49 changes: 24 additions & 25 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
# compiled output
/dist
/tmp
/out-tsc

# dependencies
/node_modules

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace

# Web store zip
*.zip
*.json

# JS Beautify
.jsbeautifyrc

# for Mac
.DS_Store
# compiled output
/dist
/tmp
/out-tsc

# dependencies
/node_modules

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace

# Web store zip
*.zip

# JS Beautify
.jsbeautifyrc

# for Mac
.DS_Store
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "es5",
"tabWidth": 4,
"semi": true,
"singleQuote": true
}
121 changes: 62 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,59 +1,62 @@
# Online Dictionary Helper (with Anki support)

[[中文版说明](README.zh_CN.md)]

Online Dictionary Helper is a Chrome/Firefox extension to show definitions for words and phrases from online (or builtin) dictionary via users' selection on any webpage and PDF documents (using [pdf.js](https://mozilla.github.io/pdf.js/)), which also supports flash-card creation using [Anki](https://github.com/dae/anki) (with **[AnkiConnect](https://github.com/FooSoft/anki-connect)**, an Anki add-on, installed).

Details on the reasons for making this extension can be found in the [background](doc/background.md) introduction if you are interested.

![Anki Notes](https://raw.githubusercontent.com/ninja33/ODH/master/doc/img/anki_001_640x400.png)

What might set this extension apart is that users can grab online dictionary content with their own customized script (running under extension development mode). For development details, please check the [development guide](doc/development.md).

## How to use

- [Install from Chrome Web Store](https://chrome.google.com/webstore/detail/anki-online-dictionary-he/lppjdajkacanlmpbbcdkccjkdbpllajb?hl=en)

- [Install from Firefox Add-ons](https://addons.mozilla.org/en-US/firefox/addon/online-dictionary-helper/)

1. Install the extension first from Chrome Web Store or Firefox Add-ons, then configure and activate the extension on your demands in the options page.
2. Open any webpage, move your mouse cursor over the word that you want to select and translate, drag and select/double-click/press **Hotkey** (defined in options page) to select the word or phrase.
3. If the word or phrase is a clickable link, use the predefined **Hotkey** or hold the <kbd>Alt</kbd> key while selecting to translate.
4. A popup window will show up above the selection displaying the word definition.
5. (Optional) While Anki and AnkiConnect are installed and running, go to the `Services Options` tab in the options page to setup the Anki deck, type, and field names to put your **expression**, **sentence**, **reading**, **definition**, etc.
6. (Optional) Press the green **(+)** button on the top right corner of each definition in the popup window to add the word or phrase to Anki as a note.

## The Options Page

The options of this extension are divided into three sections.

1. General Options
- Enabled: Turn the extension on/off.
- AutoSel.Hotkey: Configure the **Hotkey** to select words or phrases. Four options are available: Off(Disable the hotkey), <kbd>Shift</kbd>, <kbd>Ctrl</kbd>, and <kbd>Alt</kbd> key.
- Max.Context: Set the maximum number of sentences extracted from the context of the webpage.
- Max.Example: Set the maximum number of example sentences from the dictionary (requires support of the dictionary script).

2. AnkiConnect Options: Setup Anki deck/type name, and which note fields you are going to put **expression**, **sentence**, **reading**, **definition**, etc.

3. Dictionary Options:
- Dictionary Script: Input your own script name here, and click <kbd>Load Script</kbd> button to load it.
- Selected Dictionary: Choose the dictionary (bultin or loaded) for the definitions on your preference.

![Options Page](https://raw.githubusercontent.com/ninja33/ODH/master/doc/img/option_general_640x400_en.png)

## Development
### Getting started
The source code of this extension on Github does not contain offline dictionary and English word deformation table data. You can go to the Chrome Web Store to download, or use a Chrome extension downloader to download the plugin's crx file and extract the dictionary JSON file.

### Use existing script or develop by yourself

1. You can use existing dictionary scripts in the [dictionaries list](doc/scriptlist.md).
2. Or develop the script by yourself based on [development guide](doc/development.md).
3. Or open an [issue](https://github.com/ninja33/ODH/issues) in this repo if you really need help.

### Pull request

Pull requests are welcome if you want to enhance this extension, or submit your own dictionary script in the next release.

- The extension source will go to [/src](https://github.com/ninja33/ODH/tree/master/src)
- The dictionary script will go to [/src/dict](https://github.com/ninja33/ODH/tree/master/src/dict)
# Online Dictionary Helper (with Anki support)

[[中文版说明](README.zh_CN.md)]

Online Dictionary Helper is a Chrome/Firefox extension to show definitions for words and phrases from online (or builtin) dictionary via users' selection on any webpage and PDF documents (using [pdf.js](https://mozilla.github.io/pdf.js/)), which also supports flash-card creation using [Anki](https://github.com/dae/anki) (with **[AnkiConnect](https://github.com/FooSoft/anki-connect)**, an Anki add-on, installed).

Details on the reasons for making this extension can be found in the [background](doc/background.md) introduction if you are interested.

![Anki Notes](https://raw.githubusercontent.com/ninja33/ODH/master/doc/img/anki_001_640x400.png)

What might set this extension apart is that users can grab online dictionary content with their own customized script (running under extension development mode). For development details, please check the [development guide](doc/development.md).

## How to use

- [Install from Chrome Web Store](https://chrome.google.com/webstore/detail/anki-online-dictionary-he/lppjdajkacanlmpbbcdkccjkdbpllajb?hl=en)

- [Install from Firefox Add-ons](https://addons.mozilla.org/en-US/firefox/addon/online-dictionary-helper/)

1. Install the extension first from Chrome Web Store or Firefox Add-ons, then configure and activate the extension on your demands in the options page.
2. Open any webpage, move your mouse cursor over the word that you want to select and translate, drag and select/double-click/press **Hotkey** (defined in options page) to select the word or phrase.
3. If the word or phrase is a clickable link, use the predefined **Hotkey** or hold the <kbd>Alt</kbd> key while selecting to translate.
4. A popup window will show up above the selection displaying the word definition.
5. (Optional) While Anki and AnkiConnect are installed and running, go to the `Services Options` tab in the options page to setup the Anki deck, type, and field names to put your **expression**, **sentence**, **reading**, **definition**, etc.
6. (Optional) Press the green **(+)** button on the top right corner of each definition in the popup window to add the word or phrase to Anki as a note.

## The Options Page

The options of this extension are divided into three sections.

1. General Options

- Enabled: Turn the extension on/off.
- AutoSel.Hotkey: Configure the **Hotkey** to select words or phrases. Four options are available: Off(Disable the hotkey), <kbd>Shift</kbd>, <kbd>Ctrl</kbd>, and <kbd>Alt</kbd> key.
- Max.Context: Set the maximum number of sentences extracted from the context of the webpage.
- Max.Example: Set the maximum number of example sentences from the dictionary (requires support of the dictionary script).

2. AnkiConnect Options: Setup Anki deck/type name, and which note fields you are going to put **expression**, **sentence**, **reading**, **definition**, etc.

3. Dictionary Options:
- Dictionary Script: Input your own script name here, and click <kbd>Load Script</kbd> button to load it.
- Selected Dictionary: Choose the dictionary (bultin or loaded) for the definitions on your preference.

![Options Page](https://raw.githubusercontent.com/ninja33/ODH/master/doc/img/option_general_640x400_en.png)

## Development

### Getting started

The source code of this extension on Github does not contain offline dictionary and English word deformation table data. You can go to the Chrome Web Store to download, or use a Chrome extension downloader to download the plugin's crx file and extract the dictionary JSON file.

### Use existing script or develop by yourself

1. You can use existing dictionary scripts in the [dictionaries list](doc/scriptlist.md).
2. Or develop the script by yourself based on [development guide](doc/development.md).
3. Or open an [issue](https://github.com/ninja33/ODH/issues) in this repo if you really need help.

### Pull request

Pull requests are welcome if you want to enhance this extension, or submit your own dictionary script in the next release.

- The extension source will go to [/src](https://github.com/ninja33/ODH/tree/master/src)
- The dictionary script will go to [/src/dict](https://github.com/ninja33/ODH/tree/master/src/dict)
125 changes: 63 additions & 62 deletions README.zh_CN.md
Original file line number Diff line number Diff line change
@@ -1,62 +1,63 @@
# 在线词典助手 (含Anki制卡功能)

在线词典助手是一个Chrome插件。用于浏览网页时查询在线词典,并将查询内容显示在单词旁的小弹窗里。该工具同时支持Anki制卡功能(需在Anki上安装**ankiconnect**插件).

有关制作该工具的缘由细节,详情可见[背景](doc/background.zh_CN.md)介绍。

![Anki Notes](https://raw.githubusercontent.com/ninja33/ODH/master/doc/img/anki_001_640x400.png)

本词典助手支持加载脚本,以扩展插件功能抓取更多的网页词典(插件以开发者模式运行)。有关开发细节,详情可见 [开发指南](doc/development.zh_CN.md)

## 使用说明

- [Chrome插件下载链接](https://chrome.google.com/webstore/detail/anki-online-dictionary-he/lppjdajkacanlmpbbcdkccjkdbpllajb?hl=en)

- [Firefox扩展下载链接](https://addons.mozilla.org/en-US/firefox/addon/online-dictionary-helper/)

1. 从Chrome商店或者Firefox扩展页下载安装插件后,从选项页激活插件。
2. 打开任意想要取词翻译的网页,将鼠标放在单词上,拖动选择或者双击选择该单词。
3. 如果单词本身是一个链接不宜点击,可按**取词热键**(在选项中设定)自动选取单词。
4. 根据选项中所选词典,一个含释义的弹窗将会显示在上述选中单词的旁边。
5. (可选操作) 在Ankiconnect已经安装,并且Anki已经打开的情况下,可在选项页设定Anki牌组名称、模板名称,以及用于放置 **单词字段**、**音标字段**、**额外字段**、**释义字段**、**原句字段**的字段名称。
6. (可选操作) 在上述弹窗中,点击每个释义右上角的绿色**(+)**图标,可进行Anki制卡。

## 详细选项设定

本插件的选项主要分为三个部分:

1. 通用选项:
- 启用关闭:用于开启和关闭插件。
- 取词热键:用于设定自动选取单词的热键,有四个选项。off:关闭热键、shift键、ctrl键和alt键。
- 最大原句数量:用于设定从文章上下文中摘取的最大原句数量。
- 最大例句数量:用于设定词典中例句的显示数量(需该词典脚本支持)。
2. Anki选项:
当Anki和Ankiconnect插件都已安装并打开时,插件会从Anki中获取你的牌组模板列表,并显示如下选项。
- 牌组名称:牌组名称的下拉列表,用于选择制卡所需**牌组名称**名称。
- 模板名称:模板名称的下拉列表,用于选择制卡所需**模板名称**名称。
- 单词字段名称:上述模板所含的字段列表,用于选择放置**单词字段**的字段名称。
- 音标字段名称:上述模板所含的字段列表,用于选择放置**音标字段**的字段名称。
- 额外字段名称:上述模板所含的字段列表,用于选择放置**额外字段**的字段名称。
- 释义字段名称:上述模板所含的字段列表,用于选择放置**释义字段**的字段名称。
- 原句字段名称:上述模板所含的字段列表,用于选择放置**原句字段**的字段名称。
- 当前Anki状态:显示当前Anki连接状态和Ankiconnect版本号。

3. 词典选项:

- 脚本地址: 在此处可输入脚本地址,并点击**加载脚本**按钮加载。加载后可在下方词典列表中选择新加载词典。
- 当前词典: 显示所有插件内置和外部加载的词典名称,用于选择当前划词翻译所用词典。

![Options Page](https://raw.githubusercontent.com/ninja33/ODH/master/doc/img/option_general_640x400.png)

## 使用其他脚本

1. 你可以选择预制的脚本,详见[[脚本清单](doc/scriptlist.md)]。
2. 也可以自行开发并加载,详见[[开发指南](doc/development.md)]。
3. 如有任何问题和想法,你也可以提交[[issue](https://github.com/ninja33/ODH/issues)]。

## Pull request

如果你想提交词典脚本或者改进插件本身,欢迎PR。

- 插件代码 [[/src](https://github.com/ninja33/ODH/tree/master/src)]。
- 脚本代码 [[/src/dict](https://github.com/ninja33/ODH/tree/master/src/dict)]。
# 在线词典助手 (含Anki制卡功能)

在线词典助手是一个Chrome插件。用于浏览网页时查询在线词典,并将查询内容显示在单词旁的小弹窗里。该工具同时支持Anki制卡功能(需在Anki上安装**ankiconnect**插件).

有关制作该工具的缘由细节,详情可见[背景](doc/background.zh_CN.md)介绍。

![Anki Notes](https://raw.githubusercontent.com/ninja33/ODH/master/doc/img/anki_001_640x400.png)

本词典助手支持加载脚本,以扩展插件功能抓取更多的网页词典(插件以开发者模式运行)。有关开发细节,详情可见 [开发指南](doc/development.zh_CN.md)

## 使用说明

- [Chrome插件下载链接](https://chrome.google.com/webstore/detail/anki-online-dictionary-he/lppjdajkacanlmpbbcdkccjkdbpllajb?hl=en)

- [Firefox扩展下载链接](https://addons.mozilla.org/en-US/firefox/addon/online-dictionary-helper/)

1. 从Chrome商店或者Firefox扩展页下载安装插件后,从选项页激活插件。
2. 打开任意想要取词翻译的网页,将鼠标放在单词上,拖动选择或者双击选择该单词。
3. 如果单词本身是一个链接不宜点击,可按**取词热键**(在选项中设定)自动选取单词。
4. 根据选项中所选词典,一个含释义的弹窗将会显示在上述选中单词的旁边。
5. (可选操作) 在Ankiconnect已经安装,并且Anki已经打开的情况下,可在选项页设定Anki牌组名称、模板名称,以及用于放置 **单词字段**、**音标字段**、**额外字段**、**释义字段**、**原句字段**的字段名称。
6. (可选操作) 在上述弹窗中,点击每个释义右上角的绿色**(+)**图标,可进行Anki制卡。

## 详细选项设定

本插件的选项主要分为三个部分:

1. 通用选项:
- 启用关闭:用于开启和关闭插件。
- 取词热键:用于设定自动选取单词的热键,有四个选项。off:关闭热键、shift键、ctrl键和alt键。
- 最大原句数量:用于设定从文章上下文中摘取的最大原句数量。
- 最大例句数量:用于设定词典中例句的显示数量(需该词典脚本支持)。
2. Anki选项:
当Anki和Ankiconnect插件都已安装并打开时,插件会从Anki中获取你的牌组模板列表,并显示如下选项。

- 牌组名称:牌组名称的下拉列表,用于选择制卡所需**牌组名称**名称。
- 模板名称:模板名称的下拉列表,用于选择制卡所需**模板名称**名称。
- 单词字段名称:上述模板所含的字段列表,用于选择放置**单词字段**的字段名称。
- 音标字段名称:上述模板所含的字段列表,用于选择放置**音标字段**的字段名称。
- 额外字段名称:上述模板所含的字段列表,用于选择放置**额外字段**的字段名称。
- 释义字段名称:上述模板所含的字段列表,用于选择放置**释义字段**的字段名称。
- 原句字段名称:上述模板所含的字段列表,用于选择放置**原句字段**的字段名称。
- 当前Anki状态:显示当前Anki连接状态和Ankiconnect版本号。

3. 词典选项:

- 脚本地址: 在此处可输入脚本地址,并点击**加载脚本**按钮加载。加载后可在下方词典列表中选择新加载词典。
- 当前词典: 显示所有插件内置和外部加载的词典名称,用于选择当前划词翻译所用词典。

![Options Page](https://raw.githubusercontent.com/ninja33/ODH/master/doc/img/option_general_640x400.png)

## 使用其他脚本

1. 你可以选择预制的脚本,详见[[脚本清单](doc/scriptlist.md)]。
2. 也可以自行开发并加载,详见[[开发指南](doc/development.md)]。
3. 如有任何问题和想法,你也可以提交[[issue](https://github.com/ninja33/ODH/issues)]。

## Pull request

如果你想提交词典脚本或者改进插件本身,欢迎PR。

- 插件代码 [[/src](https://github.com/ninja33/ODH/tree/master/src)]。
- 脚本代码 [[/src/dict](https://github.com/ninja33/ODH/tree/master/src/dict)]。
Loading