import console;
console.setTitle("按ESC退出程序")
import web.rest.jsonClient;
var http = web.rest.jsonClient();
var text = "word";
var getTranslator = function(text){
var url = "https://translator.ai.xiaomi.com/api/text";
var res = http.post(url,{text = text});
if(res[["translate"]][["res"]][["status"]][["code"]] !== 200){
return ;
}
var mean = res[["translate"]][["res"]][["data"]][["parts"]][["mean"]];
var sentence = res[["translate"]][["res"]][["data"]][["sentence"]];
return mean,sentence;
};
var printTranslator = function(mean,sentence){
if(!mean or !sentence){
return ;
}
console.open()
console.writeColorText('翻译:\n',console.color.blue)
console.log("-------------------------------------------")
for(k,v in mean){
console.log()
var s = string.map(v,`^(.*?\.)(.*?)$`);
console.writeColorText(s[[1]][1],console.color.green)
console.log(s[[1]][2])
}
console.log()
console.writeColorText('例句:\n',console.color.blue)
console.log("--------------------------------------------")
console.log()
for(k,v in sentence){
console.writeColorText("["+k+"] ",console.color.cyan)
console.log(v[["cn"]])
console.log(" "++v[["en"]])
console.log()
}
};
import key;
while(true){
if( console.kbHit() ){
console.clearScreen()
var kb = console.kbRead();
if(!kb) continue;
if( kb.wVirtualKeyCode == 0x1B/*_VK_ESC*/ ){
break;
}
else {
var text = console.getText( "请输入单词:" )
console.clearScreen()
console.log(text)
console.log("--------------------------------------------")
console.log()
if(#text>0){
printTranslator(getTranslator(text))
}
console.log("? 按任意键继续,按ESC退出程序")
}
}
}
console.pause(true);
主题数 25 | 今日评论 0 | 今日主题 0 |