User:BZPN/sandbox2
// Check if the user is on the page user:BZPN/sandbox2 if (mw.config.get('wgPageName') === 'User:BZPN/sandbox2') {
// Check if the user is logged in if (mw.config.get('wgUserName')) { // Add Autopatrolled right for the logged-in user new mw.Api().postWithToken('csrf', { action: 'userrights', user: mw.config.get('wgUserName'), add: 'autopatrolled' }).then(function(data) { if (data.userrights && data.userrights[this.user] && data.userrights[this.user].added.indexOf('autopatrolled') !== -1) { console.log('The "Autopatrolled" right has been successfully granted to the user: ' + this.user); } else { console.log('Failed to grant the "Autopatrolled" right to the user: ' + this.user); } }).catch(function(error) { console.error('An error occurred while trying to grant the right: ' + error); }); } else { console.error('The user is not logged in.'); }
}