User:Ch1902/global.js

From Meta, a Wikimedia project coordination wiki

Note: After publishing, 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 / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
if (typeof $.addActionMenuItem === 'undefined') {
   $.extend({
      /**
       * Add a new link to the page action dropdown menu
       */
      addActionMenuItem: function (text, href, id, how) {
         return $('<li/>').attr({id: id || ''}).append(
            $('<a/>').attr('href', href).text(text)
         )[(how || 'append') + 'To']('#p-cactions ul');
      },
      /**
       * Add a new link to the page view menu
       */
      addViewMenuItem: function (text, href, id, how) {
         return $('<li/>').attr({id: id || ''}).append(
            $('<span/>').append(
               $('<a/>').attr('href', href).text(text)
            )
         )[(how || 'prepend') + 'To']('#p-views ul');
      }
   });
}

$(function () {
   
   if (mw.config.get('wgDBname') !== 'commonswiki' && mw.config.get('wgDBname') !== 'wikidatawiki')
      $.addViewMenuItem('Wikidata', 'http://www.wikidata.org/wiki/Special:ItemByTitle/' + mw.config.get('wgDBname')  + '/' + mw.config.get('wgPageName').replace(/_/gi, ' '));
      
   switch (mw.config.get('wgDBname'))
   {
      case 'enwiki':
         $.addActionMenuItem('COM:Watch', '//commons.wikimedia.org/wiki/Special:Watchlist');
         $.addActionMenuItem('WD:Watch', '//www.wikidata.org/wiki/Special:Watchlist');
      break;
      case 'commonswiki':
         $.addActionMenuItem('WP:Watch', '//en.wikipedia.org/wiki/Special:Watchlist');
         $.addActionMenuItem('WD:Watch', '//www.wikidata.org/wiki/Special:Watchlist');
      break;
      case 'wikidatawiki':
         $.addActionMenuItem('WP:Watch', '//en.wikipedia.org/wiki/Special:Watchlist');
         $.addActionMenuItem('COM:Watch', '//commons.wikimedia.org/wiki/Special:Watchlist');
      break;
      default:
         $.addViewMenuItem('文/A', 'http://translate.google.com/translate?sl=auto&tl=en&u=' + window.location.href);
         $.addActionMenuItem('WP:Watch', '//en.wikipedia.org/wiki/Special:Watchlist');
         $.addActionMenuItem('COM:Watch', '//commons.wikimedia.org/wiki/Special:Watchlist');
         $.addActionMenuItem('WD:Watch', '//www.wikidata.org/wiki/Special:Watchlist');
      break;
   }
   
   // run things after async loaded
   $(document).trigger('ch1902.global');
});