Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
youngdze committed Jan 18, 2016
2 parents 4f479cc + 8e8991a commit cd8f98f
Show file tree
Hide file tree
Showing 24 changed files with 582 additions and 206 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["es2015", "stage-0"]
}
72 changes: 72 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
## 参考 http://eslint.org/docs/user-guide/configuring
---
env:
browser: true
node: true
es6: true
ecmaFeatures:
arrowFunctions: true
binaryLiterals: true
blockBindings: true
classes: true
defaultParams: true
destructuring: true
forOf: true
generators: true
modules: true
objectLiteralComputedProperties: true
objectLiteralDuplicateProperties: true
objectLiteralShorthandMethods: true
objectLiteralShorthandProperties: true
octalLiterals: true
regexUFlag: true
regexYFlag: true
spread: true
superInFunctions: true
templateStrings: true
unicodeCodePointEscapes: true
globalReturn: true
jsx: true
rules:
# 应用撇号``,不使用时不报错
quotes:
- 0
- "backtick"
- "avoid-escape"
# 警告多空格
no-multi-spaces:
- 1
-
exceptions:
Property: true
# 警告对象内多空格
key-spacing:
- 0
-
align: "colon"
# 警告无逗号结尾
semi:
- 1
- "always"
# 允许逻辑语句单行
brace-style:
- 2
- "1tbs"
-
allowSingleLine: true
# 允许逻辑语句无大括号
curly:
- 1
- "multi"
# 支持 alert, confirm, prompt
no-alert: 0
# 警告未定义使用
no-use-before-define: 1
# 允许 constructor 首字母小写
new-cap: 1

no-unused-expressions: 0
no-unused-vars: 1
consistent-return: 0
eqeqeq: 1
no-mixed-spaces-and-tabs: 1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ logs
node_modules
.idea
build
bin
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# YoudaoDict

```shell
npm install
npm run build
```

自制有道词典 Chrome 扩展,使用[有道词典 api](http://fanyi.youdao.com/openapi)

## 安装
Expand All @@ -15,17 +10,24 @@ npm run build
## 开发

```shell
npm install
npm run dev
```

在 Chrome 扩展页面点击载入开发中的扩展,选择 `build` 目录。

## Test

```shell
npm run test
```

## 功能

* 点击扩展图标输入进行翻译
* 双击或按 Ctrl 对选择区域进行翻译
* 双击或按设置的按键(默认为 CTRL)对选择区域进行翻译
* 添加生词至有道单词本

## 版权
## 版权 LICENSE

* DO WHATEVER YOU WANT
* MIT
57 changes: 57 additions & 0 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'use strict';

import gulp from 'gulp';
import jade from 'gulp-jade';
import mocha from 'gulp-mocha';
import rimraf from 'gulp-rimraf';
import imagemin from 'gulp-imagemin';
import pngquant from 'imagemin-pngquant';
import webpack from 'webpack-stream';
import webpackConf from './webpack.config.js';

const NODE_ENV = process.env.NODE_ENV || 'dev';

gulp.task('clean', () => {
gulp.src('build/**/*.map', {read: false}).pipe(rimraf({force: true}));
});

gulp.task('move', () => {
gulp.src('manifest.json').pipe(gulp.dest('build'));
gulp.src('src/lib/**/*.js').pipe(gulp.dest('build/lib'));
});

gulp.task('jade', () => {
gulp.src(['src/tpl/popup.jade', 'src/tpl/options.jade'])
.pipe(jade())
.pipe(gulp.dest('build'));
});

gulp.task('imagemin', () => {
gulp.src('src/img/icon.png')
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngquant()]
}))
.pipe(gulp.dest('build/img'));
});

gulp.task('webpack', () => {
gulp.src('./src/script/*.js')
.pipe(webpack(webpackConf))
.pipe(gulp.dest('build'));
});

gulp.task('mocha', () => {
gulp.src('./test/**/*.js', {read: false})
.pipe(mocha({reporter: 'nyan'}));
});

gulp.task('default', ['move', 'jade', 'imagemin', 'webpack'], () => {
gulp.watch(['./manifest.json'], ['move']);
gulp.watch(['./src/tpl/*.jade'], ['jade']);
gulp.watch(['./src/tpl/*.jade', './src/style/*.scss', './src/script/**/*.js'], ['webpack']);
});

gulp.task('build', ['clean', 'move', 'jade', 'imagemin', 'webpack']);
gulp.task('test', ['mocha']);
48 changes: 0 additions & 48 deletions gulpfile.js

This file was deleted.

2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"name": "Youdao Dict",
"description": "有道词典 Chrome 扩展",
"version": "0.2.4",
"version": "0.2.5",

"icons": {
"16": "img/icon.png",
Expand Down
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,32 @@
"homepage": "https://github.com/youngdze/YoudaoDict#readme",
"scripts": {
"dev": "NODE_ENV=dev gulp",
"build": "NODE_ENV=production gulp"
"build": "NODE_ENV=production gulp build",
"webdriver": "java -jar bin/selenium-server-standalone.jar",
"test": "NODE_ENV=test gulp test"
},
"devDependencies": {
"babel-core": "^6.3.26",
"babel-core": "^6.4.0",
"babel-loader": "^6.2.0",
"babel-polyfill": "^6.3.14",
"babel-preset-es2015": "^6.3.13",
"babel-preset-stage-0": "^6.3.13",
"chai": "^3.4.1",
"css-loader": "^0.23.1",
"file-loader": "^0.8.5",
"gulp": "^3.9.0",
"gulp-imagemin": "^2.4.0",
"gulp-jade": "^1.1.0",
"gulp-mocha": "^2.2.0",
"gulp-rimraf": "^0.2.0",
"imagemin-pngquant": "^4.2.0",
"jade": "^1.11.0",
"jade-loader": "^0.8.0",
"node-fetch": "^1.3.3",
"node-sass": "^3.4.2",
"sass-loader": "^3.1.2",
"style-loader": "^0.13.0",
"webpack": "^1.12.9",
"webpack": "^1.12.11",
"webpack-stream": "^3.1.0"
}
}
47 changes: 24 additions & 23 deletions src/script/background.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
"use strict";

{
let defaultOptions = {
dblclick: true,
ctrl: true
};
let defaultOptions = {
dblclick: true,
shortcut: true,
shortcut1: 17,
shortcut2: null,
wordbook: false
};

let addYoudaoDict = function(tab) {
chrome.tabs.executeScript(tab.id, {
file: "js/popover.js",
allFrame: true
});
chrome.tabs.insertCSS(tab.id, {
file: "css/popover.css",
allFrame: true
});
};
let addYoudaoDict = function(tab) {
chrome.tabs.executeScript(tab.id, {
file: "js/popover.js",
allFrame: true
});
chrome.tabs.insertCSS(tab.id, {
file: "css/popover.css",
allFrame: true
});
};

let init = function(details) {
if (Object.is(details.reason, 'install')) {
chrome.storage.sync.set(defaultOptions);
// chrome.tab.query({}, (tabs) => tabs.forEach(addYoudaoDict));
}
};
let init = function(details) {
if (Object.is(details.reason, 'install')) {
chrome.storage.sync.set(defaultOptions);
// chrome.tab.query({}, (tabs) => tabs.forEach(addYoudaoDict));
}
};

chrome.runtime.onInstalled.addListener(init);
}
chrome.runtime.onInstalled.addListener(init);
Loading

0 comments on commit cd8f98f

Please sign in to comment.