User:AT/monobook.js

From Guild Wars Wiki
Jump to navigationJump to search

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.
/*
 I refactored wikiswap, finally, and mainly so I can leave maintenence to people
 who are actually active. It's now extensible, and you can do whatever
 you feel like with it. For basic usage, pass it a hostname of another wiki, 
 a title, name, and unique id. However, you can now do a couple of fancy things
 using the modifier parameter.

 For instance, say I wanted to add a tab to search google images for the page name, 
 but only within a certain site.

 For this, you'd call:

  wiki_swapper('http:images.google.com/images?q=', 'google', 'Google Image Search', '_gis', add_site_search);

 Where the function add_site_search is defined as follows:

 function add_site_search(href) {
    return href + "+site:wiki.guildwars.com";
 }

 or, if you wanted to restrict the tab to certain namespaces, you could call a modifier like this:

 function modifier_func(href) {
   if(wgCanonicalNamespace == 'foo') {
       return false;
   }
   else {
       return href;
   }

 If the modifier function returns false, the tab won't be added. So, the modifier needs to take a 
 href as a parameter, and then either return the path to be used, or return false if no tab is to
 be added. Of course, you'll also need to include this page, or just copy the wiki_swapper and 
 addTab functions to your own monobook.js.

 Have fun!
*/


function addTab(url, name, id, title, key) { 
 return addPortletLink('p-cactions', url, name, id, title, key); 
}

/**
* This function provides a fairly simple interface for switching 
* between wikis. To use it, call wiki_swapper() within load_swapper()
* with the desired parameters.
*
* @author   AT
* @param    path          The base path of the site you'd like to switch to.
* @param    name          The name to be displayed on the tab
* @param    title         The tab's title attribute
* @param    identifier    A unique identifier to distinguish this tab
*                         from others. Used for styling, DOM manipulation
* @param    modifier      A function that can modify the final URI of the tab.
*/
function wiki_swapper(path, name, title, identifier, modifier) 
{
   href = path + wgCanonicalNamespace + ':' + wgTitle;
   if ( modifier != null ) {
      href = modifier(href);
   }
   if (href) addTab(href, name, "swapper_"+identifier, title, '');
}

/**
* Use this function to define your tabs. I've added a simple example - google 
* image search, only in the main namespace
*/
function load_swapper() {
  wiki_swapper('http://images.google.com/images?q=', 'google', 'Google Image Search', '_gis', add_site_search);
}

function add_site_search(href) {
   if(wgNamespaceNumber == '0') {
     return href+"+site:wiki.guildwars.com";
   }
   else {
     return false;
   }
}

// And add them to the page on load.
addOnloadHook(load_swapper);