-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathindex.html
348 lines (288 loc) · 10.5 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="viewport" content="width=device-width,initial-scale=0.5, maximum-scale=0.5, minimum-scale=0.5, user-scalable=no">
<meta name="x5-fullscreen" content="true">
<meta name="full-screen" content="yes">
<title>Super Dictionary</title>
<link rel="stylesheet" href="lib/bootstrap-4.0.0-dist/css/bootstrap.min.css">
<style>
.logo {
width: 60%;
height: 500px;
margin: auto;
}
.name {
text-align: center;
font-size: 66px;
text-shadow: 3px 5px grey, 1px 1px #333;
}
.img {
width: 48%;
height: 53%;
margin: auto;
margin-top: 38px;
}
.img img {
width: 100%;
height: 100%;
}
.search {
width: 80%;
height: 100px;
margin: auto;
}
.noExtension {
width: 60%;
height: 100px;
margin: auto;
font-size: 23px;
}
#search_value {
width: 80%;
height: 50px;
box-shadow: 3px 5px grey, 1px 1px #333;
}
.search button {
width: 18%;
height: 50px;
margin-left: 6px;
box-shadow: 3px 5px grey, 1px 1px #333;
}
@keyframes rotate {
0% { transform:rotateY(0deg);}
25% { transform:rotateY(180deg);}
50% { transform:rotateY(0deg);}
75% { transform:rotateY(180deg);}
100% { transform:rotateY(0deg);}
}
.logo_rotate {
/*
animation: rotate 10s infinite;
animation-fill-mode: forwards;
animation-timing-function: linear;
*/
/* 当动画结束时,让<div>元素保留上一个关键帧的样式值 */
}
.result_success {
width: 60%;
margin: auto;
font-size: 22px
}
.result_faile{
width: 60%;
margin: auto;
font-size: 22px
}
.add_banner{
width: 80%;
margin: auto;
}
.add_banner input{
width: 80%;
height: 50px;
box-shadow: 3px 5px grey, 1px 1px #333;
}
.add_banner button{
width: 18%;
height: 50px;
margin-left: 6px;
box-shadow: 3px 5px grey, 1px 1px #333;
}
#search_banner{
font-size: 50px;
border-bottom: 1px solid black;
}
p{
text-indent:2em;
font-size: 30px;
}
.hide{
display: none;
}
.contenner{
background: url("img/bg.jpg");
height: 1500px;
}
.author{
text-align: right;
}
.author p{
display: inline-block;
font-size: 18px;
}
</style>
</head>
<body>
<div class="contenner">
<div class="logo">
<div class="name">SUPER DICTIONARY</div>
<div class="img logo_rotate">
<img src="img/logo.png" alt="">
</div>
</div>
<div class="noExtension hide" id="noExtension">
NOTE: Please install <a target="_blank" href="https://github.com/ChengOrangeJu/WebExtensionWallet">WebExtensionWallet</a> to use SUPER DICTIONARY
</div>
<div class="search">
<input id="search_value" type="text">
<button id=search>search</button>
</div>
<div class="result_success hide">
<div id=search_banner></div>
<p id=search_result> wait for content </p>
<div class="author">
<i><p> Author:</p> <p id=search_result_author> dasdajkajksdhjasdkjahdkjad</p></i>
</div>
</div>
<div class="result_faile hide">
Failed to find related information. Do you want to <button id="add">add</button> infromation for "<i id="result_faile_add">asd</i>"?
</div>
<div class="add_banner hide">
<input type="text" id="add_value" placeholder="input contents for your keyword">
<button id="push">submit</button>
</div>
</div>
<script src=lib/jquery-3.3.1.min.js></script>
<script src=lib/nebPay.js></script>
<script src=lib/bootstrap-4.0.0-dist/js/bootstrap.min.js></script>
<script src=lib/nebulas.js></script>
<script>
"use strict";
// $("#search_value").attr("disabled",true)
// $("#search").attr("disabled",true)
// //to check if the extension is installed
// //if the extension is installed, var "webExtensionWallet" will be injected in to web page
// if(typeof(webExtensionWallet) === "undefined"){
// //alert ("Extension wallet is not installed, please install it first.")
// $("#noExtension").removeClass("hide")
// }else{
// $("#search_value").attr("disabled",false)
// $("#search").attr("disabled",false)
// }
var dappAddress = "n1oXdmwuo5jJRExnZR5rbceMEyzRsPeALgm";
//here we use neb.js to call the "get" function to search from the Dictionary
var nebulas = require("nebulas"),
Account = nebulas.Account,
neb = new nebulas.Neb();
neb.setRequest(new nebulas.HttpRequest("https://testnet.nebulas.io"));
// 搜索功能: 查找Super-Dictionary 中有没有该词条
$("#search").click(function(){
// $("#search_value").val() 搜索框内的值
var from = Account.NewAccount().getAddressString();
var value = "0";
var nonce = "0"
var gas_price = "1000000"
var gas_limit = "2000000"
var callFunction = "get";
//var callArgs = "[\"" + $("#search_value").val() + "\"]"; //in the form of ["args"]
var arg = $("#search_value").val()
var callArgs = JSON.stringify([arg]); //推荐用 JSON.stringify 来生成参数字符串,这样会避免出错!
var contract = {
"function": callFunction,
"args": callArgs
}
neb.api.call(from,dappAddress,value,nonce,gas_price,gas_limit,contract).then(function (resp) {
cbSearch(resp)
}).catch(function (err) {
//cbSearch(err)
console.log("error:" + err.message)
})
})
//return of search,
function cbSearch(resp) {
var result = resp.result ////resp is an object, resp.result is a JSON string
console.log("return of rpc call: " + JSON.stringify(result))
var resultString = JSON.stringify(result);
if(resultString.search("key") !== -1 && resultString.search("value") !== -1){
result = JSON.parse(result)
$(".add_banner").addClass("hide");
$(".result_faile").addClass("hide");
$("#search_banner").text($("#search_value").val())
$("#search_result").text(result.value)
$("#search_result_author").text(result.author)
$(".result_success").removeClass("hide");
}
if(resultString.search('"null"') !== -1){
$(".add_banner").addClass("hide");
$(".result_success").addClass("hide");
$("#result_faile_add").text($("#search_value").val())
$(".result_faile").removeClass("hide");
}
if(resultString.search("error") !== -1){
$(".add_banner").addClass("hide");
$(".result_faile").addClass("hide");
$("#search_banner").text($("#search_value").val())
$("#search_result").text(result)
$("#search_result_author").text("")
$(".result_success").removeClass("hide");
}
}
// 添加信息功能: 像super-dictionary 中添加词条
$("#add").click(function() {
$(".result_faile").addClass("hide");
$(".add_banner").removeClass("hide");
$("#add_value").val("")
})
var NebPay = require("nebpay"); //https://github.com/nebulasio/nebPay
var nebPay = new NebPay();
var serialNumber
//var callbackUrl = NebPay.config.mainnetUrl; //如果合约在主网,则使用这个
var callbackUrl = NebPay.config.testnetUrl; //
$("#push").click(function() {
clearInterval(intervalQuery);
//console.log("clear intervalQuery=" + intervalQuery)
var to = dappAddress;
var value = "0";
var callFunction = "save"
//var callArgs = "[\"" + $("#search_value").val() + "\",\"" + $("#add_value").val() + "\"]"
var arg1 = $("#search_value").val(),
arg2 = $("#add_value").val();
var callArgs = JSON.stringify([arg1, arg2]);
serialNumber = nebPay.call(to, value, callFunction, callArgs, { //使用nebpay的call接口去调用合约,
listener: cbPush, //设置listener, 处理交易返回信息
callback: callbackUrl
});
intervalQuery = setInterval(function () {
//console.log("querying intervalQuery=" + intervalQuery)
funcIntervalQuery();
}, 6000);
});
var intervalQuery
function funcIntervalQuery() {
var options = {
callback: callbackUrl
}
nebPay.queryPayInfo(serialNumber,options) //search transaction result from server (result upload to server by app)
.then(function (resp) {
console.log("tx result: " + resp) //resp is a JSON string
var respObject = JSON.parse(resp)
if(respObject.code === 0 && respObject.data.status !== 2){
clearInterval(intervalQuery);
//console.log("clear intervalQuery=" + intervalQuery)
if(respObject.data.status === 1)
alert(`Saving {${$("#search_value").val()} : ${$("#add_value").val()}} into super-dictionary successfully!`);
else if(respObject.data.status === 0){
alert(`Saving ${$("#search_value").val()} into super-dictionary failed!\n"${respObject.data.execute_error}"`);
}
}
})
.catch(function (err) {
console.log(err);
});
}
function cbPush(resp) {
console.log("response of push: " + JSON.stringify(resp))
var respString = JSON.stringify(resp);
if(respString.search("rejected by user") !== -1){
clearInterval(intervalQuery)
alert(respString)
}else if(respString.search("txhash") !== -1){
//alert("wait for tx result: " + resp.txhash)
}
}
</script>
</body>
</html>