Socket
Socket
Sign inDemoInstall

node-dict

Package Overview
Dependencies
118
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.3 to 1.1.0

.npmgitignore

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc