MediaWiki:Gadget-NewPP-report.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
/**
 * @description:
 * This script makes the [[mw:NewPP parser report]] visible on every content page at the bottom.
 * @required modules: 'mediawiki.util'
 */
$(function () {
'use strict';
$(mw.util.addPortletLink('p-cactions', '#', 'NewPP report')).on('click', function (e) {
	e.preventDefault();
	$(this).remove();
	e = null;
	$('.mw-parser-output').contents().filter(function () {
		return this.nodeType === 8 && /^\s*(NewPP|Transclusion|Saved) /.test(this.data);
	}).replaceWith(function () {
		var pre = $('<pre>', { dir: 'ltr' }).text($.trim(this.data));
		if (!e) e = pre[0];
		return pre;
	});
	if (e) e.scrollIntoView();
});
});