User:Xiplus/js/replacement-display.js

注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。

(function(){

if (mw.config.get('wgAction') !== 'view' && mw.config.get('wgArticleId') !== 0) {
    return;
}

if (typeof(ReplacementDisplay) == 'undefined')
    ReplacementDisplay = {};

if (typeof(ReplacementDisplay.replace) != 'function') {
    ReplacementDisplay.replace = function(string) {
        return string;
    };
}

if (typeof(ReplacementDisplay.activePage) != 'function') {
    ReplacementDisplay.activePage = function(string) {
        if (mw.config.get('wgNamespaceNumber') === 0) {
            return true;
        }
        return false;
    };
}

if (!ReplacementDisplay.activePage()) return;

var content = $('#mw-content-text', mw.util.$content);

new mw.Api().get({
    action: 'query',
    prop: 'revisions',
    rvprop: [ 'content' ],
    titles: [ mw.config.get('wgPageName') ],
    formatversion: '2'
}).done(function(data) {
    new mw.Api().post({
        action: 'parse',
        title: [ mw.config.get('wgPageName') ],
        text: ReplacementDisplay.replace(data.query.pages[0].revisions[0].content),
        prop: 'text'
    }).done(function(data) {
        content.html(data.parse.text['*']);
    });
});

})();