diff --git a/src/session/DeputyRootSession.ts b/src/session/DeputyRootSession.ts index ebc03d5c..73d28989 100644 --- a/src/session/DeputyRootSession.ts +++ b/src/session/DeputyRootSession.ts @@ -569,7 +569,11 @@ export default class DeputyRootSession { } await casePage.addActiveSection( sectionId ); - heading.insertAdjacentElement( 'afterend', el.render() ); + if ( heading.parentElement.classList.contains( 'mw-heading' ) ) { + heading.parentElement.insertAdjacentElement( 'afterend', el.render() ); + } else { + heading.insertAdjacentElement( 'afterend', el.render() ); + } await el.loadData(); mw.hook( 'deputy.load.cci.session' ).fire(); diff --git a/src/ui/root/DeputyContributionSurveySection.tsx b/src/ui/root/DeputyContributionSurveySection.tsx index c0a6bbfe..eb749826 100644 --- a/src/ui/root/DeputyContributionSurveySection.tsx +++ b/src/ui/root/DeputyContributionSurveySection.tsx @@ -300,7 +300,8 @@ export default class DeputyContributionSurveySection implements DeputyUIElement for ( let i = 0; i < this.originalList.children.length; i++ ) { const li = this.originalList.children.item( i ); if ( li.tagName !== 'LI' ) { - return false; + // Skip this element. + continue; } const anchor: HTMLElement = li.querySelector( 'a:first-of-type' ); // Avoid enlisting if the anchor can't be found (invalid row). @@ -559,7 +560,17 @@ export default class DeputyContributionSurveySection implements DeputyUIElement this._section = null; await this.getSection( Object.assign( wikitext, { revid } ) ); await this.prepare(); - heading.insertAdjacentElement( 'afterend', this.render() ); + if ( heading.parentElement.classList.contains( 'mw-heading' ) ) { + // Intentional recursive call + heading.parentElement.insertAdjacentElement( + 'afterend', this.render() + ); + } else { + // Intentional recursive call + heading.insertAdjacentElement( + 'afterend', this.render() + ); + } // Run this asynchronously. setTimeout( this.loadData.bind( this ), 0 ); } diff --git a/src/wiki/DeputyCasePage.ts b/src/wiki/DeputyCasePage.ts index 623449de..adcf8624 100644 --- a/src/wiki/DeputyCasePage.ts +++ b/src/wiki/DeputyCasePage.ts @@ -139,8 +139,11 @@ export default class DeputyCasePage extends DeputyCase { isContributionSurveyHeading( el: HTMLElement ): el is ContributionSurveyHeading { // All headings (h1, h2, h3, h4, h5, h6) // TODO: l10n - const headlineElement = this.parsoid ? el : el.querySelector( '.mw-headline' ); - return /^H\d$/.test( el.tagName ) && + const headlineElement = this.parsoid ? + el : + el.querySelector( '.mw-headline' ); + // Handle DiscussionTools case (.mw-heading) + return ( el.classList.contains( 'mw-heading' ) || /^H\d$/.test( el.tagName ) ) && headlineElement != null && /(Page|Article|Local file|File)s? \d+ (to|through) \d+$/.test( headlineElement.innerText ); } @@ -223,6 +226,10 @@ export default class DeputyCasePage extends DeputyCase { sectionHeading = sectionHeading.parentElement; } } + // When DiscussionTools is being used, the header is wrapped in a div. + if ( sectionHeading.parentElement.classList.contains( 'mw-heading' ) ) { + sectionHeading = sectionHeading.parentElement; + } const sectionMembers: HTMLElement[] = [];