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

微件討論: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)