MediaWiki:Gadget-transclusionreport.js

From Final Fantasy XIV Online Wiki
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
(() => {
  const iter = document.createNodeIterator(
    document.querySelector('#mw-content-text .mw-parser-output'),
    NodeFilter.SHOW_COMMENT
  );

  const output = document.createElement('pre');
  output.id = 'gadget-transclusionreport-output-pre';
  let node = iter.nextNode();
  // skip to first perf report
  while (!node.data.trim().startsWith("NewPP limit report")) {
    node = iter.nextNode();
  }
  // render all remaining comments at the end of the content
  while (node) {
    output.textContent += '\n\n' + node.data.trim();
    node = iter.nextNode();
  }

  const style = document.createElement('style');
  style.textContent = `
    #gadget-transclusionreport-output-pre {
      margin: 0;
      padding: 0.5rem 1rem;
    }
    #catlinks:not(.catlinks-allhidden) + #gadget-transclusionreport-output-pre {
      border-top: 0;
    }
    #gadget-transclusionreport-output-pre:not(:hover) {
      font-size: 0;
      transition: font-size step-end 300ms;
    }
    #gadget-transclusionreport-output-pre::before {
      display: block;
      content: "Transclusion performance report (hover)";
      font-size: 0.875rem;
      text-align: center;
    }
  `;

  document.querySelector('#bodyContent').append(output, style);
})();