Jump to content

User:Drrngrvy/monobook.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.
// [[User:Zocky/PicturePopups.js]]
document.write('<script type="text/javascript" src="' 
             + 'http://en.wikipedia.org/w/index.php?title=User:Zocky/PicturePopups.js' 
             + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');

try {
  var ch = get("//div[@id='bodyContent']/dl/dd/span[@class='plainlinks']/i[contains(.,'initial letter is capitalized')]/b").snapshotItem(0);
  var correction = ch.innerHTML;
  var articleTitle = get("//div[@id='content']/h1[@class='firstHeading']").snapshotItem(0);
  var template = ch.parentNode.parentNode.parentNode;

  // check if the original and correct versions match
  // this avoids acting on non-"real" uses of the template
  if(articleTitle.innerHTML.toLowerCase() == correction.toLowerCase()) {
    // Correct the page title
    document.title = document.title.replace(articleTitle.innerHTML, correction);
  
    // Correct the article title
    articleTitle.innerHTML = correction;
  
    // Remove template
    template.style.display = "none";
  }
}
catch(e){}

function get(query, context) {
  return document.evaluate(
    query,
    document,
    null,
    XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
    context
  );
}