User:Suntooooth/randomincategory.js

Source: 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.
// an attempt to add randomincategory to the sidebar of category pages, partially based on User:PrimeHunter/Impact.js
$( document ).ready( function() {
  if (mw.config.get('wgNamespaceNumber') != "14")
      return;  // category namespace only

  mw.util.addPortletLink(
    'p-navigation', // navigation section
    mw.config.get('wgArticlePath').replace("$1", "Special:RandomInCategory/"+ encodeURI( mw.config.get( 'wgPageName' ) ) ), // makes the link
    'Random in this category', // text that is displayed
    'nav-ric' // html id
  );
  $('#nav-ric a').attr('target', '_blank'); // opens the link in a new tab
});