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
| function newYear() { if (!document.querySelector('#newYear')) return;
const specialDates = [ { month: 2, day: 4, title: "立春", image: "https://wmimg.com/i/1452/2025/04/67f0ca55c250a.webp" }, { month: 2, day: 19, title: "雨水", image: "https://wmimg.com/i/1452/2025/04/67f0ca7917f9d.webp" }, { month: 3, day: 5, title: "惊蛰", image: "https://wmimg.com/i/1452/2025/04/67f0ca83b7966.webp" }, { month: 3, day: 20, title: "春分", image: "https://wmimg.com/i/1452/2025/04/67f0ca904f4b6.webp" }, { month: 4, day: 4, title: "清明", image: "https://wmimg.com/i/1452/2025/04/67f0caa2cd872.webp" }, { month: 4, day: 20, title: "谷雨", image: "https://wmimg.com/i/1452/2025/04/67f0d032b6181.webp" }, { month: 5, day: 5, title: "立夏", image: "https://wmimg.com/i/1452/2025/04/67f0d05562fef.webp" }, { month: 5, day: 21, title: "小满", image: "https://wmimg.com/i/1452/2025/04/67f0d067a9a7e.webp" }, { month: 6, day: 5, title: "芒种", image: "https://wmimg.com/i/1452/2025/04/67f0d0764f333.webp" }, { month: 6, day: 21, title: "夏至", image: "https://wmimg.com/i/1452/2025/04/67f0d0833d54f.webp" }, { month: 7, day: 7, title: "小暑", image: "https://wmimg.com/i/1452/2025/04/67f0d0c61edc7.webp" }, { month: 7, day: 23, title: "大暑", image: "https://wmimg.com/i/1452/2025/04/67f0d0e3e1710.webp" }, { month: 8, day: 7, title: "立秋", image: "https://wmimg.com/i/1452/2025/04/67f0d0ed8ecf5.webp" }, { month: 8, day: 23, title: "处暑", image: "https://wmimg.com/i/1452/2025/04/67f0d0f9e0bb3.webp" }, { month: 9, day: 7, title: "白露", image: "https://wmimg.com/i/1452/2025/04/67f0d104d716a.webp" }, { month: 9, day: 23, title: "秋分", image: "https://wmimg.com/i/1452/2025/04/67f0d10f609df.webp" }, { month: 10, day: 8, title: "寒露", image: "https://wmimg.com/i/1452/2025/04/67f0d11c22029.webp" }, { month: 10, day: 23, title: "霜降", image: "https://wmimg.com/i/1452/2025/04/67f0d129dd195.webp" }, { month: 11, day: 7, title: "立冬", image: "https://wmimg.com/i/1452/2025/04/67f0d13603562.webp" }, { month: 11, day: 22, title: "小雪", image: "https://wmimg.com/i/1452/2025/04/67f0d14465376.webp" }, { month: 12, day: 7, title: "大雪", image: "https://wmimg.com/i/1452/2025/04/67f0d14d8f04b.webp" }, { month: 12, day: 21, title: "冬至", image: "https://wmimg.com/i/1452/2025/04/67f0d15a7644f.webp" }, { month: 1, day: 5, title: "小寒", image: "https://wmimg.com/i/1452/2025/04/67f0d1647ee35.webp" }, { month: 1, day: 20, title: "大寒", image: "https://wmimg.com/i/1452/2025/04/67f0d16e52efc.webp" },
];
const siteStartDate = new Date('2022-10-29'); const siteStartDateTimestamp = siteStartDate.getTime() / 1000;
const week = { 0: '周日', 1: '周一', 2: '周二', 3: '周三', 4: '周四', 5: '周五', 6: '周六' };
function nol(h) { h = Number(h); return h > 9 ? h : '0' + h; }
function time() { const now = new Date(); const nowTimestamp = Math.round(now.getTime() / 1000); const today = `${now.getMonth() + 1}-${now.getDate()}`;
document.querySelector('#newYear .today').innerHTML = `${now.getFullYear()}-${nol(now.getMonth() + 1)}-${nol(now.getDate())} ${week[now.getDay()]}`;
let closestDate = null; let closestSecond = Infinity;
for (const specialDate of specialDates) { const specialDateThisYear = new Date(now.getFullYear(), specialDate.month - 1, specialDate.day); const specialDateNextYear = new Date(now.getFullYear() + 1, specialDate.month - 1, specialDate.day);
let specialDateTimestamp; if (specialDateThisYear > now) { specialDateTimestamp = specialDateThisYear.getTime() / 1000; } else { specialDateTimestamp = specialDateNextYear.getTime() / 1000; }
const second = specialDateTimestamp - nowTimestamp;
if (second < 0) continue;
if (second < closestSecond) { closestSecond = second; closestDate = specialDate; } }
if (closestDate) { document.querySelector('#newYear .title').innerHTML = `距离${closestDate.title}:`;
if (closestSecond > 86400) { document.querySelector('#newYear .newYear-time').innerHTML = `<span class="day">${Math.ceil(closestSecond / 86400)}</span><span class="unit">天</span>`; } else { let h = nol(parseInt(closestSecond / 3600)); closestSecond %= 3600; let m = nol(parseInt(closestSecond / 60)); closestSecond %= 60; let s = nol(closestSecond); document.querySelector('#newYear .newYear-time').innerHTML = `<span class="time">${h}:${m}:${s}</span>`; }
document.querySelector('.newYear-slider').style.backgroundImage = `url(${closestDate.image})`; } else { document.querySelector('#newYear .title').innerHTML = `距离建站${now.getFullYear() - siteStartDate.getFullYear()}周年:`; const second = nowTimestamp - siteStartDateTimestamp; const days = Math.floor(second / 86400); document.querySelector('#newYear .newYear-time').innerHTML = `<span class="day">${days}</span><span class="unit">天</span>`; document.querySelector('.newYear-slider').style.backgroundImage = `url(url_to_default_image.jpg)`; }
if (!window.newYearTimer) { window.newYearTimer = setInterval(time, 1000); } }
time(); }
function newYearSwiper() { var swiper = new Swiper('.newYear-slider', { passiveListeners: true, loop: true, autoplay: { disableOnInteraction: true, delay: 5000 }, effect: 'fade', mousewheel: true, autoHeight: true }); container.onmouseenter = () => { swiper.autoplay.stop(); }; container.onmouseleave = () => { swiper.autoplay.start(); }; }
function whenDOMReady() { newYear(); newYearSwiper(); }
whenDOMReady(); document.addEventListener("pjax:complete", whenDOMReady);
|