diff --git a/README.md b/README.md
index 1021fb0..e6b17e2 100644
--- a/README.md
+++ b/README.md
@@ -1,24 +1,50 @@
# CodeVar
+
+fork 自 xudaolong 的 CodeVar
+https://github.com/xudaolong/CodeVar
+
开发基于 `Javascript`、 `alfy`、`有道翻译api`;
+# 调整
+
+1. 修复了 xudaolong/CodeVar 旧版本有道 API 无法使用问题
+2. 调整 appKey 和 key 为 al 的 env 配置
+
+# 使用
+
+1. 创建有道云 API
+ https://ai.youdao.com/console/#/service-singleton/text-translation
+
+2. 获取应用 id 和应用密钥
+ 
+
+3. 配置 workflow 环境变量(key 为应用密钥,appKey 为应用 id)
+ 
+ 
+
+4. 开始使用
+
# 依赖
-- Node.js 8+
-- Alfred 3
+
+- Node.js 8+
+- Alfred 3
# 安装
-[点击下载](https://github.com/xudaolong/CodeVar/releases)
+
+[点击下载](https://github.com/liuarui/CodeVar/releases)
# 开发趋向
-- 使用标准的缩写(如 rpt)。✔️
-- 去掉虚词 and,or,the。✔️
-- 使用名字中的每一个重要单词,最多不超过3个。❎
-- 去掉无用的后缀(如 ing、ed 等)。❎
-- 确保不要改变变量的含义。✔️
-- 不要从每个单词中删除一个字符的方式来缩写。❎
-- 缩写要一致:如果将 function 缩写成 func。那么将整个项目里,最好都统一使用这种缩写。✔️
+- 使用标准的缩写(如 rpt)。✔️
+- 去掉虚词 and,or,the。✔️
+- 使用名字中的每一个重要单词,最多不超过 3 个。❎
+- 去掉无用的后缀(如 ing、ed 等)。❎
+- 确保不要改变变量的含义。✔️
+- 不要从每个单词中删除一个字符的方式来缩写。❎
+- 缩写要一致:如果将 function 缩写成 func。那么将整个项目里,最好都统一使用这种缩写。✔️
+
+# 效果
-# 效果
> 小驼峰命名法:xt

@@ -38,14 +64,3 @@
> 中划线命名法:zh

-
-
-
-# 作者
-关注作者有更多好用的小工具哦~
-
-
-
-# 其他作品
-
-[CodeExpander](https://github.com/oncework/codeexpander) 专为开发者开发的一个集输入增强、代码片段管理(支持 Markdown)为一体跨平台云同步的开发工具。
\ No newline at end of file
diff --git a/_config.yml b/_config.yml
deleted file mode 100644
index 2f7efbe..0000000
--- a/_config.yml
+++ /dev/null
@@ -1 +0,0 @@
-theme: jekyll-theme-minimal
\ No newline at end of file
diff --git a/assets/.DS_Store b/assets/.DS_Store
deleted file mode 100644
index 5008ddf..0000000
Binary files a/assets/.DS_Store and /dev/null differ
diff --git a/assets/img/2.png b/assets/img/2.png
new file mode 100644
index 0000000..0ab61ba
Binary files /dev/null and b/assets/img/2.png differ
diff --git a/assets/img/image-1.png b/assets/img/image-1.png
new file mode 100644
index 0000000..0af3143
Binary files /dev/null and b/assets/img/image-1.png differ
diff --git a/assets/img/image.png b/assets/img/image.png
new file mode 100644
index 0000000..1195773
Binary files /dev/null and b/assets/img/image.png differ
diff --git a/cl.js b/cl.js
index fad7aa4..8f061c2 100644
--- a/cl.js
+++ b/cl.js
@@ -1,8 +1,8 @@
-'use strict';
+'use strict'
-const config = require('./src/config');
-const style = require('./src/style');
+const config = require('./src/config')
+const style = require('./src/style')
-(function () {
- style.core(config.youDaoApi,config.getParams(),style.namedConst);
-})();
\ No newline at end of file
+;(function () {
+ style.core(config.youDaoApi, config.getParams(), style.namedConst)
+})()
diff --git a/dist/CodeVar.alfredworkflow b/dist/CodeVar.alfredworkflow
index 392da96..1a6e22d 100644
Binary files a/dist/CodeVar.alfredworkflow and b/dist/CodeVar.alfredworkflow differ
diff --git a/dt.js b/dt.js
index fb0c565..d3aeb33 100644
--- a/dt.js
+++ b/dt.js
@@ -1,8 +1,8 @@
-'use strict';
+'use strict'
-const config = require('./src/config');
-const style = require('./src/style');
+const config = require('./src/config')
+const style = require('./src/style')
-(function () {
- style.core(config.youDaoApi,config.getParams(),style.bigHump);
-})();
+;(function () {
+ style.core(config.youDaoApi, config.getParams(), style.bigHump)
+})()
diff --git a/icon.png b/icon.png
index 2230c7f..0bcdeab 100644
Binary files a/icon.png and b/icon.png differ
diff --git a/info.plist b/info.plist
index a464cf4..0f86eeb 100644
--- a/info.plist
+++ b/info.plist
@@ -3,9 +3,7 @@
bundleid
- codevar
- category
- Tools
+ com.liuarui.codevar.workflow
connections
0A329E4B-AB21-41F7-A869-D878DF4EAE92
@@ -77,7 +75,7 @@
createdby
- Xudaolong
+ liuarui
description
翻译
disabled
@@ -93,6 +91,8 @@
alfredfiltersresultsmatchmode
0
+ argumenttreatemptyqueryasnil
+
argumenttrimmode
0
argumenttype
@@ -131,7 +131,7 @@
uid
7058EC8E-E2B9-4134-A85D-C92BE50493FD
version
- 2
+ 3
config
@@ -140,6 +140,8 @@
alfredfiltersresultsmatchmode
0
+ argumenttreatemptyqueryasnil
+
argumenttrimmode
0
argumenttype
@@ -178,7 +180,7 @@
uid
8039E6FB-F0FA-419B-B00E-048A1DBA460A
version
- 2
+ 3
config
@@ -187,6 +189,8 @@
clipboardtext
{query}
+ ignoredynamicplaceholders
+
transient
@@ -195,7 +199,7 @@
uid
0A329E4B-AB21-41F7-A869-D878DF4EAE92
version
- 2
+ 3
config
@@ -204,6 +208,8 @@
alfredfiltersresultsmatchmode
0
+ argumenttreatemptyqueryasnil
+
argumenttrimmode
0
argumenttype
@@ -242,7 +248,7 @@
uid
B7123C78-ADE3-48F7-A520-5BBA396F6EC9
version
- 2
+ 3
config
@@ -251,6 +257,8 @@
alfredfiltersresultsmatchmode
0
+ argumenttreatemptyqueryasnil
+
argumenttrimmode
0
argumenttype
@@ -289,7 +297,7 @@
uid
D8314C21-5801-4FB6-A5AE-7528C6AAF991
version
- 2
+ 3
config
@@ -298,6 +306,8 @@
alfredfiltersresultsmatchmode
0
+ argumenttreatemptyqueryasnil
+
argumenttrimmode
0
argumenttype
@@ -336,57 +346,74 @@
uid
D71A4F8E-5E0F-4842-8D86-FA949331C890
version
- 2
+ 3
readme
-
+ (fork自xudalong的 CodeVar)
+修复了有道切换api的问题
uidata
0A329E4B-AB21-41F7-A869-D878DF4EAE92
xpos
- 500
+ 500
ypos
- 180
+ 180
7058EC8E-E2B9-4134-A85D-C92BE50493FD
xpos
- 130
+ 130
ypos
- 20
+ 20
8039E6FB-F0FA-419B-B00E-048A1DBA460A
xpos
- 130
+ 130
ypos
- 130
+ 130
B7123C78-ADE3-48F7-A520-5BBA396F6EC9
xpos
- 130
+ 130
ypos
- 240
+ 240
D71A4F8E-5E0F-4842-8D86-FA949331C890
xpos
- 130
+ 130
ypos
- 480
+ 480
D8314C21-5801-4FB6-A5AE-7528C6AAF991
xpos
- 130
+ 130
ypos
- 350
+ 350
+ userconfigurationconfig
+
+ variables
+
+ appKey
+ 3a85ada7b66ee343
+ key
+ Cb02EXWzBIShNJvhzxymrOgBB94B78df
+
+ variablesdontexport
+
+ key
+ appKey
+
+ version
+ 1.0.0
webaddress
- https://github.com/xudaolong/CodeVar
+ https://github.com/liuarui/CodeVar
diff --git a/package.json b/package.json
index 3e99cfa..2a87bcd 100644
--- a/package.json
+++ b/package.json
@@ -1,20 +1,21 @@
{
- "name": "CodeVar",
- "version": "1.3.0",
- "description": "生成可用的代码变量 (CodeVar that return u a better variable from Chinese to English . ",
- "main": "index.js",
- "scripts": {
- "test": "echo \"Error: no test specified\" && exit 1"
- },
- "author": "xudaolong",
- "license": "ISC",
- "devDependencies": {
- "alfy": "^0.6.0"
- },
- "dependencies": {
- "lodash.difference": "^4.5.0",
- "lodash.sample": "^4.2.1",
- "lodash.union": "^4.6.0",
- "lodash.without": "^4.4.0"
- }
+ "name": "CodeVar",
+ "version": "1.3.0",
+ "description": "生成可用的代码变量 (CodeVar that return u a better variable from Chinese to English . ",
+ "main": "index.js",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "author": "liuarui",
+ "license": "ISC",
+ "devDependencies": {
+ "alfy": "^0.6.0"
+ },
+ "dependencies": {
+ "crypto-js": "^4.1.1",
+ "lodash.difference": "^4.5.0",
+ "lodash.sample": "^4.2.1",
+ "lodash.union": "^4.6.0",
+ "lodash.without": "^4.4.0"
+ }
}
diff --git a/prefs.plist b/prefs.plist
new file mode 100644
index 0000000..e75eaa4
--- /dev/null
+++ b/prefs.plist
@@ -0,0 +1,10 @@
+
+
+
+
+ appKey
+ 3a85ada7b66ee343
+ key
+ Cb02EXWzBIShNJvhzxymrOgBB94B78df
+
+
diff --git a/src/config.js b/src/config.js
index a9ba0de..a46834d 100644
--- a/src/config.js
+++ b/src/config.js
@@ -1,98 +1,44 @@
-'use strict';
+'use strict'
-const alfy = require('alfy');
-const sample = require('lodash.sample');
+const alfy = require('alfy')
+const CryptoJS = require('crypto-js')
-// 此 key 全采集于 github 上面 若有冒犯就先谢罪了啊哈...
-const FIXED_KEY = [
- {
- keyfrom: 'CoderVar',
- key: '802458398'
- },
- {
- keyfrom: 'whatMean',
- key: '1933652137'
- },
- {
- keyfrom: 'chinacache',
- key: '1247577973'
- },
- {
- keyfrom: 'huipblog',
- key: '439918742'
- },
- {
- keyfrom: 'chinacache',
- key: '1247577973'
- },
- {
- keyfrom: 'fanyi-node',
- key: '593554388'
- },
- {
- keyfrom: 'wbinglee',
- key: '1127870837'
- },
- {
- keyfrom: 'forum3',
- key: '1268771022'
- },
- {
- keyfrom: 'node-translator',
- key: '2058911035'
- },
- {
- keyfrom: 'kaiyao-robot',
- key: '2016811247'
- },
- {
- keyfrom: 'stone2083',
- key: '1576383390'
- },
- {
- keyfrom: 'myWebsite',
- key: '423366321'
- },
- {
- keyfrom: 'leecade',
- key: '54015339'
- },
- {
- keyfrom: 'github-wdict',
- key: '619541059'
- },
- {
- keyfrom: 'lanyuejin',
- key: '2033774719'
- },
-];
+function truncate(q) {
+ var len = q.length
+ if (len <= 20) return q
+ return q.substring(0, 10) + len + q.substring(len - 10, len)
+}
module.exports = {
- youDaoApi: 'http://fanyi.youdao.com/openapi.do',
+ youDaoApi: 'https://openapi.youdao.com/api',
getParams: function () {
- let selected = sample(FIXED_KEY);
+ var appKey = process.env.appKey // 需要使用自己的appkey并且开通了api功能的
+ var key = process.env.key //注意:暴露 appSecret,有被盗用造成损失的风险
+ var salt = new Date().getTime()
+ var curtime = Math.round(new Date().getTime() / 1000)
+ var query = alfy.input
+ // 多个query可以用\n连接 如 query='apple\norange\nbanana\npear'
+ var from = 'zh-CHS'
+ var to = 'en'
+ var str1 = appKey + truncate(query) + salt + curtime + key
+ var sign = CryptoJS.SHA256(str1).toString(CryptoJS.enc.Hex)
return {
query: {
- keyfrom: selected.keyfrom,
- key: selected.key,
- type: 'data',
- doctype: 'json',
- version: '1.1',
- q: alfy.input
-
- }
+ q: query,
+ appKey: appKey,
+ salt: salt,
+ from: from,
+ to: to,
+ sign: sign,
+ signType: 'v3',
+ curtime: curtime,
+ },
}
},
filter: {
- prep: [
- 'and', 'or', 'the', 'a', 'at', 'of'
- ],
+ prep: ['and', 'or', 'the', 'a', 'at', 'of'],
prefix: [],
- suffix: [
- 'ing', 'ed', 'ly'
- ],
- verb: [
- 'was'
- ]
- }
-};
\ No newline at end of file
+ suffix: ['ing', 'ed', 'ly'],
+ verb: ['was'],
+ },
+}
diff --git a/src/filter.js b/src/filter.js
index 9426b99..f66fbd9 100644
--- a/src/filter.js
+++ b/src/filter.js
@@ -1,12 +1,20 @@
-'use strict';
+'use strict'
-const config = require('./config');
-const diff = require('lodash.difference');
-const union = require('lodash.union');
+const config = require('./config')
+const diff = require('lodash.difference')
+const union = require('lodash.union')
module.exports = {
- run:function (s) {
- let strArr = s.toLowerCase();
- return diff(strArr.split(' '),union(config.filter.prep,config.filter.prefix,config.filter.suffix,config.filter.verb));
- }
-};
\ No newline at end of file
+ run: function (s) {
+ let strArr = s.toLowerCase()
+ return diff(
+ strArr.split(' '),
+ union(
+ config.filter.prep,
+ config.filter.prefix,
+ config.filter.suffix,
+ config.filter.verb
+ )
+ )
+ },
+}
diff --git a/src/style.js b/src/style.js
index f54747f..7e1cb29 100644
--- a/src/style.js
+++ b/src/style.js
@@ -1,95 +1,103 @@
-'use strict';
+'use strict'
-const alfy = require('alfy');
-const filter = require('./filter');
+const alfy = require('alfy')
+const filter = require('./filter')
module.exports = {
core: function (api, params, style) {
- alfy.fetch(api, params).then(result => {
- if (result.errorCode == 0) {
+ alfy.fetch(api, params).then((result) => {
+ if (result.errorCode == '0') {
//结果
- let result_value = [];
+ let result_value = []
// 过滤中文
- let reg = /^[a-zA-Z ]/;
+ let reg = /^[a-zA-Z ]/
// 标准翻译结果 : translation
- let result_translation = result.translation;
+ let result_translation = result.translation
for (let i = 0, len = result_translation.length; i < len; i++) {
if (reg.test(result_translation[i])) {
result_value.push({
title: style(result_translation[i]),
subtitle: `标准翻译 => ${result_translation[i]}`,
arg: style(result_translation[i]),
- });
+ })
}
}
// 网络翻译 : web
if (result.web) {
- let result_web = result.web;
+ let result_web = result.web
for (let i = 0, len = result_web.length; i < len; i++) {
- for (let j = 0, ilen = result_web[i].value.length; j < ilen; j++) {
+ for (
+ let j = 0, ilen = result_web[i].value.length;
+ j < ilen;
+ j++
+ ) {
if (reg.test(result_web[i].value[j])) {
result_value.push({
title: style(result_web[i].value[j]),
subtitle: `网络翻译 => ${result_web[i].value[j]}`,
arg: style(result_web[i].value[j]),
- });
+ })
}
}
}
}
- alfy.output(result_value);
+ alfy.output(result_value)
} else {
- alfy.output([{
- title: '抱歉',
- subtitle: `无相关记录`,
- arg: 'error',
- }]);
+ alfy.output([
+ {
+ title: '抱歉',
+ subtitle: `无相关记录`,
+ arg: 'error',
+ },
+ ])
}
- });
+ })
},
bigHump: function (s) {
- let strArr = filter.run(s);
- strArr[0] = strArr[0].charAt(0).toUpperCase() + strArr[0].substring(1);
+ let strArr = filter.run(s)
+ strArr[0] = strArr[0].charAt(0).toUpperCase() + strArr[0].substring(1)
// 单词首字母大写
for (let i = 1; i < strArr.length; i++) {
- strArr[i] = strArr[i].charAt(0).toUpperCase() + strArr[i].substring(1);
+ strArr[i] =
+ strArr[i].charAt(0).toUpperCase() + strArr[i].substring(1)
}
- return strArr.join('');
+ return strArr.join('')
},
hump: function (s) {
- let strArr = filter.run(s);
+ let strArr = filter.run(s)
// 单词首字母大写
for (let i = 1; i < strArr.length; i++) {
- strArr[i] = strArr[i].charAt(0).toUpperCase() + strArr[i].substring(1);
+ strArr[i] =
+ strArr[i].charAt(0).toUpperCase() + strArr[i].substring(1)
}
- return strArr.join('');
+ return strArr.join('')
},
namedConst: function (s) {
- let strArr = filter.run(s);
+ let strArr = filter.run(s)
for (let i = 0; i < strArr.length; i++) {
- strArr[i] = strArr[i].toUpperCase();
+ strArr[i] = strArr[i].toUpperCase()
}
- return strArr.join('_');
+ return strArr.join('_')
},
underline: function (s) {
- let strArr = filter.run(s);
+ let strArr = filter.run(s)
for (let i = 0; i < strArr.length; i++) {
- strArr[i] = strArr[i].toLowerCase();
+ strArr[i] = strArr[i].toLowerCase()
}
- return strArr.join('_');
+ return strArr.join('_')
},
underline: function (s) {
- let strArr = filter.run(s);
+ let strArr = filter.run(s)
for (let i = 0; i < strArr.length; i++) {
- strArr[i] = strArr[i].toLowerCase();
+ strArr[i] = strArr[i].toLowerCase()
}
- return strArr.join('_');
+ return strArr.join('_')
},
hyphen: function (s) {
- let strArr = filter.run(s);
+ let strArr = filter.run(s)
for (let i = 0; i < strArr.length; i++) {
- strArr[i] = strArr[i].toLowerCase();
+ strArr[i] = strArr[i].toLowerCase()
}
- return strArr.join('-');
- }
-};
\ No newline at end of file
+ return strArr.join('-')
+ },
+}
diff --git a/xh.js b/xh.js
index a5cc63a..0108379 100644
--- a/xh.js
+++ b/xh.js
@@ -1,8 +1,8 @@
-'use strict';
+'use strict'
-const config = require('./src/config');
-const style = require('./src/style');
+const config = require('./src/config')
+const style = require('./src/style')
-(function () {
- style.core(config.youDaoApi,config.getParams(),style.underline);
-})();
\ No newline at end of file
+;(function () {
+ style.core(config.youDaoApi, config.getParams(), style.underline)
+})()
diff --git a/xt.js b/xt.js
index dd1170f..aaeac6f 100644
--- a/xt.js
+++ b/xt.js
@@ -1,8 +1,8 @@
-'use strict';
+'use strict'
-const config = require('./src/config');
-const style = require('./src/style');
+const config = require('./src/config')
+const style = require('./src/style')
-(function () {
- style.core(config.youDaoApi,config.getParams(),style.hump);
-})();
\ No newline at end of file
+;(function () {
+ style.core(config.youDaoApi, config.getParams(), style.hump)
+})()
diff --git a/zh.js b/zh.js
index b4e8f2b..8be8cca 100644
--- a/zh.js
+++ b/zh.js
@@ -1,8 +1,8 @@
-'use strict';
+'use strict'
-const config = require('./src/config');
-const style = require('./src/style');
+const config = require('./src/config')
+const style = require('./src/style')
-(function () {
- style.core(config.youDaoApi,config.getParams(),style.hyphen);
-})();
\ No newline at end of file
+;(function () {
+ style.core(config.youDaoApi, config.getParams(), style.hyphen)
+})()