-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
456 lines (405 loc) · 13.7 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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
<html>
<head>
<title>Noticer</title>
<meta charset="utf-8">
<link rel='stylesheet' href='./css/bootstrap.css' />
<link rel='stylesheet' href='./css/bootstrap-switch.css' />
<!-- <link rel='stylesheet' href='./css/flat-ui.css' /> -->
<style>
body{
width:100%;
height:100%;
overflow: hidden;
margin: 0;
padding: 0;
font-family: "微软雅黑" Vandana YaHei self;
background: #2c3e50;
color:#fff;
}
.eachPanel{
height: 300px;
width: 100%;
box-shadow:1px 2px #999;
}
.indexTitle{
height: 100%;
width: 100%;
text-align: center;
line-height: 300px;
font-size: 30px;
}
#panelWeather{
padding: 10px;
}
#fn{
padding-top: 5px;
height: 50px;
width: 100%;
text-align:center;
line-height: 50px;
}
.fnBtn{
border-radius: 0;
}
.panelTitle{
padding:5px 20px;
font-size: 20px;
}
#clock{
width: 100px;
height: 100px;
position: relative;
border-radius: 100%;
border:2px solid #fff;
margin: 0 auto;
}
#hour,#min,#second{
width: 1px;
height: 20px;
position: absolute;
bottom: 50%;
left:50%;
margin-left: -2px;
background: #fff;
-webkit-transform-origin:bottom center;
/*-webkit-transition:-webkit-transform 1s linear;*/
}
#min{
height: 30px;
}
#second{
height: 45px;
}
.clear{
clear:both;
}
#setTimer{
margin-left: 20px;
height: 30px;
}
#saveTimer{
float: right;
margin-right: 20px;
}
#chooseTimer{
margin: 10px;
}
.weahterImg{
position: absolute;
right: 20px;
top:10px;
}
#panelShow{
padding: 10px;
}
#panelShowDetail{
width: 305px;
height: 250px;
overflow: auto;
padding-top: 10px;
}
.today{
width: 100%;
height: 100%;
}
.showOne {
border-bottom: 1px dashed #999;
}
.min{
display: inline-block;
width: 65px;
line-height: 0;
}
</style>
</head>
<body>
<div id="mainPanel">
<div id="panelIndex" class="eachPanel">
<div class="indexTitle">
Daily Notice
</div>
</div>
<div id="panelWeather" class="eachPanel" style="display:none">
<div id="weatherBox" >
loading………………
</div>
<a id="refreshWeather" href="###">刷新</a>
</div>
<div id="panelTime" class="eachPanel" style="display:none">
<p class="panelTitle" >当前时间: <span id="digitalTime"></span></p>
<div id="clock">
<div id="hour"></div>
<div id="min"></div>
<div id="second"></div>
</div>
<hr/>
<span style="margin-left:10px;">设置:</span>
<div class="switch" id="setTimer" data-on="success" data-off="warning">
<input type="checkbox" checked/>
</div>
<div id="chooseTimer" >
<p>间隔时间: <input id="duration" type="text" style="width:50px;"/>小时</p>
<p class="btn btn-primary" id="saveTimer" >保存</p>
</div>
</div>
<div id="panelShow" class="eachPanel" style="display:none">
<div>
<strong>本日更新美剧</strong> (美国西部时间) :
<a id="refreshShow" href="###">刷新</a>
</div>
<div id="panelShowDetail">
loading......
</div>
</div>
<div id="panelWeibo" class="eachPanel" style="display:none">
神马也没有……
</div>
<div id="fn">
<span class="btn-lg btn btn-warning fnBtn" data="Weather">天气</span>
<span class="btn-lg btn btn-warning fnBtn" data="Time">时间</span>
<span class="btn-lg btn btn-warning fnBtn" data="Show">美剧</span>
<a class="min" href="###">最小化</a>
</div>
</div>
<script src="./js/jquery.js"></script>
<script src="./js/bootstrap.js"></script>
<script src="./js/bootstrapSwitch.js"></script>
<script src="./js/nw-desktop-notifications.js"></script>
<script type="text/javascript">
$(function(){
if(!localStorage.isTimer){
localStorage.isTimer = 0;
}
var timeTimer;
var os = require('os');
var http = require('http');
var iconv = require('iconv-lite');
var win,tray,gui;
var templete = function(html, data){
for(var key in data){
html = html.split(key).join(data[key]);
}
return html;
};
var buld = function(){
//clock
var that = {};
var pre = new Date();
var parseNum = function(ori_num){
var num = parseInt(ori_num,10);
return num<10 ? '0'+num: num;
};
var clockFn = function(){
var timer = setTimeout(function(){
var now = new Date();
_time = now.getTime() - pre.getTime();
var hour = parseInt((pre.getHours() + pre.getMinutes()/60 + pre.getMinutes()/3600 + _time/(1000*3600))*360/12);
var min =parseInt((pre.getMinutes() + pre.getSeconds()/60 + _time/(1000*60))*360/60);
var sec =parseInt((pre.getSeconds() + _time/(1000))*360/60);
$('#second').css('-webkit-transform','rotate('+sec+'deg)');
$('#min').css('-webkit-transform','rotate('+min+'deg)');
$('#hour').css('-webkit-transform','rotate('+hour+'deg)');
$('#digitalTime').html(parseNum(now.getHours())+":"+parseNum(now.getMinutes())+":"+parseNum(now.getSeconds()));
clockFn();
},1000);
};
var timerDom = function(){
var _time = localStorage.timeTimer/1000/60/60;
$('#duration').val(_time);
};
that.clock = clockFn;
that.timerDom = timerDom;
return that;
};
var bind = function(){
//panel 切换
$('.fnBtn').bind('click',function(){
var which = $(this).attr('data');
if(which){
$('.eachPanel').hide();
$('#panel'+which).show();
}
});
//set time checkbox click event
$('#setTimer input').bind('change',function(){
if($(this)[0].checked === true){
localStorage.isTimer = 1;
$('#chooseTimer').show();
}else{
localStorage.isTimer = 0;
$('#chooseTimer').hide();
}
timeTimerFn();
});
$('#saveTimer').bind('click',function(){
var timer = Number($('#duration').val());
if(!timer){
alert('请设置时间!');
return false;
}
localStorage.timeTimer = timer*60*60*1000;
timeTimerFn();
alert('设置成功!');
});
$('#refreshShow').bind('click',function(){
$('#panelShowDetail').html('loading……');
checkShow();
});
$('#refreshWeather').bind('click',function(){
$('#weatherBox').html('loading……');
checkIp();
});
$('.min').bind('click',function(){
win.minimize();
});
//最小化到系统托盘
win.on('minimize',function(){
this.hide();
//create a tray icon
tray = new gui.Tray({title:'Daily Notice',icon:'icon.jpg'});
tray.on('click',function(){
//remove the tray
this.remove();
tray = null;
//show window
win.show();
})
});
};
var timeTimerFn = function(){
if(timeTimer){
clearTimeout(timeTimer);
}
if(parseInt(localStorage.isTimer)){
timeTimer = setTimeout(function(){
//win气泡
window.LOCAL_NW.desktopNotifications.notify('desktop-notify.png', '定时提醒', '休息、休息一下', function(){
});
timeTimerFn();
},localStorage.timeTimer);
}else{
if($('#setTimer input')[0].checked === true){
$('#setTimer input').click();
$('#chooseTimer').hide();
}
}
};
var getWeather = function(city){
var options = {
host:'9snow.org',
port:null,
path:'/weather/api?city=' + city
};
var Req = http.get(options, function(res){
res.setEncoding('utf8');
var data = "";
res.on('data', function (chunk) {
data += chunk;
});
res.on('end', function() {
var weatherInfo = JSON.parse(data)['weatherinfo'];
console.log(weatherInfo);
templeteHtml = '<div class="weather-info"><div>所在城市:<strong>{#city#}</strong></div><div class="weather-show"><div class="day_weather"><span class="weather"><div>{#date#}天气:</div>{#day_weather#}</span>/<span class="temp">气温:{#day_temp#}</span><div class="temp">风力:{#day_wind#}</div></div></div><div class="weahterImg"><img src="{#weather_img#}" /></div></div>';
var _html = templete( templeteHtml, {
'{#city#}' : weatherInfo.city,
'{#date#}' : weatherInfo.date_y,
'{#day_weather#}' : weatherInfo.weather1 ,
'{#day_temp#}' : weatherInfo.temp1,
'{#day_wind#}' : weatherInfo.fl1+','+weatherInfo.wind1,
'{#weather_img#}':'./img/weather/'+weatherInfo.img1+'.png'
});
$('#weatherBox').html(_html);
});
});
Req.end();
};
var getPosition = function(ip,cb){
var options = {
host: 'int.dpool.sina.com.cn',
port: null,
path: '/iplookup/iplookup.php?format=json&ip=' + ip
}
var curtThis = this;
var req = http.get(options, function(res){
res.setEncoding('utf8');
var data = "";
res.on('data', function (chunk) {
data += chunk;
});
res.on('end', function() {
var city = JSON.parse(data)['city'];
cb(city);
});
});
req.end();
};
var checkIp = function(){
var options = {
host:'ip.qq.com',
port:80,
path:'/'
};
var html = "";
//获取ip.qq.com页面,把ip截取出来
var req = http.get(options, function(res){
res.setEncoding('binary');
res.on('data',function (data) {
html += data;
}).on('end', function () {
html=iconv.decode(new Buffer(html,'binary'), 'GBK');
var dom = $(html);
var ip=dom.find("#login_show .red").text();
if(ip.split('.').length==4){
getPosition(ip,getWeather)
}
});
});
req.end();
};
var checkShow = function(){
var options = {
host:'www.pogdesign.co.uk',
port:null,
path:'/cat/'
};
var html = "";
//获取pogdesign页面
var req = http.get(options, function(res){
res.setEncoding('binary');
res.on('data',function (data) {
html += data;
}).on('end', function () {
html=iconv.decode(new Buffer(html,'binary'), 'GBK');
var _tempDom = $(html).find(".today p");
var dom = ''
for(var i=0;i<_tempDom.length;i++){
if( i%2 ===1 ){
dom += '<p class="showOne">'+$(_tempDom[i]).text()+'</p>';
}else{
dom += '<p class="showOne text-warning">'+$(_tempDom[i]).text()+'</p>';
}
}
$('#panelShowDetail').html(dom);
});
});
req.end();
};
var init = function(){
gui = require('nw.gui');
win = gui.Window.get();
//win.showDevTools();
timeTimerFn();
checkIp();
checkShow();
};
window.onload = function(){
var bulder = buld();
bulder.clock();
bulder.timerDom();
init();
bind();
};
});
</script>
</body>
</html>