-
Notifications
You must be signed in to change notification settings - Fork 0
/
searcher-c2e.html
87 lines (83 loc) · 4.07 KB
/
searcher-c2e.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="res/css/style.css" />
<title>Search Result</title>
<meta charset="UTF-8" />
<meta http-equiv="Content-Type" content="text/html" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimal-ui" />
<script>
if (typeof module === 'object') {
window.module = module; module = undefined;
}
</script><!-- 解决electron环境下jQuery缺失问题 -->
<script src="js/jquery-3.3.1.min.js"></script>
<script src="js/md5.min.js"></script>
<script src="js/barCtrl.js"></script>
<script src="js/copyCommand.js"></script>
<script>
var ipc = require('electron').ipcRenderer;
ipc.send('window-dict');//调整尺寸
$(document).ready(function () {
var Mousetrap = require('mousetrap');
Mousetrap.bind(['command+b', 'ctrl+b'], function () {
ipc.send("back-home");
// return false to prevent default browser behavior
// and stop event from bubbling
return false;
});
$("#detail").css("display", "block");
s = location.search.substr(1);
a = s.split('&');
var wordUse = '';
for (i in a) {
b = a[i].split('=');
wordUse = b[1];
}
wordUse = decodeURI(wordUse);
if (wordUse.length > 30) document.getElementById("detail").innerHTML = "<br/><h2>对不起,您输入的单词长度超限。</h2><h3><a href='index.html' class='backLink'>返回</a> | 您是打算 <a href='translator.html?word=" + decodeURI(wordIn) + "' class='backLink'>翻译</a> 吗?</h3>";
else {
const request = require('request');
const cheerio = require('cheerio');
const ipc2 = require('electron').ipcRenderer;
request.get({ url: 'https://cn.bing.com/dict/search?q=' + encodeURI(wordUse) }, function (error, response, body) {
if (body) {
const $ = cheerio.load(body);
if ($('div #crossid').html()) {
document.getElementById("detail").innerHTML = "<span id='wordTitle'>" + wordUse + "</span>" + $('div #crossid').html();
} else {
document.getElementById("detail").innerHTML = "<h3>对不起,找不到对应的英文单词。<br/><br/><a href='index.html' class='backLink'>返回</a> | 您是打算 <a href='translator.html?word=" + wordUse + "' class='backLink'>翻译</a> 吗?</h3>";
}
} else {
document.getElementById("detail").innerHTML = "<h3>对不起,发生了错误。<br/>请检查网络和代理设置。如果此问题一直出现,请联系项目开发者。不过这也可能是我们正在使用的必应服务器错误。</h3>";
}
$("#detail").css("height", "216px")
$(".se_d").css("display", "none");
$(".p1-12").each(function () {
$(this).attr("href", "searcher-e2c.html?word=" + $(this).text());
});//优化显示效果
});
}
});
</script>
</head>
<body id="body">
<div id="logo"><a href="index.html"><img src="res/icons/previous.png" width="40px" height="40px" alt="返回首页" /></a>
</div>
<div id="bar">
<div id="btn">
<a href="javascript:minimize()"><img src="res/icons/minimize.png" alt="最小化" /></a>
<a href="javascript:window.close()"><img src="res/icons/close.png" alt="关闭窗口" /></a>
</div>
</div>
<div id="detailbox">
<div id="detail">
<br />
<h2>等待服务器响应...</h2>
<h3><a href="javascript:history.back(-1)" class="backLink">返回</a></h3>
<!-- 动态加入内容 -->
</div>
</div>
<br />
</body>
</html>