Make some of the options dynamic

This change modifies the logic of several features so they aren't
enabled/disabled depending on the options state when the page is loaded
but dynamically.

So, for instance, when the thread list avatars feature is switched from
enabled to disabled, when browsing the Community Console, newly loaded
thread lists won't have the avatars, without having to reload the whole
Community Console.

This will make "kill switches" more effective, since they will be able
to take effect without having to reload the Community Console page.

The options which still haven't been made dynamic are features which add
CSS tweaks to the Community Console. For those features (like the dark
mode) a future CL will make them dynamic.

Bug: twpowertools:61
Change-Id: I72b511dd3b2622a2e9c633850e29806953e4b284
diff --git a/src/contentScripts/communityConsole/autoRefresh.js b/src/contentScripts/communityConsole/autoRefresh.js
index ae11751..a35a6f0 100644
--- a/src/contentScripts/communityConsole/autoRefresh.js
+++ b/src/contentScripts/communityConsole/autoRefresh.js
@@ -1,5 +1,6 @@
 import {CCApi} from '../../common/api.js';
 import {getAuthUser} from '../../common/communityConsoleUtils.js';
+import {isOptionEnabled} from '../../common/optionsUtils.js';
 
 import {createExtBadge} from './utils/common.js';
 
@@ -90,6 +91,7 @@
     this.isUpdatePromptShown = true;
   }
 
+  // This function can be called even if the update prompt is not shown.
   hideUpdatePrompt() {
     if (this.snackbar) this.snackbar.classList.add('TWPT-hidden');
     document.title = document.title.replace('[!!!] ', '');
@@ -261,24 +263,28 @@
   // This is called when a thread list node is detected in the page. This
   // initializes the interval to check for updates, and several other things.
   setUp() {
-    if (!this.isOrderedByTimestampDescending()) {
-      this.injectStatusIndicator(false);
-      console.debug(
-          'autorefresh_list: refused to start up because the order is not by timestamp descending.');
-      return;
-    }
+    isOptionEnabled('autorefreshlist').then(isEnabled => {
+      if (!isEnabled) return;
 
-    this.unregister();
+      if (!this.isOrderedByTimestampDescending()) {
+        this.injectStatusIndicator(false);
+        console.debug(
+            'autorefresh_list: refused to start up because the order is not by timestamp descending.');
+        return;
+      }
 
-    console.debug('autorefresh_list: starting set up...');
+      this.unregister();
 
-    if (this.snackbar === null) this.injectUpdatePrompt();
-    this.injectStatusIndicator(true);
+      console.debug('autorefresh_list: starting set up...');
 
-    this.isLookingForUpdates = true;
-    this.path = location.pathname;
+      if (this.snackbar === null) this.injectUpdatePrompt();
+      this.injectStatusIndicator(true);
 
-    var checkUpdateCallback = this.checkUpdate.bind(this);
-    this.interval = window.setInterval(checkUpdateCallback, intervalMs);
+      this.isLookingForUpdates = true;
+      this.path = location.pathname;
+
+      var checkUpdateCallback = this.checkUpdate.bind(this);
+      this.interval = window.setInterval(checkUpdateCallback, intervalMs);
+    });
   }
 };