Widget talk:Countdown
跳转到导航
跳转到搜索
编辑请求 - MJH - 2021.06.01
由MJH提出的对Widget:Countdown的编辑请求:
- 状态: 完成
将以下内容:
const fromNow = function (then, before, after) {
/* ... */
const isBefore = then.isBefore(now);
/* ... */
return (isBefore ? before : after).replace("$1", result.replace(/(\d) /g, "$1"));
};
const run = () => {
$(".countdownNode:not(.disabled)").each((_, ele) => {
const self = $(ele);
self.text(fromNow(self.data("target"), ele.dataset.before || "$1前", ele.dataset.after || "还剩$1"));
});
};
修改为:
const fromNow = function (then, before, after, on) {
/* ... */
const isBefore = then.isBefore(now);
const isAfter = now.isBefore(then);
/* ... */
return ((isBefore === isAfter) ? on : (isBefore ? before : after)).replace("$1", result.replace(/(\d) /g, "$1"));
};
const run = () => {
$(".countdownNode:not(.disabled)").each((_, ele) => {
const self = $(ele);
self.text(fromNow(self.data("target"), ele.dataset.before || "$1前", ele.dataset.after || "还剩$1", ele.dataset.on || "就是现在!"));
});
};
嘛,可能我有点吹毛求疵了,但是看到{{Countdown}}和{{Time Countdown}}里面“就是现在”的时候显示的却是“前”(而不是“0秒前”!)让我觉得有点不爽啦。{{Day Countdown}}里面明明就有“今日举行”的说。
(题外话,() => {}和function () {}混用也有点不爽。)——
- Done.——From AnnAngela the Temporary Bureaucrat (Talk) 2021年6月1日 (二) 13:22 (CST)
好吧,看样子这并没有达成我想象中的效果……可能moment()的精确度比想象中要高一些。抱歉要再度编辑请求了:
由MJH提出的对Widget:Countdown的编辑请求:
- 状态: 完成
将以下内容:
const fromNow = (then, before, after, on) => {
const now = moment();
const isBefore = then.isBefore(now);
const isAfter = now.isBefore(then);
/* ... */
return (isBefore === isAfter ? on : isBefore ? before : after).replace("$1", result.replace(/(\d) /g, "$1"));
};
修改为:
const fromNow = (then, before, after, on) => {
const now = moment();
const isBefore = then.isBefore(now);
/* ... */
return (result === "" ? on : isBefore ? before : after).replace("$1", result.replace(/(\d) /g, "$1"));
};
这样应该就不会有moment()过于精确导致的问题了。感谢! --