Adding two-term exceptions, fixes #25
This commit is contained in:
parent
abbfef5093
commit
445f38b4ee
|
@ -14,6 +14,7 @@ function replaceAll() {
|
||||||
const isPronounsSet = !(options.preset === undefined || options.preset == "");
|
const isPronounsSet = !(options.preset === undefined || options.preset == "");
|
||||||
const isPovSet = !(options.pov === undefined || options.pov == "");
|
const isPovSet = !(options.pov === undefined || options.pov == "");
|
||||||
const isPovLegal = isPovSet && (options.pov != "third" || (isNameSet && isPronounsSet));
|
const isPovLegal = isPovSet && (options.pov != "third" || (isNameSet && isPronounsSet));
|
||||||
|
const isAllSet = isNameSet && isPronounsSet && isPovLegal;
|
||||||
|
|
||||||
if (isPovLegal) {
|
if (isPovLegal) {
|
||||||
replaceVerbs(options);
|
replaceVerbs(options);
|
||||||
|
@ -34,7 +35,10 @@ function replaceAll() {
|
||||||
replaceAlso(options);
|
replaceAlso(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
replaceCuts();
|
if (isAllSet) {
|
||||||
|
replaceExceptions(options);
|
||||||
|
replaceCuts();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,6 +235,13 @@ function replaceAlso(options) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Replaces exception statements by POV */
|
||||||
|
function replaceExceptions(options) {
|
||||||
|
const searchTerm = /[Ee]xc\/([^\/]*)\/([^\/]*)\//;
|
||||||
|
walk(document.body, searchTerm, options, exceptionMethod);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Replaces cut statements with cuts */
|
/* Replaces cut statements with cuts */
|
||||||
function replaceCuts() {
|
function replaceCuts() {
|
||||||
const searchTerm = /[Cc]ut\/([^\/]+)\/(-?[\d]+)\//;
|
const searchTerm = /[Cc]ut\/([^\/]+)\/(-?[\d]+)\//;
|
||||||
|
@ -425,6 +436,22 @@ function cutMethod(node, searchTerm, unused) {
|
||||||
cutMethod(node, searchTerm, unused);
|
cutMethod(node, searchTerm, unused);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allows for custom words to be cut off */
|
||||||
|
function exceptionMethod(node, searchTerm, options) {
|
||||||
|
let match = node.nodeValue.match(searchTerm);
|
||||||
|
if (match == null) { return; }
|
||||||
|
|
||||||
|
let replaceValue;
|
||||||
|
if (options.pov == "third") {
|
||||||
|
replaceValue = match[2];
|
||||||
|
} else {
|
||||||
|
replaceValue = match[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
node.nodeValue = node.nodeValue.replace(searchTerm, replaceValue);
|
||||||
|
cutMethod(node, searchTerm, options);
|
||||||
|
}
|
||||||
|
|
||||||
/* Returns the input word, capitalized */
|
/* Returns the input word, capitalized */
|
||||||
function capitalize(word) {
|
function capitalize(word) {
|
||||||
return word.charAt(0).toUpperCase() + word.slice(1);
|
return word.charAt(0).toUpperCase() + word.slice(1);
|
||||||
|
|
Loading…
Reference in New Issue