MediaWiki:Common.js: Difference between revisions

From Lost Waves Wiki
(Undo revision 5054 by LB-LM (talk))
Tag: Undo
No edit summary
Line 31: Line 31:
         addToDMZ();
         addToDMZ();
     });
     });
});
   
 
$( document ).ready(function() {
     if ( mw.config.get( 'wgUserGroups' ).includes('checkuser') ) {
     if ( mw.config.get( 'wgUserGroups' ).includes('checkuser') ) {
    var chkusr = document.createElement("li");
    var chkusr = $('<li />');
         chkusr.id = "t-checkuser";
         chkusr.id = "t-checkuser";
         chkusr.class = "mw-list-item";
         chkusr.class = "mw-list-item";
         chkusr.outerHTML = "<a href="/wiki/index.php/Special:CheckUser/Spyvs.Spy"><span>Check user</span></a>";
         chkusr.text("hello world");
        chkusr.appendTo($('.vector-menu-content-list'));
     }
     }
});
});

Revision as of 10:50, 30 May 2024

/* 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();
    });
    
    if ( mw.config.get( 'wgUserGroups' ).includes('checkuser') ) {
	    var chkusr = $('<li />');
        chkusr.id = "t-checkuser";
        chkusr.class = "mw-list-item";
        chkusr.text("hello world");
        chkusr.appendTo($('.vector-menu-content-list'));
    }
});