User:Erutuon/scripts/contributionsTab.js

From Wiktionary, the free dictionary
Jump to navigation Jump to search

Note – after saving, you may have to bypass your browser’s cache to see the changes.

  • Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh);
  • Konqueror and Chrome: click Reload or press F5;
  • Opera: clear the cache in Tools → Preferences;
  • Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.

/*
Adds a "contributions" tab at the top of user pages, next to "watch"/"unwatch".

To enable this script, add this code to your [[Special:MyPage/common.css]] here on Wiktionary
-------------------------------------------------
importScript("User:Erutuon/contributionsTab.js");
-------------------------------------------------

or use this code on other wikis.
-------------------------------------------------
mw.loader.load('//en.wiktionary.org/w/index.php?title=User:Erutuon/contributionsTab.js&action=raw&ctype=text/javascript');
-------------------------------------------------
*/

if ( [ 2, 3 ].indexOf(mw.config.get("wgNamespaceNumber")) !== -1 ) {
	//If we're in User or User talk namespace
	var username = mw.config.get("wgPageName").match(/^User(?:_talk)?\:([^\/]+)(?:\/.+)?$/);
	if (username !== null) {
		username = username[1];
	
		mw.util.addPortletLink(
			"p-cactions",
			"/wiki/Special:Contributions/" + username,
			"Contributions",
			null,
			"View this user\'s contributions"
		);
	} /* else {
		console.log("Username not found in pagename.");
	}
} else {
	console.log("No contributions tab added: not user or user talk namespace.");
		*/
}