User:Novem Linguae/Scripts/SpeciesHelper.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | This user script seems to have a documentation page at User:Novem Linguae/Scripts/SpeciesHelper. |
// <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>