• Moegirl.ICU:萌娘百科流亡社群 581077156(QQ),欢迎对萌娘百科运营感到失望的编辑者加入
  • Moegirl.ICU:账号认领正在试运行,有意者请参照账号认领流程

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 () {}混用也有点不爽。)——M.More about this user. J.Judge my soul. H.How I contributed.【恒】 2021年6月1日 (二) 11:32 (CST)

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()过于精确导致的问题了。感谢! --M.Me. J.Judge my soul. H.Hard work.【旅】 2021年6月1日 (二) 14:24 (CST)

Done.——From AnnAngela the Temporary Bureaucrat (Talk) 2021年6月1日 (二) 15:19 (CST)
这次行为与预期一致了,感谢! --M.More about this user. J.Join the talk. H.Heritage.【巽】 2021年6月1日 (二) 15:59 (CST)