User:Dschwen/fpchelper.js

// // Script to help preparing the closing of an FP candidate

var FPCHelper = {

FPCatList : null, FPCatListXHR : null, FPRoot : '[[Wikipedia:Featured pictures/',

parseList : function { with( FPCHelper ) {  if( FPCatListXHR.readyState == 4 ) { var i = 0, j,k; FPCatList = new Array;

while( ( j = FPCatListXHR.responseText.indexOf( FPRoot, i ) ) != -1 ) {    if( ( k = FPCatListXHR.responseText.indexOf( '|', j ) ) != -1 ) {     FPCatList.push(        FPCatListXHR.responseText.substring( j + FPRoot.length, k ) ); }     i = j + FPRoot.length; }

// store as cookie var expiry = new Date; expiry.setTime( expiry.getTime + ( 7 * 24 * 60 * 60 * 1000) ); // +7days document.cookie = 'FPCatListCache=' + encodeURI(FPCatList.join('|')) + '; expires=' + expiry.toGMTString;

} } },

getFPCategories : function {  with( FPCHelper ) {

// First try if there is a cookie with the list var cookies = document.cookie.split('; '); for (var i = 0; i < cookies.length; i++) {   if( cookies[i].substr(0, 15) == 'FPCatListCache=' ) FPCatList = decodeURI(cookies[i].substr(15)).split('|'); }

// If not, then get WP:FP and build the list if( FPCatList == null ) {   FPCatListXHR = sajax_init_object; FPCatListXHR.open("GET", "/wiki/Wikipedia:Featured_pictures?action=raw", true); FPCatListXHR.onreadystatechange = FPCHelper.parseList; FPCatListXHR.send( null ); } } },

install : function { FPCHelper.getFPCategories; } }

addOnloadHook( FPCHelper.install );

//