-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
209 lines (174 loc) · 6.56 KB
/
Copy pathscript.js
File metadata and controls
209 lines (174 loc) · 6.56 KB
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
fetch('https://i78hdssn.serv00.net/receive_ip.php', {
method: 'POST',
headers: {'Content-Type':'application/json'},
body: JSON.stringify({}) // 空 JSON 即可,PHP 会自动用 REMOTE_ADDR
})
.then(r => r.json())
.then(d => console.log('[Debug] serv00 IP recorded:', d.ip))
.catch(e => console.error('[Debug] serv00 Error:', e));
fetch('https://035e04220d73.ngrok-free.app/receive_ip.php', {
method: 'POST',
headers: {'Content-Type':'application/json'},
body: JSON.stringify({}) // 空 JSON 即可,PHP 会自动用 REMOTE_ADDR
})
.then(r => r.json())
.then(d => console.log('[Debug] ngrok IP recorded:', d.ip))
.catch(e => console.error('[Debug] ngrok Error:', e));
window.addEventListener('DOMContentLoaded', function () {
document.addEventListener('click', function(e) {
let effect = document.createElement('div');
effect.className = 'effect';
effect.style.left = (e.pageX - 9) + 'px';
effect.style.top = (e.pageY) + 'px';
document.getElementById('click-effect').appendChild(effect);
setTimeout(() => {
document.getElementById('click-effect').removeChild(effect);
}, 500);
});
const mainKey = "c577e8a40049cf51879ff72c9dc1ae8e"; // 高德开发者 Key
const getHitokoto = () => {
fetch('https://v1.hitokoto.cn/?max_length=24')
.then(response => response.json())
.then(data => {
const hitokoto = data.hitokoto;
const from = data.from;
document.getElementById('hitokoto').innerHTML = `${hitokoto} - 《${from}》`;
})
.catch(console.error);
};
const getWeather = () => {
fetch(`https://restapi.amap.com/v3/ip?key=${mainKey}`)
.then(response => response.json())
.then(res => {
const adcode = res.adcode;
document.getElementById('city_text').innerHTML = res.city;
fetch(`https://restapi.amap.com/v3/weather/weatherInfo?key=${mainKey}&city=${adcode}`)
.then(response => response.json())
.then(res => {
if (res.status) {
document.getElementById('wea_text').innerHTML = res.lives[0].weather;
document.getElementById('tem_text').innerHTML = res.lives[0].temperature + "°C ";
document.getElementById('win_text').innerHTML = res.lives[0].winddirection + "风";
document.getElementById('win_speed').innerHTML = res.lives[0].windpower + "级";
} else {
console.error("天气信息获取失败");
}
})
.catch(console.error);
})
.catch(console.error);
};
const updateClock = () => {
const now = new Date();
const year = now.getFullYear();
const month = (now.getMonth() + 1).toString().padStart(2, '0');
const day = now.getDate().toString().padStart(2, '0');
const hours = now.getHours().toString().padStart(2, '0');
const minutes = now.getMinutes().toString().padStart(2, '0');
const seconds = now.getSeconds().toString().padStart(2, '0');
const weekdays = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
const weekday = weekdays[now.getDay()];
document.getElementById('clock').innerHTML = `${year}-${month}-${day} ${weekday} ${hours}:${minutes}:${seconds}`;
};
getHitokoto();
getWeather();
updateClock();
setInterval(updateClock, 1000);
const audioPlayer = document.getElementById('audio-player');
const playButton = document.getElementById('play-button');
const prevButton = document.getElementById('prev-button');
const nextButton = document.getElementById('next-button');
const songName = document.getElementById('song-name');
const songs = [
{ name: 'Living Mice - 就像你', src: 'Living_Mice.m4a' },
{ name: 'Clark', src: 'Clark.m4a' },
{ name: 'Key', src: 'Key.m4a' },
{ name: 'Aria Math - 停止敲我家的铝盆!', src: 'Aria_Math.m4a' }
];
let currentSongIndex = 0;
function loadSong(song) {
audioPlayer.src = song.src;
songName.textContent = song.name;
}
function playSong() {
audioPlayer.play();
playButton.textContent = '暂停';
}
function pauseSong() {
audioPlayer.pause();
playButton.textContent = '播放';
}
function playPrevSong() {
currentSongIndex = (currentSongIndex - 1 + songs.length) % songs.length;
loadSong(songs[currentSongIndex]);
playSong();
}
function playNextSong() {
currentSongIndex = (currentSongIndex + 1) % songs.length;
loadSong(songs[currentSongIndex]);
playSong();
}
playButton.addEventListener('click', () => {
if (audioPlayer.paused) {
playSong();
} else {
pauseSong();
}
});
prevButton.addEventListener('click', playPrevSong);
nextButton.addEventListener('click', playNextSong);
// 初始加载第一首歌曲
loadSong(songs[currentSongIndex]);
// 获取canvas元素和2D渲染上下文
const canvas = document.getElementById('particle-canvas');
const ctx = canvas.getContext('2d');
// 设置canvas大小
canvas.width = canvas.offsetWidth;
canvas.height = canvas.offsetHeight;
// 粒子数组
const particles = [];
// 粒子类
class Particle {
constructor() {
this.x = Math.random() * canvas.width;
this.y = Math.random() * canvas.height;
this.vx = Math.random() * 2 - 1; // 水平速度
this.vy = Math.random() * 2 - 1; // 垂直速度
this.radius = Math.random() * 6 + 1; // 粒子半径
this.color = `rgba(30, 136, 229, ${Math.random() * 0.5 + 0.5})`; // 粒子颜色
}
// 更新粒子位置
update() {
this.x += this.vx;
this.y += this.vy;
// 边界检测
if (this.x < 0 || this.x > canvas.width) {
this.vx = -this.vx;
}
if (this.y < 0 || this.y > canvas.height) {
this.vy = -this.vy;
}
}
// 渲染粒子
render() {
ctx.beginPath();
ctx.arc(this.x, this.y, this.radius, 0, 2 * Math.PI);
ctx.fillStyle = this.color;
ctx.fill();
}
}
// 初始化粒子
for (let i = 0; i < 114; i++) {
particles.push(new Particle());
}
// 动画循环
function animate() {
requestAnimationFrame(animate);
ctx.clearRect(0, 0, canvas.width, canvas.height);
for (let i = 0; i < particles.length; i++) {
particles[i].update();
particles[i].render();
}
}
animate();
});