Simplify CC code with new softRefreshView function

This new function automatically clicks the Community Console logo to
soft refresh the current view. It will be used in other parts of the
extension in the future, so this commits refactors the code so the logic
is found in a unique place in the codebase.

Bug: twpowertools:153
Change-Id: I2b061123021e5026e95793d9a77730c2a1eb70ae
diff --git a/src/contentScripts/communityConsole/autoRefresh.js b/src/contentScripts/communityConsole/autoRefresh.js
index e5dc8c8..1cbee9f 100644
--- a/src/contentScripts/communityConsole/autoRefresh.js
+++ b/src/contentScripts/communityConsole/autoRefresh.js
@@ -5,7 +5,7 @@
 import {isOptionEnabled} from '../../common/optionsUtils.js';
 import {createPlainTooltip} from '../../common/tooltip.js';
 
-import {createExtBadge} from './utils/common.js';
+import {createExtBadge, softRefreshView} from './utils/common.js';
 
 var authuser = getAuthUser();
 
@@ -135,7 +135,7 @@
 
     action.addEventListener('click', e => {
       this.hideUpdatePrompt();
-      document.querySelector('.app-title-button').click();
+      softRefreshView();
     });
 
     content.append(badge, message, action);
diff --git a/src/contentScripts/communityConsole/batchLock.js b/src/contentScripts/communityConsole/batchLock.js
index db08a06..83af3ce 100644
--- a/src/contentScripts/communityConsole/batchLock.js
+++ b/src/contentScripts/communityConsole/batchLock.js
@@ -1,6 +1,6 @@
 import {isOptionEnabled} from '../../common/optionsUtils.js';
 
-import {addButtonToThreadListActions, removeChildNodes, shouldAddBtnToActionBar} from './utils/common.js';
+import {addButtonToThreadListActions, removeChildNodes, shouldAddBtnToActionBar, softRefreshView} from './utils/common.js';
 
 const kLockDebugId = 'twpt-lock';
 
@@ -71,13 +71,7 @@
             btn.addEventListener('click', _ => {
               if (btn.classList.contains('is-disabled')) return;
 
-              if (action == 'close') {
-                var refreshButton = document.querySelector('.app-title-button');
-                if (refreshButton == null)
-                  window.location.reload();
-                else
-                  refreshButton.click();
-              }
+              if (action == 'close') softRefreshView();
 
               modal.classList.remove('visible');
               modal.style.display = 'none';
diff --git a/src/contentScripts/communityConsole/utils/common.js b/src/contentScripts/communityConsole/utils/common.js
index 052b580..e1d417b 100644
--- a/src/contentScripts/communityConsole/utils/common.js
+++ b/src/contentScripts/communityConsole/utils/common.js
@@ -84,3 +84,13 @@
       JSON.parse(document.querySelector('html').getAttribute('data-startup'));
   return startup?.[1]?.[1]?.[3]?.[6] ?? 'en';
 }
+
+// Refreshes the current view in the Community Console without reloading the
+// whole page if possible.
+export function softRefreshView() {
+  const refreshButton = document.querySelector('.app-title-button');
+  if (refreshButton == null)
+    window.location.reload();
+  else
+    refreshButton.click();
+}