User:Ritchie333/drafts.js

function getDrafts( projectName, continueId ) { $.ajax( {		type: "GET",		url: mw.util.wikiScript( 'api' ),		data: { action:'query',		 list:'embeddedin',		  format:'json',		  rawcontinue:,		  eititle:'Template:' + projectName,		  eidir:'ascending',		  eicontinue:continueId,		  einamespace:119 },		dataType: 'json',		success: function( data ) {			var results = data.query.embeddedin;			if( results.length > 0 ) {				var titles = ;				var i;				var first = true;				for( i = 0; i < results.length; ++i ) {					if( first ) {						first = false;					} else {						titles += '|';				}					var draftName = results[ i ].title.substr( 'Draft talk:'.length );					titles += ( 'Draft:' + draftName );				}				$.ajax( { type: "GET", url: mw.util.wikiScript( 'api' ), data: { action:'query', prop:'categories', format:'json', titles:titles, clcategories:'Category:Pending AfC submissions' },					dataType: 'json', success: function( redata ) { for( var page in redata.query.pages ) { nextPage = redata.query.pages[ page ]; var pageTitle = nextPage.title; for( var cat in nextPage.categories ) { nextCategory = nextPage.categories[ cat ]; if( nextCategory.title === 'Category:Pending AfC submissions' ) { // Got it									$('#related-drafts').append( 										'' + pageTitle + ' ' ); }							}						}					}				});				if ( typeof data[ 'query-continue' ] != 'undefined' ) {					getDrafts( projectName, data[ 'query-continue' ].embeddedin.eicontinue );				}			}		}	}); }

jQuery(function {	mw.loader.using( ['mediawiki.util'], function  { if( mw.config.get('wgPageName').indexOf( 'Wikipedia:WikiProject' ) === 0 ) { if(mw.config.get('wgAction') == 'view' || mw.config.get('wgAction') == 'purge' ){ var portletLink = mw.util.addPortletLink('p-tb', '#', 'Draft list', 't-draft-list', 'List drafts for this project'); $( portletLink ).click( function ( e ) {			e.preventDefault;			var projectName = mw.config.get('wgPageName').substr( 'Wikipedia:'.length );			mw.util.$content.prepend( ' Related drafts ' );			getDrafts( projectName, undefined /* no continue */ );		} ); }	 }	}); });