Skip to content

Commit

Permalink
New feature: Unnamed Infant
Browse files Browse the repository at this point in the history
A requested feature.
It checks for the same birth and death date and 'Unknown' or 'Unnamed' in the First Name fields.  It then sets the First Name and Preferred Name to 'Unnamed Infant', checks the 'No spouses' and 'No children' boxes, and adds a Died Young sticker.
  • Loading branch information
shogenapps committed Jun 1, 2024
1 parent 9a3cea9 commit d98d8bc
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import "./features/bioCheck/bioCheck";

// Edit mode Add Person addons are even later
import "./features/add_person/add_person";
import "./features/unnamed_infant/unnamed_infant";
import "./features/genderPredictor/genderPredictor";
import "./features/suggested_matches_filters/suggested_matches_filters";
import "./features/verifyID/verifyID";
Expand Down
1 change: 1 addition & 0 deletions src/features/register_feature_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ import "./spacepreview/spacepreview_options";
import "./surname_table/surname_table_options";
import "./table_filters/table_filters_options";
import "./unconnected_branch_table/unconnected_branch_table_options";
import "./unnamed_infant/unnamed_infant_options";
import "./usability_tweaks/usability_tweaks_options";
import "./what_links_here/what_links_here_options";
import "./wikitable_wizard/wikitable_wizard_options";
Expand Down
Empty file.
79 changes: 79 additions & 0 deletions src/features/unnamed_infant/unnamed_infant.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
Created By: Ian Beacall (Beacall-6)
*/
import $ from "jquery";
import { showCopyMessage } from "../access_keys/access_keys";
import { isProfileEdit, isProfileAddRelative, isAddUnrelatedPerson } from "../../core/pageType";
import { shouldInitializeFeature, getFeatureOptions } from "../../core/options/options_storage";

shouldInitializeFeature("unnamedInfant").then((result) => {
if (result) {
import("./unnamed_infant.css");
initUnnamedInfant();
}
});

function doUnnamedInfant() {
const firstName = $("#mFirstName").val();
const birthDate = $("#mBirthDate").val();
const deathDate = $("#mDeathDate").val();
const standardName = "Unnamed Infant";
const diedYoung = "{{Died Young}}";
const diedYoungWithoutEnd = "{{Died Young";

if (firstName.match(/unnamed|unknown/i) && birthDate == deathDate && birthDate != "") {
let message = "";
if (firstName != standardName) {
$("#mFirstName,#mRealName").val(standardName);
message = "First name changed to 'Unnamed Infant'";
}
if (isProfileEdit) {
$("input[name='mStatus_Spouse'],input[name='mNoChildren']").each(function () {
if ($(this).prop("checked") == false) {
$(this).trigger("click");
if ($(this).parent().text().includes("spouses")) {
message += "<br>'No spouses' checked";
} else {
message += "<br>'No children' checked";
}
}
});

let enhanced = false;
const enhancedEditorButton = $("#toggleMarkupColor");
if (enhancedEditorButton.attr("value") == "Turn Off Enhanced Editor") {
enhancedEditorButton.trigger("click");
enhanced = true;
}
const bioBox = $("#wpTextbox1");
const bio = bioBox.val();
// Search Biography for Died Young sticker
if (!bio.includes(diedYoungWithoutEnd)) {
// Find /== ?Biography ?==/ and insert Died Young sticker after it.
const bioIndex = bio.search(/== ?Biography ?==/);
if (bioIndex != -1) {
const bioStart = bio.slice(0, bioIndex + 15);
const bioEnd = bio.slice(bioIndex + 15);
bioBox.val(bioStart + "\n" + diedYoung + "\n" + bioEnd);
message += "<br>Died Young sticker added to Biography";
}
}
if (enhanced) {
enhancedEditorButton.trigger("click");
}
}
// Show message
if (message != "") {
showCopyMessage(message, true);
}
}
}

function initUnnamedInfant() {
$("#addNewPersonButton,#dismissMatchesButton,#enterBasicDataButton,#wpSaveDraft,#wpSave").on(
"mouseenter",
function () {
doUnnamedInfant();
}
);
}
78 changes: 78 additions & 0 deletions src/features/unnamed_infant/unnamed_infant_options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { options } from "yargs";
import { registerFeature, OptionType } from "../../core/options/options_registry";
import { isProfileEdit, isProfileAddRelative, isAddUnrelatedPerson } from "../../core/pageType";

registerFeature({
name: "Unnamed Infant",
id: "unnamedInfant",
description: "Standardizes the naming of unnamed infants and adds a Died Young sticker to the profile.",
category: "Editing",
creators: [{ name: "Ian Beacall", wikitreeid: "Beacall-6" }],
contributors: [],
defaultValue: true,
pages: [isProfileEdit, isProfileAddRelative, isAddUnrelatedPerson],
options: [
{
id: "diedYoung",
type: OptionType.CHECKBOX,
label: "Add Died Young sticker for people who died aged 16 or younger",
defaultValue: false,
},
{
id: "diedYoungImage",
type: OptionType.SELECT,
label: "Died Young sticker image",
values: [
{
value: "Default",
text: "Default",
},
{
value: "Ribbon",
text: "Ribbon",
},
{
value: "Cradle",
text: "Cradle",
},
{
value: "Swing",
text: "Swing",
},
{
value: "Candle",
text: "Candle",
},
{
value: "Babyfeet",
text: "Babyfeet",
},
{
value: "Butterfly1",
text: "Butterfly1",
},
{
value: "Butterfly2",
text: "Butterfly2",
},
{
value: "Marigold",
text: "Marigold",
},
{
value: "Bluebirds",
text: "Bluebirds",
},
{
value: "Feethands",
text: "Feethands",
},
{
value: "Lotusbutterfly",
text: "Lotusbutterfly",
},
],
defaultValue: "Default",
},
],
});

0 comments on commit d98d8bc

Please sign in to comment.