Jump to content

User:Iamojo/iare.js

From Wikipedia, the free encyclopedia
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.
/*
	Adds a toolbox link to load Reference Explorer of the current page.

	Install by adding:
		importScript('User:iamojo/iare.js'); // [[User:iamojo/iare.js]]
	to your [[Special:MyPage/common.js]].
*/

mw.loader.using('mediawiki.util', function() {
	if (mw.config.get('wgNamespaceNumber') < 0) {
		return;
	}

	var pageUrl = 'https://' + mw.config.get('wgServerName')
		+ mw.config.get('wgArticlePath').replace('$1', mw.config.get("wgPageName"))
		
	var url = 'https://archive.org/services/context/iare/?url=' + pageUrl
	// may need to endode url parameter vvalue here...
	
	var link = mw.util.addPortletLink(
		'p-tb',  // portletId - p-tb is "portlet toolbox"
		url,	 // href
		'Open Reference Explorer',  // text display
		'pt-iare', // unique id of list item
		'Open Reference Explorer for this article'
	);

	$( link ).click( function ( event ) {
            event.preventDefault();
        	var iareLink = $(this).find("a")[0].href
            window.open(iareLink);
		    return false;
        } );
});