Soft launch: Soldier biographies and research notes vary in completeness. Prefer class-roster, NARA, newspapers, and other cited sources for contested facts — treat Research notes as leads, not settled history. Anyone can correct a page; contact us with questions.
MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
Link MII/IPW team codes in research notes. |
Split mashed research notes; keep team links. |
||
| Line 2: | Line 2: | ||
* Hide leftover imported rows the infobox no longer shows. | * Hide leftover imported rows the infobox no longer shows. | ||
* Put the research-notes disclaimer under that section heading. | * Put the research-notes disclaimer under that section heading. | ||
* | * Split mashed CSV notes into separate bullets, then link MII/IPW team codes. | ||
*/ | */ | ||
$(function () { | $(function () { | ||
| Line 45: | Line 45: | ||
}); | }); | ||
return text; | return text; | ||
} | |||
function splitNotes(text) { | |||
text = $.trim(text || ''); | |||
if (!text) { | |||
return []; | |||
} | |||
text = text.replace(/"+/g, '"'); | |||
var parts = []; | |||
$.each(text.split(/[;"]+/), function (_, chunk) { | |||
chunk = $.trim(chunk.replace(/^['"]+|['"]+$/g, '')); | |||
if (!chunk) { | |||
return; | |||
} | |||
if (/https?:\/\//i.test(chunk)) { | |||
parts.push(chunk); | |||
return; | |||
} | |||
chunk = chunk.replace(/(\d{1,2}\/\d{1,2}\/\d{2,4})(?=[A-Za-z])/g, '$1\n'); | |||
$.each(chunk.split('\n'), function (__, bit) { | |||
bit = $.trim(bit.replace(/^['"]+|['"]+$/g, '')); | |||
if (!bit) { | |||
return; | |||
} | |||
var dated = bit.match(/^(.*?)\s+(\d{1,2}\/\d{1,2}\/\d{2,4})$/); | |||
if (dated && $.trim(dated[1]) && !/^\d{1,2}\/\d{1,2}\/\d{2,4}$/.test($.trim(dated[1]))) { | |||
parts.push($.trim(dated[1])); | |||
parts.push(dated[2]); | |||
} else { | |||
parts.push(bit); | |||
} | |||
}); | |||
}); | |||
return parts; | |||
} | } | ||
var negative = /fail(?:ed|ure)?|flunk|wash(?:ed)?\s*out|kick(?:ed)?\s*out|dismiss|expel|unsatisfactor|poor\s+(?:performance|work)|awol|court[-\s]?martial|disciplin|discharged\s+for\s+cause|drop(?:ped)?\s+(?:out|from)|relieved|eliminat|unfit|misconduct|desert/i; | var negative = /fail(?:ed|ure)?|flunk|wash(?:ed)?\s*out|kick(?:ed)?\s*out|dismiss|expel|unsatisfactor|poor\s+(?:performance|work)|awol|court[-\s]?martial|disciplin|discharged\s+for\s+cause|drop(?:ped)?\s+(?:out|from)|relieved|eliminat|unfit|misconduct|desert/i; | ||
$heading.nextAll('ul').first().find('li').each(function () { | var $ul = $heading.nextAll('ul').first(); | ||
if (!$ul.length) { | |||
return; | |||
} | |||
var items = []; | |||
if (clause && !negative.test(clause)) { | $ul.find('li').each(function () { | ||
$.each(splitNotes($(this).text()), function (_, clause) { | |||
if (clause && !negative.test(clause) && items.indexOf(clause) === -1) { | |||
items.push(clause); | |||
} | } | ||
}); | }); | ||
}); | |||
$ul.empty(); | |||
$.each(items, function (_, clause) { | |||
$ul.append($('<li>').html(linkifyTeams(clause))); | |||
}); | }); | ||
}); | }); | ||
Revision as of 07:02, 18 August 2026
/**
* Hide leftover imported rows the infobox no longer shows.
* Put the research-notes disclaimer under that section heading.
* Split mashed CSV notes into separate bullets, then link MII/IPW team codes.
*/
$(function () {
$('.infobox th, .soldier-infobox th, table.wikitable td').each(function () {
var text = $(this).text().replace(/\s+/g, ' ').trim();
if (
text === 'Overseas' ||
text === 'Over Seas Flag' ||
text === 'Special'
) {
$(this).closest('tr').remove();
}
});
var $heading = $('#Research_notes').closest('h2');
var $disclaimer = $('.mw-parser-output > .research-notes-disclaimer').first();
if ($heading.length && $disclaimer.length) {
$disclaimer.insertAfter($heading);
}
function teamHref(name) {
return '/index.php?title=' + encodeURIComponent('Team ' + name).replace(/%20/g, '_');
}
function teamLink(name, label) {
return '<a href="' + teamHref(name) + '" title="Team ' + name + '">' + label + '</a>';
}
function linkifyTeams(raw) {
var text = $('<div>').text(raw).html();
text = text.replace(/\bMII\s+(\d{2,4})\s*[-–]?\s*([A-Za-z])\b/gi, function (_, num, letter) {
var name = 'MII ' + num + '-' + letter.toUpperCase();
return teamLink(name, 'MII ' + num + '-' + letter.toUpperCase());
});
text = text.replace(/\bMII\s+(\d{2,4})\b/gi, function (_, num) {
return teamLink('MII ' + num, 'MII ' + num);
});
text = text.replace(/(?<!\bMII\s)\b([4-5]\d{2})\s*[-–]\s*([GIgi])\b/g, function (_, num, letter) {
var name = 'MII ' + num + '-' + letter.toUpperCase();
return teamLink(name, num + '-' + letter.toUpperCase());
});
text = text.replace(/\bIPW\s+(\d{1,4})\b/gi, function (_, num) {
return teamLink('IPW ' + num, 'IPW ' + num);
});
return text;
}
function splitNotes(text) {
text = $.trim(text || '');
if (!text) {
return [];
}
text = text.replace(/"+/g, '"');
var parts = [];
$.each(text.split(/[;"]+/), function (_, chunk) {
chunk = $.trim(chunk.replace(/^['"]+|['"]+$/g, ''));
if (!chunk) {
return;
}
if (/https?:\/\//i.test(chunk)) {
parts.push(chunk);
return;
}
chunk = chunk.replace(/(\d{1,2}\/\d{1,2}\/\d{2,4})(?=[A-Za-z])/g, '$1\n');
$.each(chunk.split('\n'), function (__, bit) {
bit = $.trim(bit.replace(/^['"]+|['"]+$/g, ''));
if (!bit) {
return;
}
var dated = bit.match(/^(.*?)\s+(\d{1,2}\/\d{1,2}\/\d{2,4})$/);
if (dated && $.trim(dated[1]) && !/^\d{1,2}\/\d{1,2}\/\d{2,4}$/.test($.trim(dated[1]))) {
parts.push($.trim(dated[1]));
parts.push(dated[2]);
} else {
parts.push(bit);
}
});
});
return parts;
}
var negative = /fail(?:ed|ure)?|flunk|wash(?:ed)?\s*out|kick(?:ed)?\s*out|dismiss|expel|unsatisfactor|poor\s+(?:performance|work)|awol|court[-\s]?martial|disciplin|discharged\s+for\s+cause|drop(?:ped)?\s+(?:out|from)|relieved|eliminat|unfit|misconduct|desert/i;
var $ul = $heading.nextAll('ul').first();
if (!$ul.length) {
return;
}
var items = [];
$ul.find('li').each(function () {
$.each(splitNotes($(this).text()), function (_, clause) {
if (clause && !negative.test(clause) && items.indexOf(clause) === -1) {
items.push(clause);
}
});
});
$ul.empty();
$.each(items, function (_, clause) {
$ul.append($('<li>').html(linkifyTeams(clause)));
});
});