Jump to content

User:Dabao qian/mainpage-localtime.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
(function($, mw) { mw.loader.using([
    'mediawiki.user', 'mediawiki.util'
], function() { jQuery(function() {
    if (mw.config.get('wgAction') !== 'view') {
        return;
    }
    if (!mw.config.get('wgIsMainPage')) {
        return;
    }
    var timecorrection = mw.user.options.get('timecorrection');
    if (timecorrection) {
        timecorrection = timecorrection.split('|')[1];
    } else {
        timecorrection = -(new Date().getTimezoneOffset());
    }
    timecorrection = parseInt(timecorrection);
    if (timecorrection > 0) {
        timecorrection = '+' + timecorrection;
    } else if (timecorrection == 0) {
        return;
    }
    var content = $('#mw-content-text', mw.util.$content);
    var text = '{{Main_Page|timecorrection=' + timecorrection + ' minutes}}';
    // content.text(text);
    $.post(
        mw.util.wikiScript('api'),
        {
            'action': 'parse',
            'title': mw.config.get('wgPageName'),
            'text': text,
            'prop': 'text',
            'disablepp': '',
            'format': 'json'
        },
        function(data) {
            content.html(data.parse.text['*']);
        }
    );
}); }); })(jQuery, mediaWiki);