Jump to content

User:Suntooooth/randomincategory.js

From Wikipedia, the free encyclopedia
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
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
});