Add option to show the number of recent posts made by the OP

Add an option to show the number of recent posts made by the OP next to
their username in threads (profileindicator_alt).

If this option and the profileindicator options are set, then the
indicator dot and the recent posts number badge will be merged into a
single component.

Change-Id: If2fb1e8f0066d75ef136b6f93869b7fc2f0c7e57
diff --git a/src/content_scripts/profileindicator_inject.js b/src/content_scripts/profileindicator_inject.js
new file mode 100644
index 0000000..c726783
--- /dev/null
+++ b/src/content_scripts/profileindicator_inject.js
@@ -0,0 +1,41 @@
+chrome.storage.sync.get(null, function(options) {
+  if (options.profileindicator || options.profileindicatoralt) {
+    // In order to pass i18n strings and settings values to the injected script,
+    // which doesn't have access to the chrome.* APIs, we use event listeners.
+    window.addEventListener('TWPT_sendRequest', evt => {
+      var request = evt.detail;
+      switch (request.data.action) {
+        case 'geti18nMessage':
+          var data = chrome.i18n.getMessage(
+              request.data.msg,
+              (Array.isArray(request.data.placeholders) ?
+                   request.data.placeholders :
+                   []));
+          break;
+
+        case 'getProfileIndicatorOptions':
+          var data = {
+            'indicatorDot': options.profileindicator,
+            'numPosts': options.profileindicatoralt
+          };
+          break;
+
+        case 'getNumPostMonths':
+          var data = options.profileindicatoralt_months;
+          break;
+
+        default:
+          var data = 'unknownAction';
+          break;
+      }
+      var response = {data, requestId: request.id, prefix: 'TWPT'};
+
+      window.postMessage(response, '*');
+    });
+
+    injectScript(
+        chrome.runtime.getURL('injections/profileindicator_inject.js'));
+    injectStylesheet(
+        chrome.runtime.getURL('injections/profileindicator_inject.css'));
+  }
+});