User:Xover/seawall.js

/* global $, mw */ "use strict";

// Make sure the necessary modules are loaded mw.loader.using(['mediawiki.util', 'mediawiki.api'], function {

// Wait for the page to be parsed (new-style $(document).ready) $(function {

// Add portlets to turn flood flag on or off var floodonPortlet = mw.util.addPortletLink(     'p-cactions', '#', 'Flood flag ON', 'ca-floodon', 'Turn the flood flag ON'    ); $(floodonPortlet).click(function (event) {     event.preventDefault;      floodUp;    }); var floodoffPortlet = mw.util.addPortletLink(     'p-cactions', '#', 'Flood flag OFF', 'ca-floodoff', 'Turn the flood flag OFF'    ); $(floodoffPortlet).click(function (event) {     event.preventDefault;      floodDown;    });

// Flag it if +flood is on   if ($.inArray('flood', mw.config.get('wgUserGroups')) >= 0) { $('#firstHeading').css('background', 'repeating-linear-gradient(to right,rgba(0,0,0,0.4),rgba(0,0,0,0.4) 10px,rgba(255,255,0,0.6) 10px,rgba(255,255,0,0.6) 20px)'); } }); // END: $(document).ready }); // END: mw.loader.using

// Turn flood flag on function floodUp { var api = new mw.Api; var params = { action: 'userrights', user: mw.config.get('wgUserName'), add: 'flood', reason: '+flood for bulk action', format: 'json' };

api.postWithToken('userrights', params).done(function (data) {   $('#firstHeading').css('background', 'repeating-linear-gradient(to right,rgba(0,0,0,0.4),rgba(0,0,0,0.4) 10px,rgba(255,255,0,0.6) 10px,rgba(255,255,0,0.6) 20px)');  }); }

// Turn flood flag off function floodDown { var api = new mw.Api; var params = { action: 'userrights', user: mw.config.get('wgUserName'), remove: 'flood', reason: '-flood after bulk action', format: 'json' };

api.postWithToken('userrights', params).done(function (data) {   $('#firstHeading').css('background', 'revert');  }); }