MediaWiki:Common.js

Revision as of 01:05, 17 November 2015 by Vid (Talk | contribs)

Note: After saving, 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: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Clear the cache in Tools → Preferences
/* Any JavaScript here will be loaded for all users on every page load. */

var basePage = getParameterByName('Scenario_Task_Translation[Base+Page]');

if ($('textarea[name="Scenario Task Translation[Scenario Task Description]"]') && basePage) { // 
  var query = 'https://learn.equalit.ie/mw/api.php?action=ask&query=[[' + basePage + ']]|?Scenario Task Description&format=json';
  console.log('q', query);
  $.getJSON(query, function(data) {
    var val;
    try {
      var val = data.query.results[basePage.replace(/\+/g, ' ')].printouts['Scenario Task Description'][0];
      $('textarea[name="Scenario Task Translation[Scenario Task Description]"]').after('<div style="font-family: monospace; font-size: 70%">' + val.replace(/\n/g, '<br />') + '</div>');
    } catch (e) {
      window.d = data;
      console.log("failed parsing", e, 'data', data, 'val', val);
    }
  });
}

function getParameterByName(name) {
  if (window.location.search.indexOf(name) > -1) {
    value = window.location.search.split('&')[1].split('=')[1];
    return value;
  }
}