User:FR30799386/Main Page edit.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.
$.when(mw.loader.using(['mediawiki.util']), $.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()+1) + '-' + d.getDate()
    }, {
        name: 'tfl',
        link: 'Wikipedia:Today\'s featured list/' + d.getFullYear() + '-' + (d.getMonth()+1) + '-' + d.getDate()
    }];//intialized stuff...
    if (mw.config.get('wgIsMainPage')) {//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'
            })+'#wpTextbox1');
            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'
                })+'#wpTextbox1');
            }
        }

        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>');
        }
    }
});