Adding mirror feature, resolves #31
This commit is contained in:
parent
94b04337be
commit
37dcd37e04
|
@ -41,6 +41,7 @@ function replaceAll() {
|
|||
replaceExceptions(options);
|
||||
replaceCuts();
|
||||
replaceCapitals();
|
||||
replaceMirror();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -233,12 +234,18 @@ function replaceCuts() {
|
|||
walk(document.body, searchTerm, null, cutMethod);
|
||||
}
|
||||
|
||||
/* Replaces cut statements with cuts */
|
||||
/* Replaces capital statements statements with requested casing */
|
||||
function replaceCapitals() {
|
||||
const searchTerm = /(cap|Cap|CAP)\/([^\/]+)\//i;
|
||||
walk(document.body, searchTerm, null, capitalMethod);
|
||||
}
|
||||
|
||||
/* Replaces mirror statements with reversed phrases */
|
||||
function replaceMirror() {
|
||||
const searchTerm = /mrr\/([^\/]+)\//i;
|
||||
walk(document.body, searchTerm, null, mirrorMethod);
|
||||
}
|
||||
|
||||
/* Turns a term into regexp format and uses that to replace it */
|
||||
function escapeAndReplace(searchTerm, replaceValue, caseSensitive) {
|
||||
let searchTermEscaped = searchTerm.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
||||
|
@ -401,6 +408,18 @@ function capitalMethod(node, searchTerm, unused) {
|
|||
capitalMethod(node, searchTerm, unused);
|
||||
}
|
||||
|
||||
/* Allows for custom words to be mirrored */
|
||||
function mirrorMethod(node, searchTerm, unused) {
|
||||
const match = node.nodeValue.match(searchTerm);
|
||||
if (match == null) { return; }
|
||||
const target = match[1];
|
||||
|
||||
let replaceValue = target.split('').reverse().join('');
|
||||
|
||||
node.nodeValue = node.nodeValue.replace(searchTerm, replaceValue);
|
||||
mirrorMethod(node, searchTerm, unused);
|
||||
}
|
||||
|
||||
/* Returns the input word, capitalized */
|
||||
function capitalize(word) {
|
||||
return word.charAt(0).toUpperCase() + word.slice(1);
|
||||
|
|
Loading…
Reference in New Issue