User:JJPMaster/CurateThisPage2/markpatrolled1.js

From Uncyclopedia, the content-free encyclopedia
Jump to navigation Jump to search

Note: After saving, you have to bypass your browser's cache to see the changes.

  • Internet Explorer: hold down the Ctrl key and click the Refresh or Reload button, or press Ctrl+F5.
  • Firefox: hold down the Shift key while clicking Reload; alternatively press Ctrl+F5 or Ctrl-Shift-R.
  • Opera, Konqueror and Safari users can just click the Reload button.
  • Chrome: press Ctrl+F5 or Shift+F5
var page_title = mw.config.get("wgPageName");

mw.util.addPortletLink('p-cactions', '#', 'Mark as patrolled', 'markpatrolled', 'Just mark this goddamn page as patrolled!');

$("#markpatrolled").click(() => {
	patrol_page();
});

function patrol_page() {
	var params = {
			action: 'query',
			list: 'recentchanges',
			rcprop: 'title|ids|sizes|flags|user',
			rctitle: page_title,
			rclimit: 1,
			format: 'json'
		},
		api = new mw.Api();
	
	api.get( params ).done( function ( data ) {
		var recentchanges = data.query.recentchanges,
			rc;
		for ( rc in recentchanges ) {
			var revision_id = recentchanges[rc].revid;
			var patrol_params = {
			action: 'patrol',
			revid: revision_id,
			format: 'json'
		},
		patrol_api = new mw.Api();
	
		patrol_api.postWithToken( 'patrol', patrol_params ).done( function ( data ) {
			mw.notify( "Page successfully marked as patrolled!" );
			console.log( data );
		} );
	
		}
	} );
}