Jump to content

User:Novem Linguae/Scripts/SpeciesHelper.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Novem Linguae (talk | contribs) at 15:59, 22 December 2021 (create). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
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.
// <nowiki>

/*
- 
*/

$(function() {
	function shouldRunOnThisPage() {
		// don't run when not viewing articles
		let action = mw.config.get('wgAction');
		if ( action != 'view' ) return false;
		
		// don't run when viewing diffs
		let isDiff = mw.config.get('wgDiffNewId');
		if ( isDiff ) return false;
		
		let isDeletedPage = ( ! mw.config.get('wgCurRevisionId') );
		if ( isDeletedPage ) return false;
		
		// Only run in mainspace or draftspace
		let namespace = mw.config.get('wgNamespaceNumber');
		let isMainspaceOrDraftspace = ( [0, 118].includes(namespace) );
		if ( isMainspaceOrDraftspace && title != 'User:Novem_Linguae/sandbox' ) return false;

		return true;
	}

	if ( ! shouldRunOnThisPage() ) return;

	mw.util.addPortletLink(
		'p-cactions',
		'#',
		'Add taxobox',
		'#AddTaxobox'	// can't put comma here, silent error
	);

	$('#AddTaxobox').on('click', function() {
		// e.g. Draft:Aloe_framesii
		let title = mw.config.get('wgPageName'); // includes namespace, underscores instead of spaces
		
		let titleNoNamespace = title.replace('Draft:', '');

		let matches = titleNoNamespace.match(/^([^_]+)_([^_]+)$/) || alert('Unable to parse genus and species!');

		let genus = matches[1];
		let species = matches[2];
	});
});

// </nowiki>