LLWiki正在建设中,欢迎加入我们

“Widget:Countdown”的版本间差异

跳转到导航 跳转到搜索
删除16字节 、​ 2020年8月24日 (一) 04:57
无编辑摘要
"use strict";
window.addEventListener('load', function () {
var timeObj = {};
const fromNow = function (ele) {
constlet 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开始
let 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();,
let result = "";
if (second < 0) {
minute--;
month += 12;
}
let result = "";
if (year > 0) {
result += `<span class="countdown-num">${year}</` + 'span>年';
if(isBefore) {
before.innerHTML = before.innerHTML.replace("$1", result.replace(/(\d) /g, "$1"));
after.remove()style.display = "none";
}
else {
after.innerHTML = after.innerHTML.replace("$1", result.replace(/(\d) /g, "$1"));
before.remove()style.display = "none";
}
ele.children[0].remove();
};
const run = () => {
document.querySelectorAll(".countdownNode:not(.disabled)").forEach((ele) => {
fromNow(ele);
ele.style.visibility = "visible";
});
};
return;
}
timeObj[ele.id] = time;
});
run();
16,874

个编辑

导航菜单