User:MarkTraceur/autopatrol.js

function autopatrolclick { var api = new mw.Api; debug = mw.config.get( 'debug' ); var username = $('#mw-np-username').val; var bits = $('link[rel="canonical"]')[0].href.split('&'); var ns = 0; var lim = 50; var start = false; var hidepat = false; var hidered = true; for (var i=0; i500 && $.inArray('sysop', wgUserGroups) == -1) { lim = 500; } var params = {'action':'query', 'list':'recentchanges', 'rcuser':username, 'rctype':'new', 'rcnamespace':ns, 'rclimit':lim, 'rctoken':'patrol', 'rcdir':dir, 'rcprop':'ids|patrolled', 'format':'json' } if (start) { params['rcstart'] = start; } if (hidepat) { params['rcshow'] = '!patrolled'; if (hidered) { params['rcshow'] += '|!redirect'; } } else if(hidered) { params['rcshow'] = '!redirect'; } $('#autopatrolbutton').after(''); $('#autopatrol-done').ajaxStop(function {   $(this).html('  Finished!');  }); if (debug) { for (var p in params) { console.log(p); console.log(params[p]); } }  api.post( params ).then( function ( data ) {    rclen = data['query']['recentchanges'].length    for (var i=0; i<rclen; i++) {      if (typeof(data['query']['recentchanges'][i].patrolled) != "undefined" ) {        continue;      }      if (!debug) {    	 autopatrol(data['query']['recentchanges'][i]['rcid'], data['query']['recentchanges'][i]['patroltoken']);      }    }  } ); }

function autopatrol(rcid, token, last) { var api = new mw.Api; api.post( { 	'action':'patrol',    'token':token,    'rcid':rcid  } ); } function autopatrollink { if (document.getElementById('mw-np-username').value) { button = document.createElement('input'); button.type = 'button'; button.id = 'autopatrolbutton'; button.value = 'Autopatrol'; button.onclick = autopatrolclick; button.title = 'Autopatrol all edits by this user'; document.getElementById('mw-np-username').parentNode.appendChild(button); } }

if (mw.config.get('wgPageName') == 'Special:NewPages') { $(document).ready(autopatrollink); }