User:Robmoen/bugStatusUpdate.js

/* * Bug Status Update Gadget * Author: Robmoen (robm) * Description: *   Finds and updates bug status templates on page load. * * Uses Bugzilla JSON RPC API

https://bugzilla.wikimedia.org/jsonrpc.cgi?method=Bug.get&id=158&params=[ { "ids": [32353, 26065, 26079],"include_fields":["last_change_time","status"]} ] https://bugzilla.wikimedia.org/jsonrpc.cgi?method=Bug.get&id=158&params[ids][]=300&params[ids][]=400&params[ids][]=500&params[include_fields][]=last_change_time&params[include_fields][]=status&callback=updateBugs */

(function($){	var					ids = [],			bugs = [],						params = {},			fields = ["last_change_time", "status"],			body = document.getElementsByTagName('body')[0],			script = document.createElement('script');	var genParamUrl = function (ids) {		base = 'https://bugzilla.wikimedia.org/jsonrpc.cgi?method=Bug.get&id=158&params=[ { "ids": ['+ ids.join(',') +'],"include_fields":["last_change_time","status", "id"]}]&callback=mw.updateBugsGadget';		return encodeURI(base);	};

mw.updateBugsGadget = function(data) { var color = { "RESOLVED": "green", "CRITICAL": "red" };		//console.log(data);	//debug if(data.result.bugs) { for(var b in data.result.bugs) { console.log(data.result.bugs[b].status); $('.mw-trackedTemplate') .find('a[title^="bugzilla:'+data.result.bugs[b].id+'"]') .parent .next('p') .children('span') .css('color', color[data.result.bugs[b].status]) .text(data.result.bugs[b].status); }		}		};

$('.mw-trackedTemplate').each(function {		var title = $(this).find('a[title^="bugzilla:"]').attr('title');		ids.push(title.split(':')[1]);		bugs.push( $( this ) );	});

script.type = 'text/javascript'; script.src = genParamUrl(ids);

body.appendChild(script);

})(jQuery);