Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
$(function () {
	var tick = 0;
	
        console.log('Hello, Happy World!');
        
    var insertSummary = function ($this, $summary) {
        var summary = $summary.val();
        var $item = $this.parent('.mw-summary-preset-item');
        summary = summary.replace(/\s+$/g, '');
        if (summary != '') {
            summary += ' ';
        }
        summary += $item.attr('title') || $this.text();
        $this.replaceWith($this.contents());
        $summary.val(summary).change();
    };

    // 传统编辑器
    $('#wpSummaryLabel .mw-summary-preset').on('click', '.mw-summary-preset-item a', function(e) {
        e.preventDefault();
        insertSummary($(this), $('#wpSummary'));
    });

    // VE / 新维基文本
    var initSummary = false;
    mw.loader.using('ext.visualEditor.desktopArticleTarget.init', function () {
    	console.log('ext.visualEditor.desktopArticleTarget.init');
    	
        mw.hook('ve.saveDialog.stateChanged').add(function () {
        	tick++;
        	console.log('ve.saveDialog.stateChanged: ' + tick);
        	
            // 编辑摘要链接在点击“发布更改”按钮之后才会加载
            if (!initSummary) {
                $('div.ve-ui-mwSaveDialog-summaryLabel span.mw-summary-preset-item > a')
                    .removeAttr('target')
                    .click(function (e) {
                        e.preventDefault();
                        insertSummary($(this), $('div.ve-ui-mwSaveDialog-summary > textarea'))
                    });
                initSummary = true;
            }
        });
    });
});