message: Avoid duplicate `open-all-notifications` buttons
diff: @@ -10,7 +10,7 @@ import openTabs from '../helpers/open-tabs';
  import {appendBefore} from '../helpers/dom-utils';
  import showToast from '../github-helpers/toast';
  import pluralize from '../helpers/pluralize';
  -import attachElement from '../helpers/attach-element';
  +import observe from '../helpers/selector-observer';
  // Selector works on:
  // https://github.com/notifications (Grouped by date)
  @@ -68,54 +68,32 @@ async function openSelectedNotifications(): Promise<void> {
  }
  }
  -function addOpenSelectedButton(signal: AbortSignal): void {
  - delegate(document, openSelected.selector, 'click', openSelectedNotifications, {signal});
  +function removeOpenUnreadButtons(container: ParentNode = document): void {
  + for (const button of select.all(openUnread.selector, container)) {
  + button.remove();
  + }
  +}
  - attachElement(notificationHeaderSelector + ' .js-notifications-mark-selected-actions', {
  - forEach(anchor) {
  +function addSelectedButton(selectedActionsGroup: HTMLElement): void {
  const button = (
  <button className={'btn btn-sm ' + openSelected.class} type="button">
  <LinkExternalIcon className="mr-1"/>Open
  </button>
  );
  appendBefore(
  - anchor,
  + selectedActionsGroup,
  'details',
  button,
  );
  -
  - return button;
  - },
  - });
  }
  -function removeOpenUnreadButtons(container: ParentNode = document): void {
  - for (const button of select.all(openUnread.selector, container)) {
  - button.remove();
  - }
  -}
  -
  -function addOpenUnreadButtons(signal: AbortSignal): void {
  - if (getUnreadNotifications().length === 0) {
  - return;
  - }
  -
  - delegate(document, openUnread.selector, 'click', openUnreadNotifications, {signal});
  -
  - attachElement(notificationHeaderSelector, {
  - append: () => (
  - <button className={'btn btn-sm ml-auto d-none ' + openUnread.class} type="button">
  - <LinkExternalIcon className="mr-1"/>Open all unread
  - </button>
  - ),
  - });
  -
  - for (const repository of select.all('.js-notifications-group')) {
  +function addToRepoGroup(markReadButton: HTMLElement): void {
  + const repository = markReadButton.closest('.js-notifications-group')!;
  if (getUnreadNotifications(repository).length === 0) {
  - continue;
  + return;
  }
  - select('.js-grouped-notifications-mark-all-read-button', repository)!.before(
  + markReadButton.before(
  <button
  type="button"
  className={'btn btn-sm mr-2 tooltipped tooltipped-w ' + openUnread.class}
  @@ -125,11 +103,26 @@ function addOpenUnreadButtons(signal: AbortSignal): void {
  </button>,
  );
  }
  +
  +function addToMainHeader(notificationHeader: HTMLElement): void {
  + if (getUnreadNotifications().length === 0) {
  + return;
  + }
  +
  + notificationHeader.append(
  + <button className={'btn btn-sm ml-auto d-none ' + openUnread.class} type="button">
  + <LinkExternalIcon className="mr-1"/>Open all unread
  + </button>,
  + );
  }
  function init(signal: AbortSignal): void {
  - addOpenSelectedButton(signal);
  - addOpenUnreadButtons(signal);
  + delegate(document, openSelected.selector, 'click', openSelectedNotifications, {signal});
  + delegate(document, openUnread.selector, 'click', openUnreadNotifications, {signal});
  +
  + observe(notificationHeaderSelector + ' .js-notifications-mark-selected-actions', addSelectedButton, {signal});
  + observe(notificationHeaderSelector, addToMainHeader, {signal});
  + observe('.js-grouped-notifications-mark-all-read-button', addToRepoGroup, {signal});
  }
  void features.add(import.meta.url, {
  