User:Mr.Z-man/autopatrol.js

function autopatrolclick { debug = false; if (window.location.href.indexOf('debug=1') != -1) { debug = true; } var username = $('#mw-np-username').val; var bits = $('link[rel="alternate"]')[1].href.split('&'); var ns = 0; var lim = 50; var start = false; var hidepat = false; var hidered = true; for (var i=0; i500 && $.inArray('sysop', mw.config.get('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]); } }  $.post(mw.config.get('wgServer')+wgScriptPath+'/api.php', params, 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) { params = {'action':'patrol', 'token':token, 'rcid':rcid } $.post(mw.config.get('wgServer')+wgScriptPath+'/api.php', params); } 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); }