diff --git a/source/features/quick-comment-hiding.tsx b/source/features/quick-comment-hiding.tsx index 1e191610e2e8..8f52c84517cc 100644 --- a/source/features/quick-comment-hiding.tsx +++ b/source/features/quick-comment-hiding.tsx @@ -5,6 +5,11 @@ import * as pageDetect from 'github-url-detection'; import features from '../feature-manager'; +const formSelector = [ + 'form[action$="/minimize-comment"]', + 'form[action$="/minimize"]', // Review thread comments +]; + function generateSubmenu(hideButton: Element): void { if (hideButton.closest('.rgh-quick-comment-hiding-details')) { // Already generated @@ -15,13 +20,18 @@ function generateSubmenu(hideButton: Element): void { detailsElement.classList.add('rgh-quick-comment-hiding-details'); const comment = hideButton.closest('.unminimized-comment')!; - const hideCommentForm = select('.js-comment-minimize', comment)!; + const hideCommentForm: HTMLFormElement = select(formSelector, comment)!; + + // Generate dropdown + const newForm = hideCommentForm.cloneNode(); + const fields = [...hideCommentForm.elements].map(field => field.cloneNode()); + newForm.append(); // Add existing fields (comment ID, token) - hideCommentForm.classList.remove('d-flex'); + // Imitate existing menu, reset classes + newForm.className = ['dropdown-menu', 'dropdown-menu-sw', 'color-fg-default', 'show-more-popover', 'anim-scale-in'].join(' '); - // Generate dropdown items - for (const reason of select.all('[name="classifier"] option:not([value=""])', comment)) { - hideCommentForm.append( + for (const reason of select.all('option:not([value=""])', hideCommentForm.elements.classifier)) { + newForm.append(