Widget:Countdown:修订间差异
来自OGAS数据中枢
更多操作
无编辑摘要 |
无编辑摘要 |
||
| (未显示同一用户的1个中间版本) | |||
| 第12行: | 第12行: | ||
const now = new Date(); | const now = new Date(); | ||
document.querySelectorAll('.custom-countdown').forEach(el => { | document.querySelectorAll('.custom-countdown').forEach(el => { | ||
let targetStr = el.getAttribute('data-target'); | |||
const beforeTpl = el.getAttribute('data-before'); | const beforeTpl = el.getAttribute('data-before'); | ||
const afterTpl = el.getAttribute('data-after'); | const afterTpl = el.getAttribute('data-after'); | ||
if (!targetStr) return; | if (!targetStr) return; | ||
if (/^\d{4}$/.test(targetStr)) { | |||
targetStr += "-01-01T00:00:00"; | |||
} | |||
if (/[+-]\d{2}$/.test(targetStr)) { | |||
targetStr += ":00"; | |||
} | |||
if (/T\d{2}([+-]|Z|$)/.test(targetStr)) { | |||
targetStr = targetStr.replace(/(T\d{2})/, "$1:00:00"); | |||
} | |||
if (targetStr === 'today-end') { | |||
targetStr = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 59, 59).toISOString(); | |||
} | |||
const target = new Date(targetStr); | |||
const target = new Date( | |||
if (isNaN(target)) { | if (isNaN(target)) { | ||
el.innerHTML = '<span style="color:red">时间格式错误</span>'; | el.innerHTML = '<span style="color:red">时间格式错误 (' + targetStr + ')</span>'; | ||
return; | return; | ||
} | } | ||
2026年5月3日 (日) 15:32的最新版本
这是一个倒计时微件,仅供{{Countdown}}使用。