User:Mike Dillon/Scripts/timeOnload.js
Appearance
< User:Mike Dillon | Scripts
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Mike Dillon/Scripts/timeOnload. |
// Requires: [[User:Mike Dillon/Scripts/easydom.js]]
// Requires: [[User:Mike Dillon/Scripts/toolbox.js]]
/* <pre><nowiki> */
var onloadFunctTimes = {};
var oldOnloadFuncts;
var oldWindowFuncts;
var oldRunOnloadHook = window.runOnloadHook;
window.runOnloadHook = function () {
var tf = function (func) {
var start = new Date();
func();
var end = new Date();
return {
start: start,
end: end,
diff: end.getTime() - start.getTime()
};
};
var wrapOnload = function (id, func) {
return function () {
onloadFunctTimes[id] = tf(func);
};
};
oldWindowFuncts = {};
var wrapWindowFunct = function (name, alias) {
if (!alias) alias = name;
oldWindowFuncts[alias] = window[name];
window[name] = wrapOnload(alias, oldWindowFuncts[alias]);
};
/*
wrapWindowFunct('histrowinit', 'hri');
wrapWindowFunct('unhidetzbutton', 'uhtb');
wrapWindowFunct('tabbedprefs', 'tp');
wrapWindowFunct('updateTooltipAccessKeys', 'utak');
wrapWindowFunct('akeytt');
wrapWindowFunct('scrollEditBox', 'seb');
wrapWindowFunct('setupCheckboxShiftClick', 'scsc');
wrapWindowFunct('sortableTables', 'st');
oldOnloadFuncts = window.onloadFuncts;
window.onloadFuncts = [];
for (var i in oldOnloadFuncts) {
window.onloadFuncts[i] = wrapOnload(i, oldOnloadFuncts[i]);
}
*/
var loadTime = tf(oldRunOnloadHook);
with (easydom) {
var createTooltip = function (lt) {
return "Start: " + lt.start.getTime() + ", End: " + lt.end.getTime();
};
var createOnloadFunctItem = function (id) {
return li(
{ "title": createTooltip(onloadFunctTimes[id]) },
a({ "href": "#",
"onclick": function () {
if (oldOnloadFuncts[id]) {
alert(oldOnloadFuncts[id]);
} else if (oldWindowFuncts[id]) {
alert(oldWindowFuncts[id]);
}
return false;
}
}, id), ": ", onloadFunctTimes[id].diff, " ms");
};
var d = div({ title: createTooltip(loadTime) },
strong('JS load time: '), loadTime.diff + ' ms');
var list = ul();
for (var id in onloadFunctTimes) {
list.appendChild(createOnloadFunctItem(id));
}
if (list.childNodes.length) {
d.appendChild(list);
}
addToolboxLink(null, d);
}
};
/* </nowiki></pre> */