Fixing multiple verbs not being replaced, third person conjugating as plural when using name
This commit is contained in:
parent
2e911575dc
commit
4bf2f7ec01
|
@ -18,12 +18,12 @@ function replaceAllInStorage(options) {
|
|||
//const hostname = window.location.hostname
|
||||
//const is_paused = options[PAUSED_KEY] && options[PAUSED_KEY].indexOf(hostname) !== -1
|
||||
if (true) { // change paused later to only care about hostname
|
||||
replaceVerbs(options);
|
||||
replaceName(options);
|
||||
replacePronouns(options);
|
||||
replacePov(options);
|
||||
replacePlv(options);
|
||||
replaceAlso(options);
|
||||
replaceVerbs(options);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,11 @@ function replaceName(options) {
|
|||
}
|
||||
|
||||
function replaceVerbs(options) {
|
||||
if (getPronouns(options.preset, options.other).plurality == "plural") {
|
||||
const regexp = /([Pp])(?:rn|ov)\/S [Vv]rb\/([\w\s]+)\/([\w\s]+)\/|[Vv]rb\/([\w\s]+)\/([\w\s]+)\/ ([Pp])(?:rn|ov)\/S/;
|
||||
walk(document.body, regexp, options, pluralThirdVerbMethod);
|
||||
}
|
||||
|
||||
const regexp = /vrb\/([\w\s]+)\/([\w\s]+)\//;
|
||||
walk(document.body, regexp, options, verbMethod);
|
||||
}
|
||||
|
@ -134,7 +139,7 @@ function getPronouns(key, other) {
|
|||
"reflexive": "themselves"
|
||||
};
|
||||
case "other":
|
||||
return options.other;
|
||||
return other;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -165,7 +170,6 @@ function replacePov(options) {
|
|||
replacePronounSet("Pov/A", "pov/A", pronouns["adjective"]);
|
||||
replacePronounSet("Pov/R", "pov/R", pronouns["reflexive"]);
|
||||
}
|
||||
|
||||
replacePronounSet("Pov/s", "pov/s", pronouns["subjective"]);
|
||||
replacePronounSet("Pov/o", "pov/o", pronouns["objective"]);
|
||||
replacePronounSet("Pov/p", "pov/p", pronouns["possessive"]);
|
||||
|
@ -204,7 +208,7 @@ function escapeAndReplace(input_word, replace_value, case_sensitive) {
|
|||
|
||||
function walk(node, input_word, replace_value, replaceMethod) {
|
||||
if (node.contentEditable == "true" || node.type == "textarea" || node.type == "input") { return; }
|
||||
var child, next;
|
||||
let child, next;
|
||||
switch (node.nodeType) {
|
||||
case 1: /* ELEMENT_NODE */
|
||||
case 9: /* DOCUMENT_NODE */
|
||||
|
@ -227,12 +231,38 @@ function directMethod(node, input_word, replace_value) {
|
|||
|
||||
// TODO do something about options being not input_word
|
||||
function verbMethod(node, regexp, options) {
|
||||
var match = node.nodeValue.match(regexp);
|
||||
let match = node.nodeValue.match(regexp);
|
||||
if (match == null) { return; }
|
||||
var verb = match[1];
|
||||
var tense = match[2];
|
||||
const verb = match[1];
|
||||
const tense = match[2];
|
||||
const replace_value = verbsHelper.getConjugation(null, verb, tense, getPovIndex(options));
|
||||
node.nodeValue = node.nodeValue.replace(regexp, replace_value);
|
||||
verbMethod(node, regexp, options);
|
||||
}
|
||||
|
||||
function pluralThirdVerbMethod(node, regexp, options) {
|
||||
let match = node.nodeValue.match(regexp);
|
||||
if (match == null) { return };
|
||||
const before = match[1];
|
||||
const after = match[4];
|
||||
const wasBefore = !(before === undefined);
|
||||
let verb, tense;
|
||||
if (wasBefore) {
|
||||
verb = match[2];
|
||||
tense = match[3];
|
||||
} else {
|
||||
verb = match[5];
|
||||
tense = match[6];
|
||||
}
|
||||
const replace_verb = verbsHelper.getConjugation(null, verb, tense, 2);
|
||||
let replace_value;
|
||||
if (wasBefore) {
|
||||
replace_value = options["name"] + " " + replace_verb;
|
||||
} else {
|
||||
replace_value = replace_verb + " " + options["name"];
|
||||
}
|
||||
node.nodeValue = node.nodeValue.replace(regexp, replace_value);
|
||||
pluralThirdVerbMethod(node, regexp, options);
|
||||
}
|
||||
|
||||
function capitalize(word) {
|
||||
|
@ -247,13 +277,9 @@ function getPovIndex(options) {
|
|||
case "second":
|
||||
return 1;
|
||||
case "third":
|
||||
if (options.preset == "he" || options.preset == "she") {
|
||||
if (getPronouns(options.preset, options.other).plurality == "singular") {
|
||||
return 2;
|
||||
} else if (options.preset == "they") {
|
||||
return 5;
|
||||
} else if (options.other.plurality == "singular") {
|
||||
return 2;
|
||||
} else {
|
||||
} else { /* Plurality is plural, "they go" */
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue