-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbing.html
126 lines (108 loc) · 2.65 KB
/
bing.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
<html>
<head>
<style>
body {
margin: 0;
background: #333;
}
#yearMonths {
font-size: 1.5rem;
display: block;
width: 150px;
margin: 30px auto 0;
}
#container {
margin: 20px 50px 50px 50px;
display: flex;
flex-direction: row;
flex-wrap: wrap;
list-style: none;
padding: 0;
}
#container > li {
width: 400px;
margin: 3px;
overflow: hidden;
}
#container > li > div {
width: 400px;
height: 225px;
box-shadow: 3px 3px 3px #000000b3;
overflow: hidden;
}
#container > li > div > a > img {
width: 100%;
transition: transform 400ms ease-out;
}
#container > li > div img:hover {
transform: scale(1.15);
}
#container > li > label {
color: #ccc;
}
</style>
</head>
<body>
<div>
<select id="yearMonths" onchange="render(this.selectedOptions[0].text);"></select>
</div>
<ul id="container"></ul>
<script src="moment.min.js"></script>
<script>
const yearMonths = [];
const $select = document.getElementById('yearMonths');
let date = moment();
while(date.isAfter('2019-03-31')) {
const option = document.createElement('option');
option.text = date.format('YYYY-MM');
$select.add(option);
date = date.subtract(1, 'months');
}
async function query(yearMonth) {
const config = {
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
}
};
const res1 = await fetch('index.json');
const res2 = await fetch('index2.json');
const res = [...res1, ...res2];
const json = await res.json();
const list = json.filter(i => i.date.slice(0, 7) == yearMonth).map(o => ({
ThumbUrl: `/bingdaily/thumbnails/${o.fileName}`,
Url: `https://www.bing.com/th?id=${o.fileName}`,
Title: o.title,
Date: o.date,
Desc: o.desc,
Copyright: o.copyright
}));
return list.reverse();
}
async function render(yearMonth) {
const images = await query(yearMonth);
const container = document.getElementById('container');
container.innerHTML = '';
images.forEach(i => {
const link = document.createElement('a');
link.href = i.Url;
const img = document.createElement('img');
img.src = i.ThumbUrl;
img.title = i.Desc;
img.alt = i.Title;
img.loading = 'lazy';
const label = document.createElement('label');
label.innerText = `${i.Date} - ${i.Title}`;
const div = document.createElement('div');
link.appendChild(img);
div.appendChild(link);
const li = document.createElement('li');
li.appendChild(div);
li.appendChild(label);
container.appendChild(li);
});
}
render($select.selectedOptions[0].text);
</script>
</body>
</html>