User:Tollens/speciesListFormatter.js

/*   Quickly formats a list of species copied from Catalogue of Life or ITIS. To use, paste the list into the dialog and click "Format", then copy the formatted list from the dialog. Footnotes will be attached to every entry. The tool does not validate input, so please ensure the resulting list is   correct before using it in an article.

To use this script, add the following line to your Special:MyPage/common.js:

importScript("User:Tollens/speciesListFormatter.js"); // Backlink: User:Tollens/speciesListFormatter.js

The button will be placed in the same menu as the "Move" button, which depending on the skin used could be called "More" or "Tools".

// $.when(mw.loader.using(["mediawiki.util"]), $.ready).done(function {    let button = mw.util.addPortletLink( "p-cactions", "#",       "Format species list", "ca-format-specieslist", "Format a species list from Catalogue of Life or ITIS" );

if (button) { button.addEventListener("click", function {            $( "   " ).dialog({ buttons: [ {                       text: "Format", click: function { let textarea = document.getElementById("speciesListFormatterTextarea"); let footnotes = document.getElementById("speciesListFormatterFootnoteInput").value.trim; textarea.value = textarea.value .trim .replace(/species:?( |\t)*/gi, "") .split("\n") .map((line) => line.trim) .map((line) => {                                   const isExtinct = line.includes("†");                                    line = line.replace(/† */, "");

const secondSpace = line.indexOf(" ", line.indexOf(" ") + 1); return { name: line.substring(0, secondSpace), published: line.substring(secondSpace + 1).replace(/\(|\)/g, ""), extinct: isExtinct };                               })                                .map( (entry) => "* " +                                       (entry.extinct ? "" : "") + "" +                                       entry.name +                                        " " + entry.published + " " +                                       (footnotes !== ""                                            ? ' ' + footnotes + " "                                            : "") )                               .join("\n");                        }                    }                ],                close: function  {                    $(this).dialog("destroy").remove;                },                width: Math.max(400, window.innerWidth / 2)            }); });   } }); //