User:Manojk/catgraphtabs.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
/*
 *    Adds http://toolserver.org/~dapete/catgraph tabs to the tab bar: one for files and two for categories.
 *    Tested on Monobook and Vector skin
 *    Usage: add the following line to your [[Special:Mypage/common.js]]/[[Special:Mypage/monobook.js]]/[[Special:Mypage/vector.js]]:
 *    mw.loader.load("//commons.wikimedia.org/w/index.php?title=User:Saibo/catgraphtabs.js&action=raw&ctype=text/javascript"); // use tracking: [[User:Saibo/catgraphtabs.js]]
 *
 *    Watch this page to be notified on changes! This is not a stable gadget!
 *
 *    Authors of the base code at http://de.wikipedia.org/w/index.php?title=MediaWiki:Gadget-toolserver-integration.js&action=history   (Merlissimo, Arnomane, ...)
 *    This script is JSHint valid.
 */
/*global jQuery:false, mw:false */
jQuery(document).ready(function () {
  'use strict';

  var tab_SaiboCG_file = 'CG';
  var tab_SaiboCG_file_tooltip = 'Catgraph';
  var tab_SaiboCG_super = 'CG-↑↑';
  var tab_SaiboCG_super_tooltip = 'Catgraph of super categories';
  var tab_SaiboCG_sub = 'CG-↓↓';
  var tab_SaiboCG_sub_tooltip = 'Catgraph of sub categories';

  if (mw.config.get('wgAction') === 'view') {
    switch (mw.config.get('wgNamespaceNumber')) {

    case 6:
      mw.util.addPortletLink('p-cactions', '//toolserver.org/~dapete/catgraph/graph.php?wiki=commons&lang=&ns=6&cat=' + mw.util.rawurlencode(mw.config.get('wgTitle')), tab_SaiboCG_file, 'ca-SaiboCG_file', tab_SaiboCG_file_tooltip);
      break;
    case 14:
      mw.util.addPortletLink('p-cactions', '//toolserver.org/~dapete/catgraph/graph.php?wiki=commons&lang=&sub=0&cat=' + mw.util.rawurlencode(mw.config.get('wgTitle')), tab_SaiboCG_super, 'ca-SaiboCG_super', tab_SaiboCG_super_tooltip);
      mw.util.addPortletLink('p-cactions', '//toolserver.org/~dapete/catgraph/graph.php?wiki=commons&lang=&sub=1&cat=' + mw.util.rawurlencode(mw.config.get('wgTitle')), tab_SaiboCG_sub, 'ca-SaiboCG_sub', tab_SaiboCG_sub_tooltip);
      break;
    default:
      // nothing
    }
  }
});

// [[Category:User scripts]]