Skip to content

Commit

Permalink
Don't allow diceless matches in the characters text
Browse files Browse the repository at this point in the history
Ref #23
  • Loading branch information
haste committed Jan 22, 2025
1 parent df57163 commit a84465e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
8 changes: 2 additions & 6 deletions src/characters.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,11 @@ export const characterAppWatcher = (showOptionsButton = false) => {
for (const addedNode of mutation.addedNodes) {
for (const node of getTextNodes(addedNode)) {
const parentNode = node.parentElement;
if (
// Don't embed in item names
parentNode.className.includes("itemName") ||
isParentsProcessed(parentNode)
) {
if (isParentsProcessed(parentNode)) {
continue;
}

embedInText(node);
embedInText(node, null, false);
}
}
}
Expand Down
17 changes: 9 additions & 8 deletions src/utils/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ export const diceValueFromMatch = ({
return `${numDice}d${dice}${sign}${modifier}`;
};

export const isValidDice = (match) => {
export const isValidDice = (match, allowDicelessModifier = true) => {
const soloModifierType = match.groups.soloModifierType;
if (
soloModifierType &&
!(
validSoloModifierType.includes(soloModifierType) ||
getCharacterSkills().includes(soloModifierType)
)
!(allowDicelessModifier || match.groups.dice) ||
(soloModifierType &&
!(
validSoloModifierType.includes(soloModifierType) ||
getCharacterSkills().includes(soloModifierType)
))
) {
return false;
}
Expand Down Expand Up @@ -152,13 +153,13 @@ const processPreviousElement = (node, match) => {
return [null, match];
};

export const embedInText = (node, labelOrCallback) => {
export const embedInText = (node, labelOrCallback, allowDicelessModifier) => {
let offset = 0;
let fragment;
let prependNode;
const textContent = node.textContent;
for (let match of textContent.matchAll(diceRegex)) {
if (!isValidDice(match)) {
if (!isValidDice(match, allowDicelessModifier)) {
continue;
}

Expand Down

0 comments on commit a84465e

Please sign in to comment.