Options: make docs links point to the appropriate version

Until now the help button pointed to the latest version of the
"features" document, which might contain information about features
which haven't been launched yet. This change adapts this link and the
link to the "OP indicator" documentation so they point to the document
corresponding to the version installed (or the latest version if the
extension has been loaded in developer mode).

Change-Id: I2a99886b67d11da00214600620bd26f28ff1bdce
diff --git a/src/optionsCommon.js b/src/optionsCommon.js
index afb6bde..42983a5 100644
--- a/src/optionsCommon.js
+++ b/src/optionsCommon.js
@@ -1,10 +1,26 @@
+import {getExtVersion, isFirefox, isReleaseVersion} from './common/extUtils.js';
 import {cleanUpOptions, optionsPrototype, specialOptions} from './common/optionsUtils.js';
-import {isFirefox, isReleaseVersion} from './common/extUtils.js';
 
 var savedSuccessfullyTimeout = null;
 
 const exclusiveOptions = [['thread', 'threadall']];
 
+// Get a URL to a document which is part of the extension documentation (using
+// |ref| as the Git ref).
+function getDocURLWithRef(doc, ref) {
+  return 'https://gerrit.avm99963.com/plugins/gitiles/infinitegforums/+/' +
+      ref + '/docs/' + doc;
+}
+
+// Get a URL to a document which is part of the extension documentation
+// (autodetect the appropriate Git ref)
+function getDocURL(doc) {
+  if (!isReleaseVersion()) return getDocURLWithRef(doc, 'HEAD');
+
+  var version = getExtVersion();
+  return getDocURLWithRef(doc, 'refs/tags/v' + version);
+}
+
 // Get the value of the option set in the options/experiments page
 function getOptionValue(opt) {
   if (specialOptions.includes(opt)) {
@@ -80,12 +96,20 @@
 window.addEventListener('load', function() {
   i18n();
 
-  if (window.CONTEXT == 'options' && !isReleaseVersion()) {
-    var experimentsLink = document.querySelector('.experiments-link');
-    experimentsLink.removeAttribute('hidden');
-    experimentsLink.addEventListener('click', _ => chrome.tabs.create({
-      url: chrome.runtime.getURL('options/experiments.html'),
-    }));
+  if (window.CONTEXT == 'options') {
+    if (!isReleaseVersion()) {
+      var experimentsLink = document.querySelector('.experiments-link');
+      experimentsLink.removeAttribute('hidden');
+      experimentsLink.addEventListener('click', _ => chrome.tabs.create({
+        url: chrome.runtime.getURL('options/experiments.html'),
+      }));
+    }
+
+    var featuresLink = document.querySelector('.features-link');
+    featuresLink.href = getDocURL('features.md');
+
+    var profileIndicatorLink = document.getElementById('profileIndicatorMoreInfo');
+    profileIndicatorLink.href = getDocURL('op_indicator.md');
   }
 
   chrome.storage.sync.get(null, function(items) {