Add workflow menu button to thread lists
Bug: twpowertools:74
Change-Id: I703950394d674c2084278bf9e876014d08fa5cfb
diff --git a/src/contentScripts/communityConsole/utils/common.js b/src/contentScripts/communityConsole/utils/common.js
index 648fae2..68fb736 100644
--- a/src/contentScripts/communityConsole/utils/common.js
+++ b/src/contentScripts/communityConsole/utils/common.js
@@ -34,7 +34,8 @@
// Adds a button to the thread list actions bar next to the button given by
// |originalBtn|. The button will have icon |icon|, when hovered it will display
// |tooltip|, and will have a debugid attribute with value |debugId|.
-export function addButtonToThreadListActions(originalBtn, icon, debugId, tooltip) {
+export function addButtonToThreadListActions(
+ originalBtn, icon, debugId, tooltip) {
let clone = originalBtn.cloneNode(true);
clone.setAttribute('debugid', debugId);
clone.classList.add('TWPT-btn--with-badge');
@@ -59,3 +60,15 @@
return clone;
}
+
+// Returns true if |node| is the "mark as read/unread" button, the parent of the
+// parent of |node| is the actions bar of the thread list, and the button with
+// debugid |debugid| is NOT part of the actions bar.
+export function shouldAddBtnToActionBar(debugid, node) {
+ return node?.tagName == 'MATERIAL-BUTTON' &&
+ (node.getAttribute?.('debugid') == 'mark-read-button' ||
+ node.getAttribute?.('debugid') == 'mark-unread-button') &&
+ node.getAttribute?.('debugid') !== null &&
+ node.parentNode?.querySelector('[debugid="' + debugid + '"]') === null &&
+ node.parentNode?.parentNode?.tagName == 'EC-BULK-ACTIONS';
+}