MediaWiki:Monobook.js

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)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for users using the Vector skin */

// This script only works in Vector right now, but the banner should degrade gracefully.
if (wgAction == 'view' && (wgPageName == 'Home' ||
                           wgPageName == 'Template:Main_Page_banner')) {
  var randomImages = [{image: 'http://commons.wikimedia.org/wiki/File:View_from_connors_hill_panorama.jpg',
                       author: "fir0002",
                       license: "GFDL 1.2"}];

  var randomImage = randomImages[Math.floor(Math.random() * randomImages.length)];

  var css = '#content {' +
            '  background-image: url(' + randomImage.image + ');' +
            '  background-size: 100%;' +
            '  background-repeat: no-repeat;' +
            '}' +
            '#main-page-banner {' +
            '  height: 12em;' +
            '  margin-bottom: 1em;' +
            '}' +
            '#main-page-welcome {' +
            '  text-shadow: #fff 0.3em 0.3em 1em, #fff -0.1em -0.1em 1em;' +
            '}' +
            '#main-page-credit {' +
            '  position: absolute; right: 0; top: -1em; font-size: 0.5em' +
            '}';
  var head = document.getElementsByTagName('head')[0];
  var style = document.createElement('style');

  style.type = 'text/css';
  if (style.styleSheet){
    style.styleSheet.cssText = css;
  } else {
    style.appendChild(document.createTextNode(css));
  }

  addOnloadHook(function() {
    var creditDiv = document.createElement('div');
    creditDiv.id = 'main-page-credit';
    var creditLink = document.createElement('a');
    creditLink.href = randomImage.page;
    creditLink.appendChild(document.createTextNode("Image: " + randomImage.author + ", " + randomImage.license));
    creditDiv.appendChild(creditLink);

    document.getElementById('mw-content-text').appendChild(creditDiv);
  });

  head.appendChild(style);
}

/* Hide the default page heading on pages using the color bar heading format */

function removeFirstHeading() {
    if ($("div.colorbar").length) {
        document.getElementById("firstHeading").className += " nodisplay";
        document.getElementById("contentSub").className += " nodisplay";
    }
}

addOnloadHook(removeFirstHeading);
Discuss this page