infiniteScroll: fix incompatibility w/ message links

When opening a link to a specific message inside a thread in both TW
basic and the Community Console, the "load more" button might be visible
for an instant before/while scrolling to and focusing the specific
message being linked. This causes the "load more" button to be pressed
automatically when the infinite scroll feature is enabled.

This CL fixes this issue by adding a delay of 3.5s before enabling the
infinite scroll feature when the URL specifies a message to focus.

Fixed: twpowertools:141
Change-Id: Ie9126141ee9f763707bd61b272ec53b4e1d8079f
diff --git a/src/contentScripts/communityConsole/infiniteScroll.js b/src/contentScripts/communityConsole/infiniteScroll.js
index 0d2f3c1..447974e 100644
--- a/src/contentScripts/communityConsole/infiniteScroll.js
+++ b/src/contentScripts/communityConsole/infiniteScroll.js
@@ -9,6 +9,7 @@
   'scTailwindThreadMessagegapload-all': 'threadall',
   'scTailwindThreadMessagegapload-more': 'thread',
 };
+const kArtificialScrollingDelay = 3500;
 
 export default class InfiniteScroll {
   constructor() {
@@ -41,7 +42,11 @@
     });
   }
 
-  observeLoadMoreBar(bar) {
+  isPotentiallyArtificialScroll() {
+    return window.location.href.includes('/message/');
+  }
+
+  observeWithPotentialDelay(node) {
     if (this.intersectionObserver === null) {
       console.warn(
           '[infinitescroll] ' +
@@ -49,24 +54,25 @@
       return;
     }
 
+    if (this.isPotentiallyArtificialScroll()) {
+      window.setTimeout(
+          () => {this.intersectionObserver.observe(node)},
+          kArtificialScrollingDelay);
+    } else {
+      this.intersectionObserver.observe(node);
+    }
+  }
+
+  observeLoadMoreBar(bar) {
     getOptions(['thread', 'threadall']).then(threadOptions => {
       if (threadOptions.thread)
-        this.intersectionObserver.observe(
-            bar.querySelector('.load-more-button'));
+        this.observeWithPotentialDelay(bar.querySelector('.load-more-button'));
       if (threadOptions.threadall)
-        this.intersectionObserver.observe(
-            bar.querySelector('.load-all-button'));
+        this.observeWithPotentialDelay(bar.querySelector('.load-all-button'));
     });
   }
 
   observeLoadMoreInteropBtn(btn) {
-    if (this.intersectionObserver === null) {
-      console.warn(
-          '[infinitescroll] ' +
-          'The intersectionObserver is not ready yet.');
-      return;
-    }
-
     let parentClasses = btn.parentNode?.classList;
     let feature = null;
     for (const [c, f] of Object.entries(kInteropLoadMoreClasses)) {
@@ -77,7 +83,7 @@
     }
     if (feature === null) return;
     isOptionEnabled(feature).then(isEnabled => {
-      if (isEnabled) this.intersectionObserver.observe(btn);
+      if (isEnabled) this.observeWithPotentialDelay(btn);
     });
   }
 };