User:Tiptoety/culoghelper.js

/* * Small script to help navigate the CU log. * Turns timestamps of a filtered CU log like on [//en.wikipedia.org/wiki/Special:CheckUser/Log?cuSearchType=target&cuSearch=Example] * into links that try to locate the entry in the full log. * This simplifies looking at the context of a previous check. */ jQuery(function($){	if ( mw.config.get( 'wgPageName' ) == 'Special:CheckUser/Log' )	{		mw.loader.using( 'mediawiki.util', function { var paraCuloghighlight = mw.util.getParamValue('culogHighlight'); var paraCusearch = mw.util.getParamValue('cuSearch'); if (!paraCuloghighlight && !paraCusearch) return; //collect all date text nodes var dateNodes = $("#bodyContent > ul > li").map(function(i,n){return $(n).contents.first;}) //highlight the date node we clicked if (paraCuloghighlight) {				dateNodes.each(function(i,n){					if(n[0].textContent !== paraCuloghighlight) return;					//highlight					n.wrap(" ");					//and scroll into view					var windowtop = $(window).scrollTop;					var windowbottom = windowtop + $(window).height;					var ntop = n.parent.offset.top;					var nbottom = ntop + n.parent.outerHeight(true);					if (ntop < windowtop) $(window).scrollTop(ntop);					else if (nbottom > windowbottom) $(window).scrollTop(nbottom + windowtop- windowbottom);					//only the first we find. May not be the one we clicked ...					return false;				}); }			//link all date nodes to the full log view if (paraCusearch) {				dateNodes.wrap(function{					//calculate one hour into the future; this will be the upper limit of the log displayed					var dateText = $(this)[0].textContent;					var dateMs = Date.parse(dateText);					if (isNaN(dateMs)) return;					var dateOffset = new Date( dateMs + 1000*60*60 );					var dateOffsetString = "" + dateOffset.getFullYear + (dateOffset.getMonth<9?"0"+(dateOffset.getMonth+1):(dateOffset.getMonth+1)) + (dateOffset.getDate<10?"0"+dateOffset.getDate:dateOffset.getDate) + (dateOffset.getHours<10?"0"+dateOffset.getHours:dateOffset.getHours) + (dateOffset.getMinutes<10?"0"+dateOffset.getMinutes:dateOffset.getMinutes);					return "";				}); }		});	} });