משתמש:Guycn2/PerformanceInfo.js
הערה: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.
- פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
- גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
- אינטרנט אקספלורר / אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
- אופרה: ללחוץ על Ctrl-F5.
/*
הוספת כפתור בתיבת הכלים להצגת מידע על ביצועי המפענח
*/
$(function () {
'use strict';
if (
!mw.config.get('wgArticleId') || // wgPageParseReport returns null on non-existing pages
!$('#t-info').length // Same goes for pages where there is no "Page information" link, e.g. special pages
) {
return;
}
mw.loader.using('mediawiki.util').then(function () {
mw.util.addPortletLink('p-tb', '#', 'מידע על ביצועי המפענח', 't-performance_info', 'הצגת מידע על ביצועי המפענח', null, '#t-info')
.onclick = initialization;
function initialization(e) {
e.preventDefault();
if (mw.config.get('wgAction') === 'view') {
showPerformanceInfo();
}
else {
// Unfortunately, wgPageParseReport returns null when not in view mode,
// and thus we should first open the page in view mode to be able to retrieve the relevant information
window.open(mw.util.getUrl(mw.config.get('wgPageName'), {performanceInfo: '1'}));
}
}
if (mw.util.getParamValue('performanceInfo') === '1') {
showPerformanceInfo();
}
function showPerformanceInfo() {
mw.loader.using(['mediawiki.api', 'oojs-ui-windows', 'ext.pygments']).then(function () {
var report = mw.config.get('wgPageParseReport'),
container = $('<div>').css({'text-align': 'left', 'direction': 'ltr', 'font-size': '90%'});
if (report === null) return;
new mw.Api().get({
action: 'parse',
text: '<syntaxhighlight lang="json">' + JSON.stringify(report, null, '\t') + '</syntaxhighlight>',
prop: 'text'
}).done(function (data) {
container.append(data.parse.text['*']);
OO.ui.alert(container, {title: 'מידע על ביצועי המפענח', size: 'large'}).done(function () {
if (mw.util.getParamValue('performanceInfo') === '1' && self.opener) {
self.close();
}
});
});
});
}
});
});