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/common/extUtils.js b/src/common/extUtils.js
index a1b4d48..1777c87 100644
--- a/src/common/extUtils.js
+++ b/src/common/extUtils.js
@@ -11,3 +11,9 @@
   var manifest = chrome.runtime.getManifest();
   return ('version' in manifest) && manifest.version != '0';
 }
+
+// Returns the extension version
+export function getExtVersion() {
+  var manifest = chrome.runtime.getManifest();
+  return manifest?.version;
+}
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) {
diff --git a/src/static/options/options.html b/src/static/options/options.html
index 30a9b60..89413bc 100644
--- a/src/static/options/options.html
+++ b/src/static/options/options.html
@@ -28,7 +28,7 @@
           -->
           <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M12.87 15.07l-2.54-2.51.03-.03c1.74-1.94 2.98-4.17 3.71-6.53H17V4h-7V2H8v2H1v1.99h11.17C11.5 7.92 10.44 9.75 9 11.35 8.07 10.32 7.3 9.19 6.69 8h-2c.73 1.63 1.73 3.17 2.98 4.56l-5.09 5.02L4 19l5-5 3.11 3.11.76-2.04zM18.5 10h-2L12 22h2l1.12-3h4.75L21 22h2l-4.5-12zm-2.62 7l1.62-4.33L19.12 17h-3.24z"/></svg>
         </a>
-        <a href="https://gerrit.avm99963.com/plugins/gitiles/infinitegforums/+/master/docs/features.md" target="_blank" rel="noreferrer noopener" class="features-link">
+        <a target="_blank" rel="noreferrer noopener" class="features-link">
           <!--
             Material Design Icon - action/help_outline
              - LICENSE: Apache License Version 2.0
@@ -59,7 +59,7 @@
         <h4 data-i18n="profileindicator_header"></h4>
         <div class="option"><input type="checkbox" id="profileindicator"> <label for="profileindicator" data-i18n="profileindicator"></label> <span class="experimental-label" data-i18n="experimental_label"></span></div>
         <div class="option"><input type="checkbox" id="profileindicatoralt"> <label for="profileindicatoralt" data-i18n="profileindicatoralt"></label> <span class="experimental-label" data-i18n="experimental_label"></span></div>
-        <div class="option"><a href="https://gerrit.avm99963.com/plugins/gitiles/infinitegforums/+/refs/heads/master/docs/op_indicator.md" target="_blank" rel="noreferrer noopener" data-i18n="profileindicator_moreinfo"></a></div>
+        <div class="option"><a id="profileIndicatorMoreInfo" target="_blank" rel="noreferrer noopener" data-i18n="profileindicator_moreinfo"></a></div>
         <div class="actions"><button id="save" data-i18n="save"></button></div>
       </form>
       <div id="save-indicator"></div>