Jump to content

User:FR30799386/Main Page edit.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by FR30799386 (talk | contribs) at 17:16, 15 November 2018 (Created page with '$.when(mw.loader.using(['mediawiki.util','mediawiki.notify']), $.ready).then(function() { if(mw.config.get('wgUserGroups').indexOf('sysop')==-1) {...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
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.
$.when(mw.loader.using(['mediawiki.util','mediawiki.notify']), $.ready).then(function() {
     if(mw.config.get('wgUserGroups').indexOf('sysop')==-1)
     {
       console.log('Required permissions were denied !');
       return;
     }
    //intialize all configurational variables which may be needed
    var d = new Date();
    var month = [
      'January',
      'February',
      'March',
      'April',
      'May',
      'June',
      'July',
      'August',
      'September',
      'October',
      'November',
      'December'];
    var config = [{
        name: 'tfa',
        link: 'Wikipedia\:Today\'s featured article\/' + month[d.getMonth()] + ' ' + d.getDate() + ', ' + d.getFullYear()
    }, {
        name: 'itn',
        link: 'Template:In the news'
    }, {
        name: 'dyk',
        link: 'Template:Did you know'
    }, {
        name: 'otd',
        link: 'Template:On this day'
    }, {
        name: 'tfp',
        link: 'Template:POTD protected/' + d.getFullYear() + '-' + d.getMonth() + '-' + d.getDate()
    }, {
        name: 'tfl',
        link: 'Wikipedia:Today\'s featured list/' + d.getFullYear() + '-' + d.getMonth() + '-' + d.getDate()
    }];//intialized stuff...
    if (mw.config.get('wgPageName') === 'Main_Page') {//when we are on the Main Page....start the music
        for (var i = 0; i < config.length; i++) {
            makeInterface(config[i].name, mw.util.getUrl(config[i].link, {
                action: 'edit'
            }));
            if (i == config.length - 1 && (d.getDay() == 1 || d.getDay() == 4)) {//check if its Friday or Monday, if so, add the links for tfl
                makeInterface(config[i].name, mw.util.getUrl(config[i].link, {
                    action: 'edit'
                }));
            }
        }

        function makeInterface(name, link) {
            var text = $('#mp-' + name + '-h2').text();
            $('#mp-' + name + '-h2').html(text +'<span style="float:right; font-size:85%; font-weight:normal;">[<a href="' + link + '">edit</a>]</span>');
        }
    }
});