2025-02-22 18:37:26 -05:00
|
|
|
|
var browser = require("webextension-polyfill");
|
2025-02-22 03:02:18 -05:00
|
|
|
|
const verbsHelper = require("english-verbs-helper");
|
|
|
|
|
|
const verbsIrregular = require("english-verbs-irregular/dist/verbs.json");
|
|
|
|
|
|
const verbsGerunds = require("english-verbs-gerunds/dist/gerunds.json");
|
2025-01-26 23:42:29 -05:00
|
|
|
|
const verbsData = verbsHelper.mergeVerbsData(verbsIrregular, verbsGerunds);
|
2020-09-26 12:03:23 -04:00
|
|
|
|
|
2025-01-27 00:17:52 -05:00
|
|
|
|
/* Replaces verbs, point-of-view, name, pronouns, and "also" terms */
|
2024-12-23 18:34:49 -05:00
|
|
|
|
function replaceAll() {
|
2025-02-22 18:37:26 -05:00
|
|
|
|
let options = browser.storage.local.get();
|
|
|
|
|
|
options.then((options) => {
|
2025-01-26 18:26:57 -05:00
|
|
|
|
const hostname = window.location.hostname;
|
|
|
|
|
|
const isEnabled = !(options.domains === undefined) && options.domains.includes(hostname);
|
|
|
|
|
|
if (!isEnabled) { return; }
|
2024-12-23 05:58:48 -05:00
|
|
|
|
|
2025-01-26 18:26:57 -05:00
|
|
|
|
const isNameSet = !(options.name === undefined || options.name == "");
|
|
|
|
|
|
const isPronounsSet = !(options.preset === undefined || options.preset == "");
|
|
|
|
|
|
const isPovSet = !(options.pov === undefined || options.pov == "");
|
|
|
|
|
|
const isPovLegal = isPovSet && (options.pov != "third" || (isNameSet && isPronounsSet));
|
2025-02-22 00:20:27 -05:00
|
|
|
|
const isAllSet = isNameSet && isPronounsSet && isPovLegal;
|
2025-01-24 17:36:22 -05:00
|
|
|
|
|
2025-01-26 18:26:57 -05:00
|
|
|
|
if (isPovLegal) {
|
|
|
|
|
|
replaceVerbs(options);
|
|
|
|
|
|
replacePov(options);
|
|
|
|
|
|
replacePlv(options);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (isNameSet) {
|
|
|
|
|
|
replaceName(options);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (isPronounsSet) {
|
|
|
|
|
|
replacePronouns(options);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-22 05:11:03 -05:00
|
|
|
|
const isAlsoSet = !(options.also === undefined);
|
2025-01-26 18:26:57 -05:00
|
|
|
|
if (isAlsoSet) {
|
|
|
|
|
|
replaceAlso(options);
|
|
|
|
|
|
}
|
2025-02-21 23:56:45 -05:00
|
|
|
|
|
2025-02-22 00:20:27 -05:00
|
|
|
|
if (isAllSet) {
|
|
|
|
|
|
replaceExceptions(options);
|
|
|
|
|
|
replaceCuts();
|
|
|
|
|
|
}
|
2025-01-26 18:26:57 -05:00
|
|
|
|
});
|
2024-12-23 05:58:48 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-01-27 00:17:52 -05:00
|
|
|
|
/* Replaces all instances of "Y/n" with the user's name */
|
2024-12-23 05:58:48 -05:00
|
|
|
|
function replaceName(options) {
|
2025-02-21 23:03:29 -05:00
|
|
|
|
const searchTerm = /\by\/n\b|\(y\/n\)|\[y\/n\]/ig;
|
|
|
|
|
|
walk(document.body, searchTerm, options["name"], directMethod);
|
2024-12-23 18:34:49 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-01-27 00:17:52 -05:00
|
|
|
|
/* Replaces all verb keys */
|
2024-12-23 18:34:49 -05:00
|
|
|
|
function replaceVerbs(options) {
|
2025-02-22 03:02:18 -05:00
|
|
|
|
const searchTerm = /(v)r([nb])\/([\w\s]+)\/(?:((?:(?:simple|progressive|perfect|perfect[ _]progressive|participle(?![ _]future))[ _])*(?:past|present|future))\/)*/i;
|
|
|
|
|
|
walk(document.body, searchTerm, options, verbMethod);
|
2024-12-23 05:58:48 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-01-27 00:17:52 -05:00
|
|
|
|
/* Replaces all pronoun keys */
|
2025-01-26 18:26:57 -05:00
|
|
|
|
/* This could be made faster if I give premade regexp expressions for each, but I don't want to do that! */
|
2024-12-23 05:58:48 -05:00
|
|
|
|
function replacePronouns(options) {
|
|
|
|
|
|
let pronouns = getPronouns(options.preset, options.other);
|
2025-02-22 05:11:03 -05:00
|
|
|
|
walk(document.body, /([Pp])rn\/s/, pronouns["subjective"], pronounMethod);
|
|
|
|
|
|
walk(document.body, /([Pp])rn\/o/, pronouns["objective"], pronounMethod);
|
|
|
|
|
|
walk(document.body, /([Pp])rn\/p/, pronouns["possessive"], pronounMethod);
|
|
|
|
|
|
walk(document.body, /([Pp])rn\/a/, pronouns["adjective"], pronounMethod);
|
|
|
|
|
|
walk(document.body, /([Pp])rn\/r/, pronouns["reflexive"], pronounMethod);
|
|
|
|
|
|
walk(document.body, /([Pp])rn\/H/, pronouns["honorific-abbr"], pronounMethod);
|
|
|
|
|
|
walk(document.body, /([Pp])rn\/h/, pronouns["honorific"], pronounMethod);
|
|
|
|
|
|
walk(document.body, /([Pp])rn\/N/, pronouns["adult"], pronounMethod);
|
|
|
|
|
|
walk(document.body, /([Pp])rn\/n/, pronouns["youth"], pronounMethod);
|
|
|
|
|
|
walk(document.body, /([Pp])rn\/F/, pronouns["parent"], pronounMethod);
|
|
|
|
|
|
walk(document.body, /([Pp])rn\/f/, pronouns["child"], pronounMethod);
|
|
|
|
|
|
walk(document.body, /([Pp])rn\/k/, pronouns["sibling"], pronounMethod);
|
|
|
|
|
|
walk(document.body, /([Pp])rn\/m/, pronouns["married"], pronounMethod);
|
|
|
|
|
|
walk(document.body, /([Pp])rn\/d/, pronouns["dating"], pronounMethod);
|
2024-12-23 05:58:48 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-01-27 00:17:52 -05:00
|
|
|
|
/* Gets pronouns based on the provided key (or user input) */
|
2024-12-23 05:58:48 -05:00
|
|
|
|
function getPronouns(key, other) {
|
|
|
|
|
|
switch (key) {
|
|
|
|
|
|
case "she":
|
|
|
|
|
|
return {
|
|
|
|
|
|
"subjective": "she",
|
|
|
|
|
|
"objective": "her",
|
|
|
|
|
|
"possessive": "her",
|
|
|
|
|
|
"adjective": "hers",
|
|
|
|
|
|
"reflexive": "herself",
|
|
|
|
|
|
"honorific-abbr": "Ms.",
|
|
|
|
|
|
"honorific": "miss",
|
2025-02-21 19:20:28 -05:00
|
|
|
|
"adult": "woman",
|
|
|
|
|
|
"youth": "girl",
|
|
|
|
|
|
"parent": "mother",
|
|
|
|
|
|
"child": "daughter",
|
|
|
|
|
|
"sibling": "sister",
|
|
|
|
|
|
"married": "wife",
|
|
|
|
|
|
"dating": "girlfriend",
|
2024-12-23 05:58:48 -05:00
|
|
|
|
"plurality": "singular"
|
|
|
|
|
|
};
|
|
|
|
|
|
case "he":
|
|
|
|
|
|
return {
|
|
|
|
|
|
"subjective": "he",
|
|
|
|
|
|
"objective": "him",
|
|
|
|
|
|
"possessive": "his",
|
|
|
|
|
|
"adjective": "his",
|
|
|
|
|
|
"reflexive": "himself",
|
|
|
|
|
|
"honorific-abbr": "Mr.",
|
|
|
|
|
|
"honorific": "mister",
|
2025-02-21 19:20:28 -05:00
|
|
|
|
"adult": "man",
|
|
|
|
|
|
"youth": "boy",
|
|
|
|
|
|
"parent": "father",
|
|
|
|
|
|
"child": "son",
|
|
|
|
|
|
"sibling": "brother",
|
|
|
|
|
|
"married": "husband",
|
|
|
|
|
|
"dating": "boyfriend",
|
2024-12-23 05:58:48 -05:00
|
|
|
|
"plurality": "singular"
|
|
|
|
|
|
};
|
|
|
|
|
|
case "they":
|
|
|
|
|
|
return {
|
|
|
|
|
|
"subjective": "they",
|
|
|
|
|
|
"objective": "them",
|
|
|
|
|
|
"possessive": "their",
|
|
|
|
|
|
"adjective": "theirs",
|
|
|
|
|
|
"reflexive": "themself",
|
|
|
|
|
|
"honorific-abbr": "Mx.",
|
|
|
|
|
|
"honorific": "mix",
|
2025-02-21 19:20:28 -05:00
|
|
|
|
"adult": "person",
|
|
|
|
|
|
"youth": "kid",
|
|
|
|
|
|
"parent": "parent",
|
|
|
|
|
|
"child": "child",
|
|
|
|
|
|
"sibling": "sibling",
|
|
|
|
|
|
"married": "spouse",
|
|
|
|
|
|
"dating": "partner",
|
2024-12-23 05:58:48 -05:00
|
|
|
|
"plurality": "plural"
|
|
|
|
|
|
};
|
|
|
|
|
|
case "first":
|
|
|
|
|
|
return {
|
|
|
|
|
|
"subjective": "I",
|
|
|
|
|
|
"objective": "me",
|
|
|
|
|
|
"possessive": "my",
|
|
|
|
|
|
"adjective": "mine",
|
|
|
|
|
|
"reflexive": "myself"
|
|
|
|
|
|
};
|
|
|
|
|
|
case "second":
|
|
|
|
|
|
return {
|
|
|
|
|
|
"subjective": "you",
|
|
|
|
|
|
"objective": "you",
|
|
|
|
|
|
"possessive": "your",
|
|
|
|
|
|
"adjective": "yours",
|
|
|
|
|
|
"reflexive": "yourself"
|
|
|
|
|
|
};
|
|
|
|
|
|
case "first-plural":
|
|
|
|
|
|
return {
|
|
|
|
|
|
"subjective": "we",
|
|
|
|
|
|
"objective": "us",
|
|
|
|
|
|
"possessive": "our",
|
|
|
|
|
|
"adjective": "ours",
|
|
|
|
|
|
"reflexive": "ourselves"
|
|
|
|
|
|
};
|
|
|
|
|
|
case "second-plural":
|
|
|
|
|
|
return {
|
|
|
|
|
|
"subjective": "you",
|
|
|
|
|
|
"objective": "you",
|
|
|
|
|
|
"possessive": "your",
|
|
|
|
|
|
"adjective": "yours",
|
|
|
|
|
|
"reflexive": "yourselves"
|
|
|
|
|
|
};
|
|
|
|
|
|
case "third-plural":
|
|
|
|
|
|
return {
|
|
|
|
|
|
"subjective": "they",
|
|
|
|
|
|
"objective": "them",
|
|
|
|
|
|
"possessive": "their",
|
|
|
|
|
|
"adjective": "theirs",
|
|
|
|
|
|
"reflexive": "themselves"
|
|
|
|
|
|
};
|
|
|
|
|
|
case "other":
|
2024-12-24 03:11:14 -05:00
|
|
|
|
return other;
|
2024-12-23 05:58:48 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-01-27 00:17:52 -05:00
|
|
|
|
/* Replaces all point-of-view keys */
|
2024-12-23 05:58:48 -05:00
|
|
|
|
function replacePov(options) {
|
|
|
|
|
|
let pronouns;
|
2025-01-26 18:26:57 -05:00
|
|
|
|
if (options.pov == "third") {
|
|
|
|
|
|
pronouns = getPronouns(options.preset, options.other);
|
2025-02-22 05:11:03 -05:00
|
|
|
|
walk(document.body, /([Pp])ov\/S/, options.name, pronounMethod);
|
|
|
|
|
|
walk(document.body, /([Pp])ov\/O/, options.name, pronounMethod);
|
|
|
|
|
|
walk(document.body, /([Pp])ov\/P/, options.name + "’s", pronounMethod);
|
|
|
|
|
|
walk(document.body, /([Pp])ov\/A/, options.name + "’s", pronounMethod);
|
|
|
|
|
|
walk(document.body, /([Pp])ov\/R/, options.name + "’s self", pronounMethod);
|
2025-01-26 18:26:57 -05:00
|
|
|
|
} else {
|
|
|
|
|
|
pronouns = getPronouns(options.pov, null);
|
2025-02-22 05:11:03 -05:00
|
|
|
|
walk(document.body, /([Pp])ov\/S/, pronouns["subjective"], pronounMethod);
|
|
|
|
|
|
walk(document.body, /([Pp])ov\/O/, pronouns["objective"], pronounMethod);
|
|
|
|
|
|
walk(document.body, /([Pp])ov\/P/, pronouns["possessive"], pronounMethod);
|
|
|
|
|
|
walk(document.body, /([Pp])ov\/A/, pronouns["adjective"], pronounMethod);
|
|
|
|
|
|
walk(document.body, /([Pp])ov\/R/, pronouns["reflexive"], pronounMethod);
|
2024-12-23 05:58:48 -05:00
|
|
|
|
}
|
2025-02-22 05:11:03 -05:00
|
|
|
|
walk(document.body, /([Pp])ov\/s/, pronouns["subjective"], pronounMethod);
|
|
|
|
|
|
walk(document.body, /([Pp])ov\/o/, pronouns["objective"], pronounMethod);
|
|
|
|
|
|
walk(document.body, /([Pp])ov\/p/, pronouns["possessive"], pronounMethod);
|
|
|
|
|
|
walk(document.body, /([Pp])ov\/a/, pronouns["adjective"], pronounMethod);
|
|
|
|
|
|
walk(document.body, /([Pp])ov\/r/, pronouns["reflexive"], pronounMethod);
|
2019-10-20 07:41:12 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-01-27 00:17:52 -05:00
|
|
|
|
/* Replaces plural point-of-view keys */
|
2024-12-23 05:58:48 -05:00
|
|
|
|
function replacePlv(options) {
|
|
|
|
|
|
let pronouns = getPronouns(options.pov + "-plural", null);
|
2025-02-22 05:11:03 -05:00
|
|
|
|
walk(document.body, /([Pp])lv\/s/, pronouns["subjective"], pronounMethod);
|
|
|
|
|
|
walk(document.body, /([Pp])lv\/o/, pronouns["objective"], pronounMethod);
|
|
|
|
|
|
walk(document.body, /([Pp])lv\/p/, pronouns["possessive"], pronounMethod);
|
|
|
|
|
|
walk(document.body, /([Pp])lv\/a/, pronouns["adjective"], pronounMethod);
|
|
|
|
|
|
walk(document.body, /([Pp])lv\/r/, pronouns["reflexive"], pronounMethod);
|
2020-09-26 12:03:23 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-01-27 00:17:52 -05:00
|
|
|
|
/* Replaces additional terms specified by the user */
|
2024-12-23 05:58:48 -05:00
|
|
|
|
function replaceAlso(options) {
|
|
|
|
|
|
Object.entries(options.also).forEach(([key, value]) => {
|
|
|
|
|
|
escapeAndReplace(key, value, true);
|
|
|
|
|
|
});
|
2016-07-06 01:12:36 -04:00
|
|
|
|
}
|
2016-06-18 23:04:38 -04:00
|
|
|
|
|
2025-02-22 00:20:27 -05:00
|
|
|
|
/* Replaces exception statements by POV */
|
|
|
|
|
|
function replaceExceptions(options) {
|
2025-02-22 05:11:03 -05:00
|
|
|
|
const searchTerm = /exc\/([^\/]*)\/([^\/]*)\//i;
|
2025-02-22 00:20:27 -05:00
|
|
|
|
walk(document.body, searchTerm, options, exceptionMethod);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-02-21 23:56:45 -05:00
|
|
|
|
/* Replaces cut statements with cuts */
|
|
|
|
|
|
function replaceCuts() {
|
2025-02-22 05:11:03 -05:00
|
|
|
|
const searchTerm = /cut\/([^\/]+)\/(-?[\d]+)\//i;
|
2025-02-21 23:56:45 -05:00
|
|
|
|
walk(document.body, searchTerm, null, cutMethod);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-01-27 00:17:52 -05:00
|
|
|
|
/* Turns a term into regexp format and uses that to replace it */
|
2025-02-21 23:03:29 -05:00
|
|
|
|
function escapeAndReplace(searchTerm, replaceValue, caseSensitive) {
|
|
|
|
|
|
let searchTermEscaped = searchTerm.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
|
|
|
|
|
const flags = caseSensitive ? "g" : "ig"
|
|
|
|
|
|
if (searchTermEscaped[0].match(/[a-z]/i)) {
|
|
|
|
|
|
searchTermEscaped = `\\b${searchTermEscaped}`
|
2024-12-23 05:58:48 -05:00
|
|
|
|
}
|
2025-02-21 23:03:29 -05:00
|
|
|
|
if (searchTermEscaped[searchTermEscaped.length - 1].match((/[a-z]/i))) {
|
|
|
|
|
|
searchTermEscaped = `${searchTermEscaped}\\b`
|
2024-12-23 05:58:48 -05:00
|
|
|
|
}
|
2025-02-21 23:03:29 -05:00
|
|
|
|
const searchTermRegexp = new RegExp(searchTermEscaped, flags)
|
|
|
|
|
|
walk(document.body, searchTermRegexp, replaceValue, directMethod);
|
2024-12-23 18:34:49 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-01-27 00:17:52 -05:00
|
|
|
|
/* Traverses a node and its children to run the provided replacement method */
|
2025-02-21 23:03:29 -05:00
|
|
|
|
function walk(node, searchTerm, replaceValue, replaceMethod) {
|
2024-12-23 18:34:49 -05:00
|
|
|
|
if (node.contentEditable == "true" || node.type == "textarea" || node.type == "input") { return; }
|
2024-12-24 03:11:14 -05:00
|
|
|
|
let child, next;
|
2024-12-23 18:34:49 -05:00
|
|
|
|
switch (node.nodeType) {
|
|
|
|
|
|
case 1: /* ELEMENT_NODE */
|
|
|
|
|
|
case 9: /* DOCUMENT_NODE */
|
|
|
|
|
|
case 11: /* DOCUMENT_FRAGMENT_NODE */
|
|
|
|
|
|
child = node.firstChild;
|
|
|
|
|
|
while (child) {
|
|
|
|
|
|
next = child.nextSibling;
|
2025-02-21 23:03:29 -05:00
|
|
|
|
walk(child, searchTerm, replaceValue, replaceMethod);
|
2024-12-23 18:34:49 -05:00
|
|
|
|
child = next;
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 3: /* TEXT_NODE */
|
2025-02-21 23:03:29 -05:00
|
|
|
|
replaceMethod(node, searchTerm, replaceValue);
|
2024-12-23 05:58:48 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-22 05:11:03 -05:00
|
|
|
|
/* Replaces every instance of the provided terms */
|
2025-02-21 23:03:29 -05:00
|
|
|
|
function directMethod(node, searchTerm, replaceValue) {
|
|
|
|
|
|
node.nodeValue = node.nodeValue.replaceAll(searchTerm, replaceValue);
|
2024-12-23 18:34:49 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-22 05:11:03 -05:00
|
|
|
|
/* Replaces all pronouns */
|
|
|
|
|
|
function pronounMethod(node, searchTerm, pronoun) {
|
|
|
|
|
|
const match = node.nodeValue.match(searchTerm);
|
|
|
|
|
|
if (match == null) { return; }
|
|
|
|
|
|
const isCapital = /P/.test(match[1]);
|
|
|
|
|
|
|
|
|
|
|
|
let replaceValue = pronoun;
|
|
|
|
|
|
if (isCapital) {
|
|
|
|
|
|
replaceValue = capitalize(replaceValue);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
node.nodeValue = node.nodeValue.replace(searchTerm, replaceValue);
|
|
|
|
|
|
pronounMethod(node, searchTerm, pronoun);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-01-27 00:17:52 -05:00
|
|
|
|
/* Replaces all verbs, not used for third-person plural */
|
2025-02-21 23:03:29 -05:00
|
|
|
|
function verbMethod(node, searchTerm, options) {
|
2025-02-22 03:02:18 -05:00
|
|
|
|
const match = node.nodeValue.match(searchTerm);
|
2025-02-21 23:03:29 -05:00
|
|
|
|
if (match == null) { return; }
|
|
|
|
|
|
const isCapital = /V/.test(match[1]);
|
2025-02-22 03:02:18 -05:00
|
|
|
|
const category = match[2];
|
2025-02-21 23:03:29 -05:00
|
|
|
|
const verb = match[3];
|
2025-02-22 03:02:18 -05:00
|
|
|
|
let tense = match[4];
|
2025-02-21 23:03:29 -05:00
|
|
|
|
|
2025-02-22 03:02:18 -05:00
|
|
|
|
if (tense == null) {
|
2025-02-21 23:03:29 -05:00
|
|
|
|
tense = "PAST";
|
|
|
|
|
|
} else {
|
2025-02-22 03:02:18 -05:00
|
|
|
|
tense = tense.toUpperCase().replaceAll(" ", "_");
|
2025-02-21 23:03:29 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-22 03:02:18 -05:00
|
|
|
|
let povIndex;
|
|
|
|
|
|
switch (category) {
|
|
|
|
|
|
case "B": /* B and b vary by POV, capitalized to indicate a named subject */
|
|
|
|
|
|
if (options.pov == "third") {
|
|
|
|
|
|
povIndex = getPovIndex("third-singular", null);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
povIndex = getPovIndex(options.pov, options);
|
|
|
|
|
|
}
|
2025-02-22 20:21:01 -05:00
|
|
|
|
break;
|
2025-02-22 03:02:18 -05:00
|
|
|
|
case "b":
|
|
|
|
|
|
povIndex = getPovIndex(options.pov, options);
|
2025-02-22 20:21:01 -05:00
|
|
|
|
break;
|
2025-02-22 03:02:18 -05:00
|
|
|
|
case "N": /* N and n are always third-person */
|
|
|
|
|
|
povIndex = getPovIndex("third-singular", null);
|
2025-02-22 20:21:01 -05:00
|
|
|
|
break;
|
2025-02-22 03:02:18 -05:00
|
|
|
|
case "n":
|
|
|
|
|
|
povIndex = getPovIndex("third", options);
|
2025-02-21 23:03:29 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-22 03:02:18 -05:00
|
|
|
|
let replaceValue = verbsHelper.getConjugation(verbsData, verb, tense, povIndex);
|
2025-02-21 23:03:29 -05:00
|
|
|
|
|
|
|
|
|
|
if (isCapital) {
|
|
|
|
|
|
replaceValue = capitalize(replaceValue);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-22 03:02:18 -05:00
|
|
|
|
node.nodeValue = node.nodeValue.replace(searchTerm, replaceValue);
|
|
|
|
|
|
verbMethod(node, searchTerm, options);
|
2024-12-23 18:34:49 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-21 23:56:45 -05:00
|
|
|
|
/* Allows for custom words to be cut off */
|
|
|
|
|
|
function cutMethod(node, searchTerm, unused) {
|
2025-02-22 03:02:18 -05:00
|
|
|
|
const match = node.nodeValue.match(searchTerm);
|
2025-02-21 23:56:45 -05:00
|
|
|
|
if (match == null) { return; }
|
|
|
|
|
|
const target = match[1];
|
|
|
|
|
|
const amount = match[2];
|
|
|
|
|
|
|
|
|
|
|
|
if (target.length <= Math.abs(amount)) {
|
|
|
|
|
|
node.nodeValue = node.nodeValue.replace(searchTerm, target);
|
|
|
|
|
|
cutMethod(node, searchTerm, unused);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let replaceValue;
|
|
|
|
|
|
if (amount < 0) {
|
|
|
|
|
|
replaceValue = target.slice(0, amount);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
replaceValue = target.slice(amount);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
node.nodeValue = node.nodeValue.replace(searchTerm, replaceValue);
|
|
|
|
|
|
cutMethod(node, searchTerm, unused);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-22 00:20:27 -05:00
|
|
|
|
/* Allows for custom words to be cut off */
|
|
|
|
|
|
function exceptionMethod(node, searchTerm, options) {
|
2025-02-22 03:02:18 -05:00
|
|
|
|
const match = node.nodeValue.match(searchTerm);
|
2025-02-22 00:20:27 -05:00
|
|
|
|
if (match == null) { return; }
|
|
|
|
|
|
|
|
|
|
|
|
let replaceValue;
|
|
|
|
|
|
if (options.pov == "third") {
|
|
|
|
|
|
replaceValue = match[2];
|
|
|
|
|
|
} else {
|
|
|
|
|
|
replaceValue = match[1];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
node.nodeValue = node.nodeValue.replace(searchTerm, replaceValue);
|
2025-02-22 05:11:03 -05:00
|
|
|
|
exceptionMethod(node, searchTerm, options);
|
2025-02-22 00:20:27 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-01-27 00:17:52 -05:00
|
|
|
|
/* Returns the input word, capitalized */
|
2024-12-23 05:58:48 -05:00
|
|
|
|
function capitalize(word) {
|
|
|
|
|
|
return word.charAt(0).toUpperCase() + word.slice(1);
|
2015-02-21 22:00:28 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-01-27 00:17:52 -05:00
|
|
|
|
/* Determines the index for point-of-view to be used when conjugating verbs */
|
2025-02-22 03:02:18 -05:00
|
|
|
|
function getPovIndex(pov, options) {
|
|
|
|
|
|
switch (pov) {
|
2024-12-23 18:34:49 -05:00
|
|
|
|
case "first":
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
case "second":
|
|
|
|
|
|
return 1;
|
2025-02-22 03:02:18 -05:00
|
|
|
|
case "third-singular":
|
|
|
|
|
|
return 2;
|
2024-12-23 18:34:49 -05:00
|
|
|
|
case "third":
|
2024-12-24 03:11:14 -05:00
|
|
|
|
if (getPronouns(options.preset, options.other).plurality == "singular") {
|
2024-12-23 18:34:49 -05:00
|
|
|
|
return 2;
|
2024-12-24 03:11:14 -05:00
|
|
|
|
} else { /* Plurality is plural, "they go" */
|
2024-12-23 18:34:49 -05:00
|
|
|
|
return 5;
|
|
|
|
|
|
}
|
2025-02-22 03:02:18 -05:00
|
|
|
|
return getThirdIndex(options);
|
2025-02-21 23:03:29 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-12-23 18:34:49 -05:00
|
|
|
|
replaceAll();
|