Added cut feature, fixes #26
This commit is contained in:
parent
509001f004
commit
abbfef5093
|
@ -33,6 +33,8 @@ function replaceAll() {
|
||||||
if (isAlsoSet) {
|
if (isAlsoSet) {
|
||||||
replaceAlso(options);
|
replaceAlso(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
replaceCuts();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,6 +231,12 @@ function replaceAlso(options) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Replaces cut statements with cuts */
|
||||||
|
function replaceCuts() {
|
||||||
|
const searchTerm = /[Cc]ut\/([^\/]+)\/(-?[\d]+)\//;
|
||||||
|
walk(document.body, searchTerm, null, cutMethod);
|
||||||
|
}
|
||||||
|
|
||||||
/* Turns a term into regexp format and uses that to replace it */
|
/* Turns a term into regexp format and uses that to replace it */
|
||||||
function escapeAndReplace(searchTerm, replaceValue, caseSensitive) {
|
function escapeAndReplace(searchTerm, replaceValue, caseSensitive) {
|
||||||
let searchTermEscaped = searchTerm.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
let searchTermEscaped = searchTerm.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
||||||
|
@ -393,6 +401,30 @@ function pluralPrnVerbMethod(node, searchTerm, options) {
|
||||||
pluralPrnVerbMethod(node, searchTerm, options);
|
pluralPrnVerbMethod(node, searchTerm, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allows for custom words to be cut off */
|
||||||
|
function cutMethod(node, searchTerm, unused) {
|
||||||
|
let match = node.nodeValue.match(searchTerm);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
/* 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