[Profile indicator] Fix: sometimes it doesn't get injected

In the Community Console, check if the OP's username has already been
added to the website before starting the mutationObserver.

This is because sometimes Chrome injects the profile indicator content
script after all the page has been formed, and this means in these cases
the mutationObserver doesn't detect the username being added.

Bug: #21
Change-Id: I0158fd36c590fe26d658e3ec5cfc46f45b5c5284
diff --git a/src/injections/profileindicator_inject.js b/src/injections/profileindicator_inject.js
index 3cf3dab..904f86a 100644
--- a/src/injections/profileindicator_inject.js
+++ b/src/injections/profileindicator_inject.js
@@ -332,6 +332,7 @@
 
   authuser = startup[2][1] || '0';
 
+  // When the OP's username is found, call getOptionsAndHandleIndicators
   function mutationCallback(mutationList, observer) {
     mutationList.forEach((mutation) => {
       if (mutation.type == 'childList') {
@@ -341,6 +342,7 @@
               !isElementInside(node, 'EC-RELATIVE-TIME') &&
               isElementInside(node, 'EC-QUESTION') && ('children' in node) &&
               node.children.length == 0) {
+            console.info('Handling profile indicator via mutation callback.');
             getOptionsAndHandleIndicators(node, true);
           }
         });
@@ -353,6 +355,15 @@
     subtree: true,
   }
 
+  // Before starting the mutation Observer, check if the OP's username link is
+  // already part of the page
+  var node = document.querySelector(
+      'ec-question ec-message-header .name-section ec-user-link a');
+  if (node !== null) {
+    console.info('Handling profile indicator via first check.');
+    getOptionsAndHandleIndicators(node, true);
+  }
+
   mutationObserver = new MutationObserver(mutationCallback);
   mutationObserver.observe(document.body, observerOptions);
 } else {