PageSourceSearch

https://lttthedev.github.io/scripts/setting_getTime.js

js lttthedev.github.io collected 2026-10-03 09:32:20 UTC 851 bytes, 31 lines download raw bytes

1//设置页面时间获取逻辑  @Junchen Yi  2023-9-17
2
3// 获取具有class="settingTime"的元素
4const settingTimeElement = document.querySelector('.settingTime');
5
6// 更新时间函数
7function updateTime() {
8    const now = new Date();
9    const hours = now.getHours();
10    const minutes = now.getMinutes().toString().padStart(2, '0'); // 补零
11    const seconds = now.getSeconds().toString().padStart(2, '0'); // 补零
12
13    let timeOfDay = '';
14
15    if (hours < 12) {
16        timeOfDay = '上午';
17    } else if (hours < 18) {
18        timeOfDay = '下午';
19    } else {
20        timeOfDay = '晚上';
21    }
22
23    // 将时间注入到HTML元素内
24    settingTimeElement.textContent = `${timeOfDay} ${hours}:${minutes}:${seconds}`;
25}
26
27// 初始加载时更新时间
28updateTime();
29
30// 每秒钟更新一次时间
31setInterval(updateTime, 1000);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.