node-dict
Advanced tools
Comparing version 1.0.3 to 1.1.0
74
index.js
@@ -5,41 +5,43 @@ var request = require("request"); | ||
var out = process.stdout; | ||
var word = encodeURI(Array.prototype.slice.call(process.argv, 2).join(' ')); | ||
var dotCount = 0; | ||
var word = Array.prototype.slice.call(process.argv, 2).join(' '); | ||
var search = function (w) { | ||
return 'http://cn.bing.com/dict/search?q=' + encodeURI(w); | ||
}; | ||
var f = setInterval(function () { | ||
++dotCount; | ||
out.clearLine(); | ||
out.cursorTo(0); | ||
out.write(color.green('正在查询' + '.'.repeat(dotCount))); | ||
}, 300); | ||
request({ | ||
url: search(word), | ||
headers: { | ||
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.3 (KHTML, like Gecko) Version/8.0 Mobile/12A4345d Safari/600.1.4', | ||
'Referer': 'http://cn.bing.com/dict/' | ||
} | ||
}, function (error, response, body) { | ||
clearInterval(f); | ||
if (!error && response.statusCode == 200) { | ||
var $ = cheerio.load(body); | ||
var headword = $("#headword"); | ||
var dictList = ["bing", "youdao"]; /// 对应lib文件夹的文件名 | ||
(function crawl(i) { | ||
var dotCount = 0; | ||
var option = require('./lib/' + dictList[i]); | ||
var f = setInterval(function() { | ||
++dotCount; | ||
if (dotCount > 3) { | ||
dotCount = 1; | ||
} | ||
out.clearLine(); | ||
out.cursorTo(0); | ||
if (headword.length === 0) { | ||
return console.log(color.cyan('抱歉,没有查询到')); | ||
out.write(color.green('正在使用 ' + option.name + ' 查询' + '.'.repeat(dotCount))); | ||
}, 1000); | ||
request({ | ||
url: option.url(word), | ||
headers: option.headers || {}, | ||
timeout: 5000 | ||
}, function(error, response, body) { | ||
clearInterval(f); | ||
if (!error && response.statusCode == 200) { | ||
out.clearLine(); | ||
out.cursorTo(0); | ||
var $ = cheerio.load(body); | ||
var data = option.action($); | ||
if (typeof data === 'string') { | ||
i < dictList.length - 1 ? crawl(++i) : console.log(color.cyan(data)); | ||
} else { | ||
data.map(function(item, index) { | ||
if (index === 0) { | ||
console.log(color.wrap(item, color.colors.BLUE, color.styles.hi_background)); | ||
} else { | ||
console.log(color.wrap(item[0], color.colors.YELLOW, color.styles.background), item[1]); | ||
} | ||
}); | ||
} | ||
} else { | ||
i < dictList.length - 1 ? crawl(++i) : console.log(color.red('查询失败', true)); | ||
} | ||
console.log(color.wrap(headword.text(), color.colors.BLUE, color.styles.hi_background)); | ||
headword.parent().next().children().each(function () { | ||
var type = color.wrap($(this).children().eq(0).text(), color.colors.YELLOW, color.styles.background); | ||
var explanation = $(this).children().eq(1).text(); | ||
console.log(type, explanation); | ||
}); | ||
} else { | ||
console.log(color.red('查询失败', true)); | ||
} | ||
}); | ||
}); | ||
})(0); |
{ | ||
"name" : "node-dict", | ||
"version" : "1.0.3", | ||
"version" : "1.1.0", | ||
"description" : "cmd dict", | ||
@@ -5,0 +5,0 @@ "bin" : { |
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
6148
9
0
90