打开主菜单
首页
随机
最近更改
特殊页面
沙盒
互助客栈
方针与指引
帮助
页面信息
链入页面
相关更改
设置
关于LLWiki
免责声明
LLWiki
搜索
用户菜单
18.217.103.250
讨论
监视列表
贡献
登录
LLWiki正在建设中,欢迎
加入我们
!
查看“Widget:Countdown”的源代码
←
Widget:Countdown
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您没有权限编辑
Widget
命名空间内的页面。
您可以查看和复制此页面的源代码。
<noinclude>{{doc|content=引自[[moegirl:widget:countdown|萌娘百科:Widget:Countdown]]。 请使用{{tl|countdown}}调用。}}</noinclude><includeonly><!--{if !isset($wgCountdown) || !$wgCountdown}--><!--{assign var="wgCountdown" value=true scope="global"}--><script src="/mediawiki/resources/lib/moment/moment.js"></script><script> //</includeonly>JavaScript脚本:<pre lang=js> "use strict"; window.addEventListener('load', function () { const fromNow = function (ele) { let now = moment(), then = moment(ele.dataset.target), before = ele.children[1], after = ele.children[2], isBefore = then.isBefore(now), monthsHave31Days = [0, 2, 4, 6, 7, 9, 11], // 月份从0开始 year = isBefore ? now.year() - then.year() : then.year() - now.year(), month = isBefore ? now.month() - then.month() : then.month() - now.month(), day = isBefore ? now.date() - then.date() : then.date() - now.date(), hour = isBefore ? now.hour() - then.hour() : then.hour() - now.hour(), minute = isBefore ? now.minute() - then.minute() : then.minute() - now.minute(), second = isBefore ? now.second() - then.second() : then.second() - now.second(), result = ""; if (second < 0) { minute--; second += 60; } if (minute < 0) { hour--; minute += 60; } if (hour < 0) { day--; hour += 24; } if (day < 0) { month--; if (monthsHave31Days.includes((isBefore ? then : now).month())) { day += 31; } else if ((isBefore ? then : now).month() === 1) { if ((isBefore ? then : now).year() % 4 === 0) { day += 29; } else { day += 28; } } else { day += 30; } } if (month < 0) { year--; month += 12; } if (year > 0) { result += `<span class="countdown-num">${year}</` + 'span>年'; } if (month > 0) { result += `<span class="countdown-num">${month}</` + 'span>月'; } else if (result !== "") { result += `<span class="countdown-num">${0}</` + 'span>月'; } if (day > 0) { result += `<span class="countdown-num">${day}</` + 'span>日'; } else if (result !== "") { result += `<span class="countdown-num">${0}</` + 'span>日'; } if (hour > 0) { result += `<span class="countdown-num">${hour}</` + 'span>' + ele.children[0].innerHTML; } else if (result !== "") { result += `<span class="countdown-num">${0}</` + 'span>' + ele.children[0].innerHTML; } if (minute > 0) { result += `<span class="countdown-num">${minute}</` + 'span>分'; } else if (result !== "") { result += `<span class="countdown-num">${0}</` + 'span>分'; } if (second > 0) { result += `<span class="countdown-num">${second}</` + 'span>秒'; } else if (result !== "") { result += `<span class="countdown-num">${0}</` + 'span>秒'; } if(isBefore) { before.children[0].innerHTML = result; after.style.display = "none"; } else { after.children[0].innerHTML = result; before.style.display = "none"; } }; const run = () => { document.querySelectorAll(".countdownNode:not(.disabled)").forEach((ele) => { fromNow(ele); ele.style.visibility = "visible"; }); }; document.querySelectorAll(".countdownNode").forEach((ele) => { const time = moment(ele.dataset.target); if (!time || !time.isValid()) { ele.classList.add("error", "disabled") ele.innerHTML = "(发生了致命错误!)"; return; } ele.children[1].innerHTML = ele.children[1].innerHTML.replace("$1", '<span></span>'); ele.children[2].innerHTML = ele.children[2].innerHTML.replace("$1", '<span></span>'); }); run(); window.setInterval(run, 1000); }); //</pre> <includeonly> </script> <style> /* </includeonly>CSS样式表:<pre lang="css"> */ .countdown-num { display:inline-block; width:1.25em; text-align:right; } /* </pre><includeonly> */ </style><!--{/if}--></includeonly>
本页使用的模板:
Template:CCnotice
(
查看源代码
)(受保护)
Template:Doc
(
查看源代码
)(受保护)
Template:Documentation
(
查看源代码
)(受保护)
Template:Tl
(
查看源代码
)(受保护)
返回
Widget:Countdown
。