-
Notifications
You must be signed in to change notification settings - Fork 62
/
auto.html
191 lines (174 loc) · 7.78 KB
/
auto.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title> </title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<div class="page">
<div id="log_container">
</div>
<div id="top">
<div class="nonetop_container">
</div>
<div class="hitokoto_container" style="display: block;">
<div class="hitokoto_main">
<div id="brackets-l"></div>
<div id="hitokoto"></div>
<div id="brackets-r"></div>
</div>
<div id="from"></div>
</div>
</div>
<div id="middle">
<div id="time_container">
<div id="apmOuterWrapper">
<div id="apmInnerWrapper">
<div id="apm"></div>
</div>
</div>
<div class="time" id="time"></div>
<div class="date" id="date"></div>
</div>
</div>
<div id="bottom">
<div class="nonebtm_container"></div>
<div class="weather_container" style="display: block;">
<div id="weaTitle">天气加载中...</div>
<div class="weaWrapper">
<div id="weaImg"></div>
<div id="weaTemp"></div>
<div id="weaInfo"></div>
</div>
</div>
</div>
</div>
<script>
// 深浅色模式标示
var lightMode = true
// 创建XMLHttpRequest对象
function createXHR() {
var xhr = null;
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
} else if (window.ActiveXObject) {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
return xhr;
}
// 一言模块
function hitokoto() {
var xhr = createXHR();
xhr.open('GET', 'https://v1.hitokoto.cn?encode=json&charset=utf-8', true);
xhr.onreadystatechange = function() {
if (this.readyState == 4) {
var data = JSON.parse(this.responseText)
document.getElementById('hitokoto').innerHTML = data.hitokoto
document.getElementById('from').innerHTML = data.from_who ? "「" + data.from + " " + data.from_who + "」" : "「" + data.from + "」"
}
}
xhr.send(null);
}
hitokoto()
setInterval("hitokoto()", 60 * 1000 * 60)
// 时钟模块
function clock() {
var date = new Date()
var utc8DiffMinutes = date.getTimezoneOffset() + 480
date.setMinutes(date.getMinutes() + utc8DiffMinutes)
var hour = date.getHours()
// 20点后6点前启用深色模式
if (hour > 19 || hour < 6) {
if (lightMode) {
document.getElementsByClassName('page')[0].style.color = '#ffffff'
document.getElementsByClassName('page')[0].style.backgroundColor = '#000000'
lightMode = false
}
} else {
if (!lightMode) {
document.getElementsByClassName('page')[0].style.color = '#000000'
document.getElementsByClassName('page')[0].style.backgroundColor = '#ffffff'
lightMode = true
}
}
var apm = '上<br>午'
if (hour > 12) {
apm = '下<br>午'
hour -= 12
}
var timeString = hour + ':' + ('0' + date.getMinutes()).slice(-2)
var dateString = (date.getMonth() + 1) + '月' + date.getDate() + '日'
var weekList = ['日', '一', '二', '三', '四', '五', '六']
var weekString = '星期' + weekList[date.getDay()]
document.getElementById('apm').innerHTML = apm
document.getElementById("time").innerHTML = timeString
document.getElementById("date").innerHTML = dateString + " " + weekString
}
clock()
setInterval("clock()", 60 * 1000)
// 天气模块
// 固定9种类型: xue、lei、shachen、wu、bingbao、yun、yu、yin、qing
var weaImgs = {
xue: ['', ''],
lei: ['', ''],
shachen: ['', ''],
wu: ['', ''],
bingbao: ['', ''],
yun: ['', ''],
duoyun: ['', ''],
yu: ['', ''],
yin: ['', ''],
qing: ['', ''],
weizhi: ['', '']
}
function weather() {
console.log('weather update')
var xhr = createXHR();
// xhr.open('GET', 'https://v2.alapi.cn/api/tianqi?token=pBsICqbRV2eVtGiI&ip=' + returnCitySN.cip, true);
xhr.open('GET','https://tianqiapi.com/free/day?appid=48373524&appsecret=5iHwLsS8',true);
xhr.onreadystatechange = function() {
if (this.readyState == 4) {
var data = JSON.parse(this.responseText)
if (data) {
weather_data = data
// 获取天气图标信息
var imgs = weaImgs[weather_data.wea_img]
var img = imgs[0]
var date = new Date()
var utc8DiffMinutes = date.getTimezoneOffset() + 480
date.setMinutes(date.getMinutes() + utc8DiffMinutes)
var hour = date.getHours()
// nightHour后天气使用夜间天气图标
if (hour > 19 || hour < 6) {
img = imgs[1]
}
var weaImg = '<span class="iconfont">' + img + '</span>' + '<div>天气:' + weather_data.wea + '</div>';
var weaTemp = '<div class="tempNum">' + weather_data.tem + '<div class="symbol">℃</div></div><div>当前气温</div>';
var highTemp = weather_data.tem_day // 日间气温/最高气温
var lowTemp = weather_data.tem_night// 夜间气温/最低气温
var air = weather_data.air
var updateTime = weather_data.update_time // 更新时间
var weaInfo = '<div>最高/低气温:' + highTemp + '/' + lowTemp + '℃</div>' +
'<div>湿度:' + weather_data.humidity + '</div>' +
'<div>空气质量:' + air + '</div>' +
'<div>风向:' + weather_data.win + '</div>' +
'<div>风速:' + weather_data.win_meter + ' ' + weather_data.win_speed + '</div>' +
'<div>更新时间:' + updateTime + '</div>';
document.getElementById('weaTitle').innerHTML = weather_data.city + '当前天气'
document.getElementById('weaImg').innerHTML = weaImg
document.getElementById('weaTemp').innerHTML = weaTemp
document.getElementById('weaInfo').innerHTML = weaInfo
} else {
console.error('天气数据获取失败: ' + weather_data.msg)
document.getElementById("weaTitle").innerHTML = '数据获取失败,请稍后再试~';
}
}
}
xhr.send(null);
}
weather();
setInterval("weather()", 60 * 1000 * 20);
</script>
</body>
</html>