Jump to content

User:DannyS712 test/remind bot.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by DannyS712 test (talk | contribs) at 04:20, 31 January 2019 (improve). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
RemindBot_config = {
	name: "[[User:DannyS712/Remind Bot.js|Remind Bot]]",
	version: 1.0,
	debug: true
};

mw.loader.using( 'mediawiki.util', function () {
    importScript('User:DannyS712 test/get JSON.js');
    importScript('User:DannyS712 test/set JSON.js');
    $(document).ready( function () { 
        var link = mw.util.addPortletLink( 'p-cactions', null, 'Remind BOT', 'ca-BOT-reminder', 'Check reminders'); 
        $( link ).click( function ( event ) {
            event.preventDefault();
            check_reminders();
        } );
    } );
} );
function check_reminders(){
	var arr_JSONed = get_JSON( 'User:DannyS712 test/reminders.json' );
	if (RemindBot_config.debug) console.log( arr_JSONed );
}
function get_page_list(){
	var get_pages = {
        action: 'query',
        list: 'categorymembers',
        cmlimit: 'max',
        cmtitle: 'Category:Wikipedians recieving reminders',
        cmprop: 'title',
        format: 'json'
    };
    var result = null;
	var scriptUrl = mw.config.get( 'wgScriptPath' ) + '/api.php';
	$.ajax({
		url: scriptUrl,
		type: 'get',
		data: get_pages,
		dataType: 'json',
		async: false,
		success: function(catResponse) {
	    	console.log( catResponse );
			var pages = catResponse.query.categorymembers;
			var listed = [];
			for (var i = 0; i < pages.length; i++) {
				if ( pages[i].ns === 2 ) {
					listed.push(pages[i].title + "/remind.json");
				}
			}
			if ( links === "" ) {
				alert( "There are no users recieving reminders." );
			}
			else {
		    	result = data;
			}
		} 
	});
	return result;
}