Jump to content

User:DannyS712 test/Flagged revs patroller.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by DannyS712 test (talk | contribs) at 11:44, 1 December 2019 (start). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//<nowiki>
$(function (){
var patroller_config = {
	name: '[[User:DannyS712/patrol|patrol.js]]',
	version: 1.1,
	debug: true,
	comment: "BOT: Automatically patrolled"
};
mw.loader.using( [ 'mediawiki.util', 'mediawiki.api' ], function () {
    $(document).ready( function () { 
    	mw.util.addPortletLink ( 'p-cactions', 'javascript:void(0)', 'Get null changes', 'ca-getChanges');
    	mw.util.addPortletLink ( 'p-cactions', 'javascript:void(0)', 'Patrol changes', 'ca-patrolChanges');
    	$('#ca-getChanges').on('click', function() { getChanges(); } );
    	$('#ca-patrolChanges').on('click', function() { patrolChanges(); } );
    } );
} );
async function getChanges(){
	var data = await getFiltered();
	console.log( data );
	var stringy = JSON.stringify( data, null, 2 );
	console.log( stringy );
	//set_JSON ( 'User:DannyS712 test/patrol.json', stringy, 'Candidates to patrol');
}
async function getFiltered( offset ){
	return new Promise((resolve) => {
		new mw.Api().get({
			action: 'query',
			list: 'oldreviewedpages',
			ormaxsize: 0,
			orlimit: 'max',
	        formatversion: 2,
		}).done( function( response ){ 
			console.log( response );
			resolve( response );
		});
	});
}
function shouldPatrol( page ){
	if (page.diff_size === 0){
		if (checkChange( page.stable_revid, page.revid )){
			console.log("Will patrol:", page.title);
			return true;
		}
	}
	return false;
}
function checkChange( oldid, newid ){
	var old_content = get_page( oldid );
	var new_content = get_page( newid );
	//console.log( old_content, new_content );
	if (old_content === new_content) return true;
	return false;
}
function get_page( revid ){
	return new Promise((resolve) => {
		new mw.Api().parse({
			revid: revid,
			prop: 'wikitext',
		}).always( function ( response ) {
			console.log( response );
			resolve( response );
		});
	});
}
function doPatrol( revid ){
	return new Promise((resolve) => {
		new mw.Api().postWithEditToken({
			action: 'review',
			revid: revid,
			comment: 'Testing',
		}).always( function ( response ) {
			console.log( response );
			resolve( response );
		});
	});
}
});
//</nowiki>