-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
113 lines (107 loc) · 5.14 KB
/
index.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="res/css/style.css" />
<title>yDic</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/barCtrl.js"></script>
<script>
var ipc = require('electron').ipcRenderer;
ipc.send('window-dict');//调整尺寸
var fs = require('fs');
var wordList, wLength;
fs.readFile('./res/database/words.txt', 'utf8', function (err, data) {//在编译后,务必在目录中添加res目录!!
wordList = data;
if (wordList) wLength = wordList.length;
});//单词提示api
const Store = require('electron-store');
const store = new Store();//设置数据保存
var boxVal, suggestion = "", sout = "", stemp;
var enChSource = "searcher-e2c.html", enEnSource = "searcher-e2e.html", chEnSource = "searcher-c2e.html";
$(document).ready(function () {
var defDic = store.get('defDic');
if (defDic == 'undefined' || !defDic) {
store.set('defDic', 'yd');
defDic = 'yd';
$("#searchform").attr("action", enChSource);
} else if (defDic == 'yd') {
$("#searchform").attr("action", enChSource);
$("#searchselect").val("yd");
} else if (defDic == 'mw') {
$("#searchform").attr("action", enEnSource);
$("#searchselect").val("mw");
} else {
$("#searchform").attr("action", chEnSource);
$("#searchselect").val("by");
}//默认词典设置准备工作
var autoCopyPaste = store.get('autoCopyPaste');
if (autoCopyPaste == 'undefined' || !autoCopyPaste) store.set('autoCopyPaste', 'auto');//自动复制粘贴准备工作
document.onkeyup = function () {
boxVal = $("#searchbox").val();
if (boxVal.length > 1 && wordList && $("#searchselect").val() != 'by') {//当没有输入内容时,清空提示栏
stemp = wordList.indexOf(boxVal);
sout = "";
for (var i = 0; wordList.indexOf(boxVal, stemp) != -1 && i < 4; i++) {
suggestion = "", stemp = wordList.indexOf(boxVal, stemp);
if (stemp != 0) {
if (wordList[stemp - 1] != '\n') {
stemp++;
i--;
continue;
}
}//特判,防止截取单词的一部分的情况出现
while (wordList[stemp] != '\n' && stemp < wLength) {
suggestion += wordList[stemp];
stemp++;
}
stemp++;
sout += suggestion + " ";
}
if (sout) document.getElementById("suggestions").innerHTML = "<span id='smallSpan'>输入建议:" + sout + "</span>";
} else document.getElementById("suggestions").innerHTML = "";
};//查询提示功能
});
</script>
</head>
<body>
<div id="bar">
<div id="logo"><a href="#"><img src="res/icons/yD-black.png" alt="yDic" /></a></div>
<div id="btn">
<a href="translator.html"><img src="res/icons/translate.png" alt="翻译" /></a>
<a href="settings.html"><img src="res/icons/settings.png" alt="设置" /></a>
<a href="javascript:newAboutWin()"><img src="res/icons/about.png" alt="关于" /></a>
<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="main">
<form id="searchform">
<select id="searchselect" onchange="dicTrans()">
<option value="yd">英汉</option>
<option value="mw">英英</option>
<option value="by">汉英</option>
<option value="tra">翻译</option>
</select>
<input type="text" id="searchbox" name="word" autofocus>
</form>
<br />
<div id="suggestions"></div>
</div>
<script>
function dicTrans() {
if ($("#searchselect").val() == "tra") window.location.href = "translator.html";
else if ($("#searchselect").val() == "yd") $("#searchform").attr("action", enChSource);
else if ($("#searchselect").val() == "mw") $("#searchform").attr("action", enEnSource);
else if ($("#searchselect").val() == "by") $("#searchform").attr("action", chEnSource);
}
</script>
</body>
</html>