summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/features/open-all-notifications.css9
-rw-r--r--source/features/open-all-notifications.tsx56
-rw-r--r--source/features/select-notifications.css3
-rw-r--r--source/features/select-notifications.tsx2
4 files changed, 42 insertions, 28 deletions
diff --git a/source/features/open-all-notifications.css b/source/features/open-all-notifications.css
index 4ca3b172..4848c407 100644
--- a/source/features/open-all-notifications.css
+++ b/source/features/open-all-notifications.css
@@ -1,9 +1,10 @@
/* Align right */
-.js-notifications-mark-selected-actions ~ .rgh-open-notifications-button {
+.js-notifications-mark-selected-actions ~ :is(.rgh-open-notifications-button, .rgh-open-selected-button) {
margin-left: auto;
}
-/* Hide main button when user has selected some notifications */
-.js-notifications-mark-selected-actions:not([hidden]) ~ .rgh-open-notifications-button {
- display: none;
+/* Only show "Open all selected" if some notifications are selected, otherwise show main "Open all unread" button */
+.js-notifications-mark-selected-actions[hidden] ~ .rgh-open-notifications-button,
+.js-notifications-mark-selected-actions:not([hidden]) ~ .rgh-open-selected-button {
+ display: inline-block !important;
}
diff --git a/source/features/open-all-notifications.tsx b/source/features/open-all-notifications.tsx
index 08152307..f242700c 100644
--- a/source/features/open-all-notifications.tsx
+++ b/source/features/open-all-notifications.tsx
@@ -13,33 +13,46 @@ function getUnreadNotifications(container: ParentNode = document): HTMLElement[]
return select.all('.notification-unread', container);
}
-function openNotifications({delegateTarget}: delegate.Event): void {
- const container = delegateTarget.closest('.js-notifications-group') ?? document;
-
+function openNotifications(notifications: Element[]): void {
// Ask for confirmation
- const unreadNotifications = getUnreadNotifications(container);
if (
- unreadNotifications.length >= confirmationRequiredCount
- && !confirm(`This will open ${unreadNotifications.length} new tabs. Continue?`)
+ notifications.length >= confirmationRequiredCount
+ && !confirm(`This will open ${notifications.length} new tabs. Continue?`)
) {
return;
}
- void browser.runtime.sendMessage({
- openUrls: unreadNotifications.map(element => element.querySelector('a')!.href),
- });
-
- // Mark all as read
- for (const notification of unreadNotifications) {
+ const urls: string[] = [];
+ for (const notification of notifications) {
+ // Mark all as read
notification.classList.replace('notification-unread', 'notification-read');
+ urls.push(notification.querySelector('a')!.href);
}
- // Remove all now-unnecessary buttons
+ void browser.runtime.sendMessage({openUrls: urls});
+}
+
+function removeOpenAllButtons(container: ParentNode = document): void {
for (const button of select.all('.rgh-open-notifications-button', container)) {
button.remove();
}
}
+function openUnreadNotifications({delegateTarget}: delegate.Event): void {
+ const container = delegateTarget.closest('.js-notifications-group') ?? document;
+ openNotifications(getUnreadNotifications(container));
+ // Remove all now-unnecessary buttons
+ removeOpenAllButtons(container);
+}
+
+function openSelectedNotifications(): void {
+ const selectedNotifications = select.all('.notifications-list-item :checked').map(checkbox => checkbox.closest('.notifications-list-item')!);
+ openNotifications(selectedNotifications);
+ if (!select.exists('.notification-unread')) {
+ removeOpenAllButtons();
+ }
+}
+
function addOpenReposButton(): void {
for (const repository of select.all('.js-notifications-group')) {
if (getUnreadNotifications(repository).length === 0) {
@@ -54,28 +67,27 @@ function addOpenReposButton(): void {
}
}
-function addOpenAllButton(): void {
+function addOpenAllButton(className: string, text: string): void {
// Selector works on:
// https://github.com/notifications (Grouped by date)
// https://github.com/notifications (Grouped by repo)
// https://github.com/notifications?query=reason%3Acomment (which is an unsaved filter)
select('.js-check-all-container .js-bulk-action-toasts ~ div .Box-header')!.append(
- <button className="btn btn-sm rgh-open-notifications-button" type="button">
- <LinkExternalIcon className="mr-1"/>Open all unread
+ <button className={'btn btn-sm d-none ' + className} type="button">
+ <LinkExternalIcon className="mr-1"/>{text}
</button>,
);
}
-function update(): void {
+function init(): void {
if (getUnreadNotifications().length > 0) {
- addOpenAllButton();
+ delegate(document, '.rgh-open-notifications-button', 'click', openUnreadNotifications);
+ addOpenAllButton('rgh-open-notifications-button', 'Open all unread');
addOpenReposButton();
}
-}
-function init(): void {
- delegate(document, '.rgh-open-notifications-button', 'click', openNotifications);
- update();
+ delegate(document, '.rgh-open-selected-button', 'click', openSelectedNotifications);
+ addOpenAllButton('rgh-open-selected-button', 'Open all selected');
}
void features.add(__filebasename, {
diff --git a/source/features/select-notifications.css b/source/features/select-notifications.css
index 78ed1e51..e91b9fa7 100644
--- a/source/features/select-notifications.css
+++ b/source/features/select-notifications.css
@@ -1,4 +1,5 @@
-.js-notifications-mark-selected-actions > * {
+.js-notifications-mark-selected-actions > *,
+.rgh-open-selected-button {
/* Allow clicking on "Done" and other toolbar buttons even when the dropdown (z-index of 99) is open #4753 */
z-index: 100;
}
diff --git a/source/features/select-notifications.tsx b/source/features/select-notifications.tsx
index 73b24d69..92909ba7 100644
--- a/source/features/select-notifications.tsx
+++ b/source/features/select-notifications.tsx
@@ -169,7 +169,7 @@ function init(): void {
deinit.push(selectObserver.abort);
// Close the dropdown when one of the toolbar buttons is clicked
- delegate(document, '.js-notifications-mark-selected-actions > *', 'click', closeDropdown);
+ delegate(document, '.js-notifications-mark-selected-actions > *, .rgh-open-selected-button', 'click', closeDropdown);
}
void features.add(__filebasename, {