User:Splarka/showcomments.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//Simple script to scrape a page's html comments (looking for 'served by' and 'newpp').

$(function() {
  mw.util.addPortletLink('p-tb','javascript:alert(dumpComments(document.getElementsByTagName("body")[0]));','Page stats');
})

function dumpComments(obj) {
  var childs = 0; var txt = '';
  if(obj.nodeType == 8 && obj.nodeValue.search(/(NewPP|Served by)/) != -1) { 
    txt += obj.nodeValue;
  }
  while(obj.childNodes[childs]) {
    txt += dumpComments(obj.childNodes[childs]);
    childs++;
  }
  return txt;
}