Fix: "ask" link in thread lists w/ infinite scroll

In thread lists, the "ask" link in thread lists appears after the "load
more" button. If infinite scroll is enabled, this means it can't be
clicked. This change fixes this by moving the "ask community" card
before the "load more" button.

Fixed: twpowertools:73
Change-Id: I8c331ba463148110ef8f63d1fcb6e934fa3983b4
diff --git a/src/contentScripts/publicForum.js b/src/contentScripts/publicForum.js
index 0163f54..043e8c9 100644
--- a/src/contentScripts/publicForum.js
+++ b/src/contentScripts/publicForum.js
@@ -20,5 +20,16 @@
     intersectionObserver =
         new IntersectionObserver(intersectionCallback, intersectionOptions);
     intersectionObserver.observe(button);
+
+    // On a best-effort basis, move the "ask community" card before the "load
+    // more" button, if both exist.
+    let buttonContainer = document.querySelector(
+        '.thread-list__threads > .thread-list-threads__load-more-container');
+    let askCard =
+        document.querySelector('.thread-list__threads > .ask-community-card');
+    if (buttonContainer !== null && askCard !== null) {
+      let threadList = document.querySelector('.thread-list__threads');
+      threadList.insertBefore(askCard, buttonContainer);
+    }
   }
 });