MediaWiki:Common.js

From Heroes of Might and Magic: Olden Era Official Wiki
Revision as of 14:59, 11 September 2026 by Aurelain (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.
/* Any JavaScript here will be loaded for all users on every page load. */

$(function() {
  var $box = $('#spellboxv-display');
  $('.spell-link').hover(
    function() {
      var spellName = $(this).data('spell');
      var apiUrl = mw.util.wikiScript('api');
      $.post(apiUrl, {
        action: 'parse',
        format: 'json',
        text: '{{#invoke:SpellTableUtil|spellBoxV|name=' + spellName + '}}',
        contentmodel: 'wikitext'
      }, function(data) {
        var html = data.parse.text['*'];
        $box.html(html).show();
      });
    },
    function() {
      $box.hide().empty();
    }
  );
});

/* Purge cache button for the toolbox sidebar. */

mw.loader.using('mediawiki.util').then(function () {
    mw.util.addPortletLink(
        'p-tb',
        mw.util.getUrl(null, {
            action: 'purge',
            forcelinkupdate: 1
        }),
        'Update page cache',
        't-purge'
    );
});

/* Load the HeroPlanner logic. */
mw.hook('wikipage.content').add(function () {
    if (mw.config.get('wgPageName').includes('Hero_Planner')) {
        var VERSION = '1'; // Bump this string when you need to ensure no cache
        var scriptUrl = mw.util.wikiScript('index') + '?' + $.param({
            title: 'MediaWiki:HeroPlanner.js',
            action: 'raw',
            ctype: 'text/javascript',
            version: VERSION
        });
        mw.loader.load(scriptUrl);
    }
});