User:Rich Farmbrough/ParserProfile.js
mw.util.addPortletLink(
'p-tb',
'#',
'Parse profile → WP',
'ca-parser-wikitable',
'Convert parser profiling comments to wikitables'
);
document.getElementById('ca-parser-wikitable').addEventListener('click', function (e) {
e.preventDefault();
const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_COMMENT);
const comments = [];
while (walker.nextNode()) comments.push(walker.currentNode);
const tables = [];
for (const comment of comments) {
const text = comment.textContent.trim();
if (text.startsWith('NewPP limit report')) {
const lines = text.split('\n').slice(1).map(l => l.trim()).filter(Boolean);
const rows = lines.map(line => {
if (line.includes(':')) {
return line.split(/:\s+/, 2);
} else if (line.startsWith('Parsed by ')) {
const parts = line.split(/\s+/, 3);
return [parts[0] + ' ' + parts[1], parts[2]];
} else {
return ['Unknown', line];
}
});
tables.push([
'{| class="wikitable"',
'! Metric !! Value',
...rows.map(r => '|-\n| ' + r[0] + ' || ' + r[1]),
'|}'
].join('\n'));
} else if (text.startsWith('Transclusion expansion time report')) {
const lines = text.split('\n').slice(1).map(l => l.trim()).filter(Boolean);
const rows = lines.map(line => {
const m = line.match(/^([\d.]+)%\s+([\d.]+)\s+(\d+)\s+(.*)$/);
return m ? m.slice(1) : null;
}).filter(Boolean);
tables.push([
'{| class="wikitable sortable"',
'! % !! Time (ms) !! Calls !! Template',
...rows.map(r => '|-\n| ' + r.join(' || ')),
'|}'
].join('\n'));
}
}
const output = tables.join('\n\n');
if (!output) {
alert("No profiling comments found.");
} else {
const w = Math.floor(window.innerWidth * 0.25);
const h = Math.floor(window.innerHeight * 0.25);
const left = Math.floor((window.screenX || window.screenLeft) + window.innerWidth / 2 - w / 2);
const top = Math.floor((window.screenY || window.screenTop) + window.innerHeight / 2 - h / 2);
const popup = window.open('', '', `width=${w},height=${h},left=${left},top=${top},resizable=yes`);
popup.document.write(`
<html><head><title>Parser Profiling</title></head>
<body style="margin:0.5em; font-family:sans-serif">
<button onclick="navigator.clipboard.writeText(document.getElementById('out').value)">Copy to Clipboard</button><br>
<textarea id="out" style="width:100%; height:85%; box-sizing:border-box;">${output.replace(/</g, '<').replace(/>/g, '>')}</textarea>
</body></html>
`);
popup.document.close();
}
});
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.