Jump to content

User:Suntooooth/randomincategory.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Suntooooth (talk | contribs) at 15:38, 24 January 2024. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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
    
    null, // mouseover text
    
    null // shortcut key
    
  );
  $('#nav-ric a').attr('target', '_blank'); // opens the link in a new tab
});