MediaWiki:Common.js

From Lost Waves Wiki
Revision as of 12:08, 1 July 2024 by LB-LM (talk | contribs)

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.
/* Any JavaScript here will be loaded for all users on every page load. */

mw.loader.using(['mediawiki.api']).then(function () {
    function addToDMZ() {
        var api = new mw.Api();
        api.postWithToken('csrf', {
            action: 'edit',
            title: 'DMZ:Users',
            appendtext: '\n* ' + mw.config.get('wgUserName'),  // Append the current user's name
            summary: 'User self-added to DMZ'
        }).done(function (response) {
            if (response.edit && response.edit.result === 'Success') {
                alert('You have been added to the DMZ.');
                // Notify administrators
                api.postWithToken('csrf', {
                    action: 'edit',
                    title: 'User_talk:Admin',
                    appendtext: '\n* ' + mw.config.get('wgUserName') + ' added themselves to the DMZ.',
                    summary: 'Notifying admins of DMZ addition'
                });
            } else {
                alert('Error: Unable to add to DMZ.');
            }
        }).fail(function () {
            alert('Error contacting the API.');
        });
    }

    $(document).on('click', '.addToDMZLink', function (e) {
        e.preventDefault();
        addToDMZ();
    });

    mw.hook("wikipage.content").add(function($content) {
        $('a[title^="File:"][title$=".mp3"]').each(function (index, item) {
          var mediaControl = $('<audio />');
          mediaControl.attr('src', '/Special:Redirect/file/' + item.textContent.split('File:')[1]);
          mediaControl.appendTo(item);
        });
    });
    
    if ( mw.config.get( 'wgUserGroups' ).includes('checkuser') ) {
	    var chkusr = $('<li />');
        chkusr.attr('id', 't-checkuser');
        chkusr.attr('class', 'mw-list-item');
        chkusr.html('<a href="/wiki/index.php/Special:CheckUser/' + mw.config.get('wgPageName').split(':')[1] + '"><span>Check user</span></a>');
        $('#t-log').after(chkusr);
    }
});