Add option to enable the 'SMEI_SORT_DIRECTION' experiment

This option, when enabled, activates the SMEI_SORT_DIRECTION experiment,
which is disabled by default in the Community Console.

This experiment lets user set the sort direction in thread lists, so
threads can be ordered in ascending or descending order.

Fixes: #25
Change-Id: Ie8f6825e70d11ee7d3e20a38a7f20e2a34780d9f
diff --git a/docs/features.es.md b/docs/features.es.md
index 9f75777..a1762a9 100644
--- a/docs/features.es.md
+++ b/docs/features.es.md
@@ -118,6 +118,14 @@
 
 ![GIF que muestra cómo funciona la función](resources/batch_lock.gif)
 
+### Sentido del orden en la Consola de la Comunidad
+> **Opción:** _Activa el experimento `SMEI_SORT_DIRECTION`._
+
+Esta opción activa un experimento disponible en la Consola de la Comunidad que
+te permite ordenar las listas de hilos en sentido ascendente o descendente.
+
+![GIF que muestra cómo cambiar entre el sentido ascendente/descendente](resources/smei_sort_direction.gif)
+
 ### Punto indicador
 > **Opciones:** _Muestra si el autor del hilo ha participado en otros hilos_,
 _Muestra el número de preguntas y respuestas escritas por el autor del hilo
diff --git a/docs/features.md b/docs/features.md
index babc724..c7a5a38 100644
--- a/docs/features.md
+++ b/docs/features.md
@@ -111,6 +111,14 @@
 
 ![GIF showing how the feature works](resources/batch_lock.gif)
 
+### Sort direction in the Community Console
+> **Option name:** _Enable the `SMEI_SORT_DIRECTION` experiment._
+
+This option enables an experiment available in the Community Console which lets
+you sort thread lists in ascending or descending order.
+
+![GIF showing how to switch between ascending/descending order](resources/smei_sort_direction.gif)
+
 ### Indicator dot
 > **Option names:** _Show whether the OP has participated in other threads_,
 _Show the number of questions and replies written by the OP within the last `n`
diff --git a/docs/resources/smei_sort_direction.gif b/docs/resources/smei_sort_direction.gif
new file mode 100644
index 0000000..e9b6a8f
--- /dev/null
+++ b/docs/resources/smei_sort_direction.gif
Binary files differ
diff --git a/src/_locales/ca/messages.json b/src/_locales/ca/messages.json
index 482d022..87fda39 100644
--- a/src/_locales/ca/messages.json
+++ b/src/_locales/ca/messages.json
@@ -87,6 +87,10 @@
     "message": "Afegeix l'opció per bloquejar diversos fils a la llista de fils de la Consola de la Comunitat.",
     "description": "Feature checkbox in the options page"
   },
+  "options_smei_sortdirection": {
+    "message": "Activa l'experiment <code class=\"help\" title=\"Aquest experiment et permet ordenar la llista de fils de la Consola de la Comunitat en ordre ascendent o descendent.\">SMEI_SORT_DIRECTION</code>.",
+    "description": "Feature checkbox in the options page"
+  },
   "options_profileindicator_header": {
     "message": "Punt indicador",
     "description": "Heading for the profile indicator feature options"
diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json
index ab740c1..65b2640 100644
--- a/src/_locales/en/messages.json
+++ b/src/_locales/en/messages.json
@@ -91,6 +91,10 @@
     "message": "Add the option to lock multiple threads from the Community Console thread list.",
     "description": "Feature checkbox in the options page"
   },
+  "options_smei_sortdirection": {
+    "message": "Enable the <code class=\"help\" title=\"This experiment lets you sort the Community Console thread list in ascending or descending order.\">SMEI_SORT_DIRECTION</code> experiment.",
+    "description": "Feature checkbox in the options page"
+  },
   "options_profileindicator_header": {
     "message": "Indicator dot",
     "description": "Heading for the profile indicator feature options"
diff --git a/src/_locales/es/messages.json b/src/_locales/es/messages.json
index a0e97bf..0e5b0a6 100644
--- a/src/_locales/es/messages.json
+++ b/src/_locales/es/messages.json
@@ -87,6 +87,10 @@
     "message": "Añade la opción para bloquear varios hilos en la lista de hilos de la Consola de la Comunidad.",
     "description": "Feature checkbox in the options page"
   },
+  "options_smei_sortdirection": {
+    "message": "Activa el experimento <code class=\"help\" title=\"Este experimento te permite ordenar la lista de hilos de la Consola de la Comunidad en orden ascendente o descendente.\">SMEI_SORT_DIRECTION</code>.",
+    "description": "Feature checkbox in the options page"
+  },
   "options_profileindicator_header": {
     "message": "Punto indicador",
     "description": "Heading for the profile indicator feature options"
diff --git a/src/common/common.js b/src/common/common.js
index 3426fb0..28a86fd 100644
--- a/src/common/common.js
+++ b/src/common/common.js
@@ -20,6 +20,7 @@
   'ccforcehidedrawer': false,
   'ccdragndropfix': false,
   'batchlock': false,
+  'smei_sortdirection': false,
 };
 
 const specialOptions = [
diff --git a/src/content_scripts/console_inject_start.js b/src/content_scripts/console_inject_start.js
index 52482c5..f0bda9b 100644
--- a/src/content_scripts/console_inject_start.js
+++ b/src/content_scripts/console_inject_start.js
@@ -7,6 +7,11 @@
       startup[4][13] = true;
     }
 
+    if (items.smei_sortdirection) {
+      if (!startup[1][6].includes(8))
+        startup[1][6].push(8);
+    }
+
     document.querySelector('html').setAttribute(
         'data-startup', JSON.stringify(startup));
   }
diff --git a/src/options/options.html b/src/options/options.html
index 6edd040..15716da 100644
--- a/src/options/options.html
+++ b/src/options/options.html
@@ -32,6 +32,7 @@
       <div class="option"><input type="checkbox" id="ccforcehidedrawer"> <label for="ccforcehidedrawer" data-i18n="ccforcehidedrawer"></label></div>
       <div id="dragndrop-wrapper" class="option" hidden><input type="checkbox" id="ccdragndropfix"> <label for="ccdragndropfix" data-i18n="ccdragndropfix"></label></div>
       <div class="option"><input type="checkbox" id="batchlock"> <label for="batchlock" data-i18n="batchlock"></label> <span class="experimental-label" data-i18n="experimental_label"></span></div>
+      <div class="option"><input type="checkbox" id="smei_sortdirection"> <label for="smei_sortdirection" data-i18n="smei_sortdirection"></label> <span class="experimental-label" data-i18n="experimental_label"></span></div>
       <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>