Skip to content

Commit

Permalink
Fix setting label from heading when processing Actions
Browse files Browse the repository at this point in the history
Apparently they don't use similar CSS styles anymore.
  • Loading branch information
haste committed Jan 26, 2025
1 parent b80e6ff commit 482dfc7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Bug fixes

* Fix header of actions not being set as dice labels.

## 0.18.0 (2025-01-26)

### Bug fixes
Expand Down
3 changes: 2 additions & 1 deletion src/utils/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ export const embedInText = (node, labelOrCallback, matchDicelessModifier) => {
if (!label) {
// Only fetch #text nodes directly under the parent. In most (all?) just
// using node.firstChild.textContent would probably be enough.
const heading = getSiblingWithClass(node.parentElement, "_heading__", 7);
// Actions use __heading while Features & Traits use heading
const heading = getSiblingWithClass(node.parentElement, "_heading", 7);
if (heading) {
label = Array.prototype.filter
.call(heading.childNodes, (node) => node.nodeType === 3)
Expand Down
26 changes: 24 additions & 2 deletions src/utils/web.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,30 @@ describe("diceRegex", () => {
});

describe("getTextNodes + embedInText", () => {
// grom D&D Beyond Character v1.69.44
describe("Feature & Traits", () => {
// from D&D Beyond Character v1.69.44
describe("Actions", () => {
test("dice value outside tooltip and modifier inside", () => {
// Second Wind PHB
document.body.innerHTML = `<div class="ct-feature-snippet"><div class="ct-feature-snippet__heading ct-feature-snippet__heading--dark-mode">Second Wind </div><div class="ct-feature-snippet__content"><div class="ddbc-snippet ddbc-snippet--parsed ddbc-snippet--dark-mode"><div class="jsx-parser ddbc-snippet__content"><p>Once per short rest, you can use a bonus action to regain 1d10 + <span class="ddbc-tooltip ddbc-tooltip--dark-mode" data-tippy="" data-original-title="classlevel"><span class="ddbc-snippet__tag">3</span></span> HP.</p></div></div></div><div class="ct-feature-snippet__limited-use ct-feature-snippet__limited-use--dark-mode"><div class="ct-feature-snippet__limited-use-usages"><div class="ct-slot-manager ct-slot-manager--size-small"><div role="checkbox" aria-checked="false" aria-label="use" class="ct-slot-manager__slot ct-slot-manager__slot--interactive"></div></div></div><div class="ct-feature-snippet__limited-use-sep">/</div><div class="ct-feature-snippet__limited-use-reset">Short Rest</div></div></div>`;

const textNodes = getTextNodes(document.body);
expect(textNodes.length).toEqual(1);

for (const node of textNodes) {
embedInText(node);
}

const button = document.querySelector("button");
expect(button.className).toEqual(
"integrated-dice__container tales-beyond-extension",
);
expect(button.dataset.tsLabel).toEqual("Second Wind");
expect(button.dataset.tsDice).toEqual("1d10+3");
});
});

// from D&D Beyond Character v1.69.44
describe("Features & Traits", () => {
test("dice and modifier value inside tooltip", () => {
// Sneak Attack PHB
document.body.innerHTML = `<div class="styles_snippet__CzYh+ ct-feature-snippet--class"><div class="styles_heading__yD0Cm styles_headingDarkMode__YO4Ql">Sneak Attack<span><span class="styles_metaItem__wEnyV styles_metaItemDarkMode__oscOW"><span>4d6</span></span><span class="styles_metaItem__wEnyV styles_metaItemDarkMode__oscOW"><p class="styles_reference__4pmEk" data-tooltip-id="0aba286b-18fb-4037-97bd-0412f7b78480" data-tooltip-delay-show="1500"><span class="styles_name__mZMFY">PHB</span><span>, pg. 96</span></p><div class="Tooltip_container__20y9m"></div></span></span></div><div class="styles_content__VHVQW"><div class="ddbc-snippet ddbc-snippet--parsed ddbc-snippet--dark-mode"><div class="jsx-parser ddbc-snippet__content"><p>Once per turn, you can deal an extra <span class="ddbc-tooltip ddbc-tooltip--dark-mode" data-tippy="" data-original-title="scalevalue"><span class="ddbc-snippet__tag">4d6</span></span> damage to one creature you hit with an attack with a finesse or ranged weapon if you have advantage on the attack roll. You don’t need advantage on the attack roll if another enemy of the target is within 5 ft. of it, that enemy isn’t incapacitated, and you don’t have disadvantage on the attack roll.</p></div></div></div><div class="styles_extra__BgeMp" style="border-color: rgb(213, 145, 57);"><div class="ct-feature-snippet__actions"><div class="ct-feature-snippet__action"><div class="ct-feature-snippet__action-summary ct-feature-snippet__action-summary--dark-mode">Sneak Attack: (No Action)</div></div></div></div></div>`;
Expand Down

0 comments on commit 482dfc7

Please sign in to comment.