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=[%20{%20%22ids%22:%20[32353,%2026065,%2026079],%22include_fields%22:[%22last_change_time%22,%22status%22]}%20] https://bugzilla.wikimedia.org/jsonrpc.cgi?method=Bug.get&id=158&params%5Bids%5D%5B%5D=300&params%5Bids%5D%5B%5D=400&params%5Bids%5D%5B%5D=500&params%5Binclude_fields%5D%5B%5D=last_change_time&params%5Binclude_fields%5D%5B%5D=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 (params) {		base = "https://bugzilla.wikimedia.org/jsonrpc.cgi?";		tail = [];		$.each(params, function(key, value) { tail.push(key + "=" + encodeURIComponent(value)); });		return base + tail.join("&");	};

var updateBugs = function(data) { console.log(data);	//debug };

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

//get status object for all ids console.log(ids); //debug

params = { method: 'Bug.get', id: '158', params: { ids: ids, include_fields: fields },		callback: 'updateBugs' };

script.type = 'text/javascript'; script.src = genParamUrl(params); body.appendChild(script);

})(jQuery);