Add option to limit the height of inline images

Fixed: twpowertools:39
Co-authored-by: Barry Hunter
Change-Id: Iabed778be68f4a5211916c648ebcce3a0e305b12
diff --git a/src/common/optionsPrototype.json5 b/src/common/optionsPrototype.json5
index 093228e..0132436 100644
--- a/src/common/optionsPrototype.json5
+++ b/src/common/optionsPrototype.json5
@@ -105,6 +105,11 @@
     context: 'options',
     killSwitchType: 'option',
   },
+  'imagemaxheight': {
+    defaultValue: false,
+    context: 'options',
+    killSwitchType: 'option',
+  },
 
   // Experiments:
 
diff --git a/src/contentScripts/communityConsole/main.js b/src/contentScripts/communityConsole/main.js
index 6b32496..eaff3ce 100644
--- a/src/contentScripts/communityConsole/main.js
+++ b/src/contentScripts/communityConsole/main.js
@@ -225,6 +225,10 @@
     injectStylesheet(chrome.runtime.getURL('css/reposition_expand_thread.css'));
   }
 
+  if (options.imagemaxheight) {
+    injectStylesheet(chrome.runtime.getURL('css/image_max_height.css'));
+  }
+
   if (options.ccforcehidedrawer) {
     var drawer = document.querySelector('material-drawer');
     if (drawer !== null && drawer.classList.contains('mat-drawer-expanded')) {
diff --git a/src/options/optionsPage.json5 b/src/options/optionsPage.json5
index e4641b6..df14718 100644
--- a/src/options/optionsPage.json5
+++ b/src/options/optionsPage.json5
@@ -36,6 +36,7 @@
         {codename: 'ccdragndropfix', customHTML: '<div id="dragndrop-wrapper" class="option" hidden><input type="checkbox" id="ccdragndropfix"> <label for="ccdragndropfix" data-i18n="ccdragndropfix"></label></div>'},
         {codename: 'enhancedannouncementsdot'},
         {codename: 'repositionexpandthread', experimental: true},
+        {codename: 'imagemaxheight'},
       ],
     },
   ],
diff --git a/src/static/_locales/en/messages.json b/src/static/_locales/en/messages.json
index 02b0bea..1fe26e9 100644
--- a/src/static/_locales/en/messages.json
+++ b/src/static/_locales/en/messages.json
@@ -111,6 +111,10 @@
     "message": "Show a notification in the Community Console when a thread list has new updates.",
     "description": "Feature checkbox in the options page"
   },
+  "options_imagemaxheight": {
+    "message": "Prevent inline images in messages from being taller than the current window.",
+    "description": "Feature checkbox in the options page"
+  },
   "options_profileindicator_moreinfo": {
     "message": "+info about the 2 previous options",
     "description": "Link to learn more about the profile indicator feature"
diff --git a/src/static/css/image_max_height.css b/src/static/css/image_max_height.css
new file mode 100644
index 0000000..2e9b48b
--- /dev/null
+++ b/src/static/css/image_max_height.css
@@ -0,0 +1,5 @@
+ec-question .body img,
+    ec-message .body img {
+  /* "Max height = full height - 2 * height of the header" */
+  max-height: calc(100vh - 2*64px);
+}