-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.html
264 lines (242 loc) · 7.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
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="referrer" content="origin" />
<title>Bing每日一图</title>
<link href="./resource/bing_logo.ico" rel="shortcut icon"/>
</head>
<body style="margin:0;padding:0; background: #999999">
<div>
<img id="wallpaper"/>
</div>
<div style="position: fixed; bottom: 0px; left: 0px;">
<p id="copyright" style="max-width:400px; margin-left:20px; margin-bottom:30px; color:white; font-size:18px;"></p>
<p id="date" style="max-width:400px; margin-left:20px; margin-bottom:30px; color:white; font-size:12px;"></p>
</div>
<div id="load" style="position: fixed; bottom: 0px; left: 40%; visibility:hidden">
<img id="loaing" src="./resource/loading.gif"/>
<p id="tips" style="color:#DFDFDF; font-size:30px;"></p>
</div>
<div style="position: fixed; top: 40%;">
<img id="pre" onclick="preClick()" onmousedown="preDown()" onmouseup="preUp()" src="./resource/previous.svg" alt="Previous Wallpaper" />
</div>
<div style="position: fixed; top: 40%; right:0px">
<img id="next" onclick="nextClick()" onmousedown="nextDown()" onmouseup="nextUp()" src="./resource/next.svg" alt="Next Wallpaper" />
</div>
</body>
</html>
<script type="text/javascript">
function getQueryString(name) {
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null) {
return unescape(r[2]);
}
}
function getAndSet(key) {
var value = getQueryString(key);
if (value == undefined || value == '' || value == null) {
value = localStorage.getItem(key);
} else {
localStorage.setItem(key, value);
}
return value;
}
function request(url, success, failure) {
var httpRequest = new XMLHttpRequest();
httpRequest.open('GET', url, true);
httpRequest.send();
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState == 4) {
if (httpRequest.status == 200) {
var json = httpRequest.responseText;
success(json);
} else {
failure(httpRequest.status);
}
}
};
}
function getApiUrl(region, year, month, day) {
if (region == undefined || region == '' || region == null) {
region = 'zh-CN';
}
var url = './api/' + region + '/' + year + '/' + month + '/' + year + '-' + month + '-' + day + '.json';
return url;
}
function resizeWindow(){
//var winWidth = document.body.clientWidth;
//var winHeight = document.body.clientHeight;
var winWidth = document.documentElement.clientWidth;
var winHeight = document.documentElement.clientHeight;
var wallpaper = document.getElementById('wallpaper');
var imgWidth = 1080;
var imgHeight = 1920;
wallpaper.width = winWidth;
wallpaper.height = winHeight;
}
function preClick() {
if (!isLoading) {
startLoading();
var preDate = new Date(date.getTime() - ONE_DAY);
tmpDate = preDate;
var preYear = preDate.getFullYear();
var preMonth = preDate.getMonth()+1;
if (preMonth < 10) {
preMonth = '0' + preMonth;
}
var preDay = preDate.getDate();
if (preDay < 10) {
preDay = '0' + preDay;
}
var url = getApiUrl(region, preYear, preMonth, preDay);
request(url, success, failure);
}
}
function preDown() {
var pre = document.getElementById('pre');
pre.src = "./resource/previous-down.svg";
}
function preUp() {
var pre = document.getElementById('pre');
pre.src = "./resource/previous.svg";
}
function nextClick() {
if (!isLoading) {
startLoading();
var nextDate = new Date(date.getTime() + ONE_DAY);
tmpDate = nextDate;
var nextYear = nextDate.getFullYear();
var nextMonth = nextDate.getMonth()+1;
if (nextMonth < 10) {
nextMonth = '0' + nextMonth;
}
var nextDay = nextDate.getDate();
if (nextDay < 10) {
nextDay = '0' + nextDay;
}
var url = getApiUrl(region, nextYear, nextMonth, nextDay);
request(url, success, failure);
}
}
function nextDown() {
var next = document.getElementById('next');
next.src = "./resource/next-down.svg";
}
function nextUp() {
var next = document.getElementById('next');
next.src = "./resource/next.svg";
}
function endLoading() {
isLoading = false;
}
function startLoading() {
isLoading = true;
var load = document.getElementById('load');
load.style.visibility = 'visible';
loading();
}
function loading() {
var tips = document.getElementById('tips');
if (isLoading) {
loadCount = loadCount % 7;
tips.innerText = LOADING_TIPS.substr(0, LOADING_TIPS.length - 6 + loadCount);
loadCount ++;
setTimeout(loading, 100);
} else {
var load = document.getElementById('load');
load.style.visibility = 'hidden';
tips.innerText = LOADING_TIPS;
loadCount = 0;
}
}
function success(json) {
var apiObj = JSON.parse(json);
var wallpaper = document.getElementById('wallpaper');
if (type == 'bingtmp') {
wallpaper.src = apiObj.image.bingtmb;
} else if (type == 'binghd') {
wallpaper.src = apiObj.image.binghd;
} else if (type == 'hd') {
wallpaper.src = '.' + apiObj.image.hd;
} else {
wallpaper.src = '.' + apiObj.image.tmb;
}
var copyright = document.getElementById('copyright');
copyright.innerText = apiObj.copyright;
var tdate = document.getElementById('date');
var tYear = apiObj.date.substr(0, 4);
var tMonth = apiObj.date.substr(4, 2);
var tDay = apiObj.date.substr(6, 2);
tdate.innerText = tYear + "-" + tMonth + "-" + tDay;
date = tmpDate;
localStorage.setItem('date', date.getTime());
var pre = document.getElementById('pre');
pre.style.visibility = 'visible';
var next = document.getElementById('next');
next.style.visibility = 'visible';
endLoading();
};
function failure(code) {
if (code == 404) {
if (date.getTime() == tmpDate.getTime()) {
var fDate = new Date(date.getTime() - ONE_DAY);
tmpDate = fDate;
var fYear = fDate.getFullYear();
var fMonth = fDate.getMonth()+1;
if (fMonth < 10) {
fMonth = '0' + fMonth;
}
var fDay = fDate.getDate();
var url = getApiUrl(region, fYear, fMonth, fDay);
request(url, success, failure);
} else if (date.getTime() > tmpDate.getTime()) {
var pre = document.getElementById('pre');
pre.style.visibility = 'hidden';
var wallpaper = document.getElementById('wallpaper');
//wallpaper.src = './resource/404.jpg';
} else {
var next = document.getElementById('next');
next.style.visibility = 'hidden';
var wallpaper = document.getElementById('wallpaper');
//wallpaper.src = './resource/404.jpg';
}
}
endLoading();
};
</script>
<script type="text/javascript">
var loadCount = 0;
var ONE_DAY = 24*60*60*1000;
var LOADING_TIPS = 'Bing wallpaper loding......';
var isLoading = false;
var region = getQueryString('region');
var type = getQueryString('type');
var date;
var dateTime = getQueryString('date');
if (dateTime == undefined || dateTime == '' || dateTime == null) {
date = new Date()
} else {
date = new Date(parseInt(dateTime));
}
var tmpDate = date;
var year = date.getFullYear();
var month = date.getMonth() + 1;
if (month < 10) {
month = '0' + month;
}
var day = date.getDate();
if (day < 10) {
day = '0' + day;
}
var url = getApiUrl(region, year, month, day);
request(url, success, failure);
startLoading();
document.documentElement.style.overflow='hidden';
document.body.style.overflow='hidden';
//window.addEventListener('resize', resizeWindow)
resizeWindow();
window.onresize = resizeWindow;
</script>