-
Notifications
You must be signed in to change notification settings - Fork 63
/
weiboDark.html
193 lines (175 loc) · 7.99 KB
/
weiboDark.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title> </title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<!-- 查询客户端ip用于天气查询 -->
<script src="https://pv.sohu.com/cityjson"></script>
</head>
<body>
<div class="page dark">
<div id="log_container">
</div>
<div id="top">
<div class="weibo_container" style="display: block">
<div class="weibo_title">微博热搜加载中...</div>
<div class="hot_list">
<ul id="hot_word"></ul>
<ul id="hot_word_num"></ul>
</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>
// 创建XMLHttpRequest对象
function createXHR() {
var xhr = null;
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
} else if (window.ActiveXObject) {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
return xhr;
}
// 微博热搜模块
function weibo() {
console.log("weibo update");
var xhr = createXHR();
xhr.open("GET", 'https://tenapi.cn/resou/', true);
xhr.onreadystatechange = function () {
if (this.readyState == 4) {
var data = JSON.parse(this.responseText);
var weibo_title = document.getElementsByClassName("weibo_title")[0];
var hot_word = document.getElementById("hot_word");
var hot_word_num = document.getElementById("hot_word_num");
if (data.data === 200) {
weibo_data = data.list; // alapi
weibo_title.innerHTML = "微博实时热搜";
hot_word.innerHTML = "";
hot_word_num.innerHTML = "";
for (var i = 0; i < 3; i++) {
var index = i + 1;
hot_word.innerHTML +=
"<li>" + index + ". " + weibo_data[i].name + "</li>"; // alapi
hot_word_num.innerHTML += "<li>" + weibo_data[i].hot + "</li>"; // alapi
}
} else {
console.error("微博热搜数据获取失败: " + data.msg);
weibo_title.innerHTML = "数据获取失败,请稍后再试~";
}
}
};
xhr.send(null);
}
weibo();
setInterval("weibo()", 60 * 1000 * 20);
// 时钟模块
function clock() {
var date = new Date();
var utc8DiffMinutes = date.getTimezoneOffset() + 480;
date.setMinutes(date.getMinutes() + utc8DiffMinutes);
var hour = date.getHours();
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>