Extract logic to add buttons to the bulk actions bar

In the future, we will want to add many buttons to the bulk actions bar
in thread lists. This CL prepares for that by moving the logic which
detects whether the button has already been inserted into the bar to a
common file, so it can be reused by features other than the "batch lock"
feature.

Bug: twpowertools:74
Change-Id: Ic98cb68e5a8d0ca97e24578050b53cff6fdde41c
diff --git a/src/contentScripts/communityConsole/batchLock.js b/src/contentScripts/communityConsole/batchLock.js
index 86a7057..db08a06 100644
--- a/src/contentScripts/communityConsole/batchLock.js
+++ b/src/contentScripts/communityConsole/batchLock.js
@@ -1,19 +1,12 @@
 import {isOptionEnabled} from '../../common/optionsUtils.js';
 
-import {addButtonToThreadListActions, removeChildNodes} from './utils/common.js';
+import {addButtonToThreadListActions, removeChildNodes, shouldAddBtnToActionBar} from './utils/common.js';
+
+const kLockDebugId = 'twpt-lock';
 
 export var batchLock = {
-  nodeIsReadToggleBtn(node) {
-    return ('tagName' in node) && node.tagName == 'MATERIAL-BUTTON' &&
-        node.getAttribute('debugid') !== null &&
-        (node.getAttribute('debugid') == 'mark-read-button' ||
-         node.getAttribute('debugid') == 'mark-unread-button') &&
-        ('parentNode' in node) && node.parentNode !== null &&
-        ('parentNode' in node.parentNode) &&
-        node.parentNode.querySelector('[debugid="twpt-lock"]') === null &&
-        node.parentNode.parentNode !== null &&
-        ('tagName' in node.parentNode.parentNode) &&
-        node.parentNode.parentNode.tagName == 'EC-BULK-ACTIONS';
+  shouldAddButton(node) {
+    return shouldAddBtnToActionBar(kLockDebugId, node);
   },
   createDialog() {
     var modal = document.querySelector('.pane[pane-id="default-1"]');
@@ -119,7 +112,7 @@
       if (isEnabled) {
         let tooltip = chrome.i18n.getMessage('inject_lockbtn');
         let btn = addButtonToThreadListActions(
-            readToggle, 'lock', 'twpt-lock', tooltip);
+            readToggle, 'lock', kLockDebugId, tooltip);
         btn.addEventListener('click', () => {
           this.createDialog();
         });