MT:カスタムボタン:公開日の秒数を切り上げ0に設定してフォームに投げるボタン

久々のCustom Editor Button用追加ボタンです。投稿日のフォームへ秒数を00にして切り上げた状態のものをセットします。

最近公開時間の秒数を00にそろえるというのが自分のマイブームとなっています(何をやってるんだか)。ようするにきっちりと揃えたいというだけなのです。前は現在時刻をフォームにいれるボタンを使っていましたが、秒数だけ修正するのに面倒になってきたのでボタンを作ることにしました。

config.yamlファイル

name: PublishDateSetZeroSecondsButton
id: PublishDateSetZeroSecondsButton
key: PublishDateSetZeroSecondsButton
author_link: http://www.markdiary.com/
author_name: maRk
description: utility button for Custom Editor Button2 plugins
version: 0.1
#
# require Custom Editor Button 2 Plugin https://github.com/aklaswad/mt-plugin-custom-editor-button-2/
#
buttons:
    util_curtime2:
        title: Publish Date would set as zero seconds to Current Time
        image: images/now0.png
        code: |
            function ceb_util_curtime2 (text, args) {
                function zp(num) {
                    if(num < 10){num = '0' + num;}
                    return num;
                }
                var now = new Date();
                    if (zp(now.getMinutes()) < 59 ){
                        var date = '' + now.getFullYear() + '-' + zp(now.getMonth() + 1) + '-' + zp(now.getDate());
                        var time = zp(now.getHours()) + ':' + zp(now.getMinutes() + 1) + ':00';
                        document.entry_form.authored_on_date.value = date;
                        document.entry_form.authored_on_time.value = time;
                    } else if (zp(now.getHours()) != 23 && zp(now.getMinutes()) == 59) {
                        var time = zp(now.getHours()+1) + ':' +'00:00';
                        document.entry_form.authored_on_time.value = time;
                    } else { var time = zp(now.getHours()) + ':' + zp(now.getMinutes()) + ':00';
                      alert('wait few minutes');
                }
                return undefined;
            }

config.yamlは、PublishDateSetZeroSecondsButtonフォルダにいれてpluginsディレクトリへ。now0.pngは適当な画像を/mt-static/plugins/PublishDateSetZeroSecondsButton/images/.にいれるとします。

* Custom Editor Button 2プラグインが必要です