From d003a96d3e4cf65bebd4472c182d239671edb247 Mon Sep 17 00:00:00 2001 From: Adam Pritchard Date: Tue, 2 Jun 2015 21:47:20 -0400 Subject: [PATCH] Fixed #283: Google Inbox forgot-to-render detection was broken --- src/_locales/en/messages.json | 6 ++--- src/common/CHANGES.md | 7 +++++ src/common/common-logic.js | 27 ++++++++++++++----- src/common/options.html | 4 +-- src/common/utils.js | 2 ++ .../chrome/locale/en/strings.properties | 4 +-- 6 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index 94466c4e..840cebcc 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -292,13 +292,13 @@ "description": "Label for the checkbox that enables the forgot-to-render feature" }, "options_page__forgot_to_render_1": { - "message": "Currently only supported in the Gmail web interface and Thunderbird (and Postbox and Icedove)." + "message": "Currently only supported in the Gmail and Google Inbox web interfaces, and Thunderbird (and Postbox and Icedove)." }, "options_page__forgot_to_render_2": { "message": "When you send an email, this checks the content to see if it looks like you wrote it in Markdown, but forgot to render it (i.e., click \"Markdown Toggle\") before sending. This may need to be disabled if it interferes with your ability to send email." }, - "options_page__forgot_to_render_3": { - "message": "If you find yourself disabling this, please let me know why and how it could be better. Create a post on the \"markdown-here\" Google Group or an issue in the Github project. Thanks." + "options_page__forgot_to_render_4": { + "message": "If this feature stops working for you, please let us know by posting to the \"markdown-here\" Google Group or creating an issue in the Github project. (Hooking into the email sending web UI is brittle and will sometimes break.)" }, "options_page__contributing_title": { "message": "Contributing", diff --git a/src/common/CHANGES.md b/src/common/CHANGES.md index e677aaf5..42361448 100644 --- a/src/common/CHANGES.md +++ b/src/common/CHANGES.md @@ -4,6 +4,13 @@ Change Log ### Voting is complete and the [**new Markdown Here logo**](http://markdown-here.com/logo.html) has been chosen by the users! +2015-06-xx: v2.11.10 +-------------------- + +* [Fixed bug #283](https://github.com/adam-p/markdown-here/issues/283): Forgot-to-render detection was broken for Google Inbox. Thanks to [Marvin R.](https://github.com/therealmarv). + - If you find that the forgot-to-render detection gets broken for the Gmail or Google Inbox web interfaces, please post to the ["markdown-here" Google Group](https://groups.google.com/group/markdown-here) or create [an issue in the Github project](https://github.com/adam-p/markdown-here/issues). The MDH code that hooks into the web UI is brittle and might break when Google changes stuff. + + 2015-05-26: v2.11.9 ------------------- diff --git a/src/common/common-logic.js b/src/common/common-logic.js index e87d3b96..dff71d87 100644 --- a/src/common/common-logic.js +++ b/src/common/common-logic.js @@ -122,14 +122,14 @@ var ESCAPE_KEYCODE = 27; var WATCHED_PROPERTY = 'markdownHereForgotToRenderWatched'; -// Returns the correct selector to use when looking for the Send button. +// Returns the correct selector to use when looking for the Send button. // Returns null if forgot-to-render should not be used here. function getForgotToRenderButtonSelector(elem) { if (elem.ownerDocument.location.host.indexOf('mail.google.') >= 0) { return '[role="button"][tabindex="1"]'; } else if (elem.ownerDocument.location.host.indexOf('inbox.google.') >= 0) { - return '[role="button"][tabindex="0"]'; + return '[role="button"][tabindex="0"][jsaction$=".send"]'; } return null; @@ -157,7 +157,7 @@ function forgotToRenderIntervalCheck(focusedElem, MarkdownHere, MdhHtmlToText, m var forgotToRenderButtonSelector = getForgotToRenderButtonSelector(focusedElem); if (!forgotToRenderButtonSelector) { debugLog('forgotToRenderIntervalCheck', 'not supported'); - return; + return; } // If focus isn't in the compose body, there's nothing to do @@ -189,7 +189,7 @@ function findClosestSendButton(elem) { // boundaries and sometimes we won't. var forgotToRenderButtonSelector = getForgotToRenderButtonSelector(elem); - // If we're in this function, this should not non-null, but... + // If we're in this function, this should be non-null, but... if (!forgotToRenderButtonSelector) { return null; } @@ -243,13 +243,28 @@ function setupForgotToRenderInterceptors(composeElem, MdhHtmlToText, marked, pre return probablyWritingMarkdown(mdMaybe, marked, prefs); }; + // Helper function to look for element within parents up to a certain point. + // We use this because sometimes a click even happens on a child element of + // the send button, but we still want it to count as a click on the button. + var isSendButtonOrChild = function(eventTarget) { + var elem = eventTarget; + while (elem && elem.nodeType === elem.ELEMENT_NODE && + elem !== composeSendButton.parentNode) { + if (elem === composeSendButton) { + return true; + } + elem = elem.parentNode; + } + return false; + }; + // NOTE: We are setting the event listeners on the *parent* element of the // send button and compose area. This is so that we can capture and prevent // propagation to the actual element, thereby preventing Gmail's event // listeners from firing. var composeSendButtonKeyListener = function(event) { - if (event.target === composeSendButton && + if (isSendButtonOrChild(event.target) && (event.keyCode === ENTER_KEYCODE || event.keyCode === SPACE_KEYCODE) && shouldIntercept()) { // Gmail uses keydown to trigger its send action. Firefox fires keyup even if @@ -267,7 +282,7 @@ function setupForgotToRenderInterceptors(composeElem, MdhHtmlToText, marked, pre }; var composeSendButtonClickListener = function(event) { - if (event.target === composeSendButton && + if (isSendButtonOrChild(event.target) && !event[Utils.MARKDOWN_HERE_EVENT] && shouldIntercept()) { eatEvent(event); diff --git a/src/common/options.html b/src/common/options.html index b94e5899..f1f38ef0 100644 --- a/src/common/options.html +++ b/src/common/options.html @@ -590,8 +590,8 @@

When you send an email, this checks the content to see if it looks like you wrote it in Markdown, but forgot to render it (i.e., click "Markdown Toggle") before sending. This may need to be disabled if it interferes with your ability to send email.

-

- If you find yourself disabling this, please let me know why and how it could be better. Create a post on the "markdown-here" Google Group or an issue in the Github project. Thanks. +

+ If this feature stops working for you, please let us know by posting to the "markdown-here" Google Group or creating an issue in the Github project. (Hooking into the email sending web UI is brittle and will sometimes break.)

diff --git a/src/common/utils.js b/src/common/utils.js index c45126ae..24f78765 100644 --- a/src/common/utils.js +++ b/src/common/utils.js @@ -194,6 +194,7 @@ function getSelectedElementsInRange(range) { } }); + /*? if(platform!=='mozilla'){ */ /* // This code is probably superior, but TreeWalker is not supported by Postbox. // If this ends up getting used, it should probably be moved into walkDOM @@ -211,6 +212,7 @@ function getSelectedElementsInRange(range) { elems.push(treeWalker.currentNode); } */ + /*? } */ } return elems; diff --git a/src/firefox/chrome/locale/en/strings.properties b/src/firefox/chrome/locale/en/strings.properties index 65d2a41b..2ef3c38d 100644 --- a/src/firefox/chrome/locale/en/strings.properties +++ b/src/firefox/chrome/locale/en/strings.properties @@ -28,9 +28,9 @@ options_page__donate_plea_3=Help support the development of Markdown Her options_page__donate_plea_4=You know what makes it easier to keep Markdown Here working on Chrome, Firefox, Thunderbird, Postbox, Safari, Opera, Gmail, Yahoo, Hotmail, Blogger, Evernote, etc.? Coffee! options_page__footer_1=Markdown Here is open source. To ask questions, report bugs, request features, or contribute, visit the Github project page or the \"markdown-here\" Google Group. options_page__footer_2=Created by Adam Pritchard. -options_page__forgot_to_render_1=Currently only supported in the Gmail web interface and Thunderbird (and Postbox and Icedove). +options_page__forgot_to_render_1=Currently only supported in the Gmail and Google Inbox web interfaces, and Thunderbird (and Postbox and Icedove). options_page__forgot_to_render_2=When you send an email, this checks the content to see if it looks like you wrote it in Markdown, but forgot to render it (i.e., click \"Markdown Toggle\") before sending. This may need to be disabled if it interferes with your ability to send email. -options_page__forgot_to_render_3=If you find yourself disabling this, please let me know why and how it could be better. Create a post on the \"markdown-here\" Google Group or an issue in the Github project. Thanks. +options_page__forgot_to_render_4=If this feature stops working for you, please let us know by posting to the \"markdown-here\" Google Group or creating an issue in the Github project. (Hooking into the email sending web UI is brittle and will sometimes break.) options_page__forgot_to_render_label=Enable \"forgot-to-render\" check. options_page__gfm_line_breaks_enabled_label=Enable GFM line breaks. options_page__ggroup=Ask a question, start a discussion, or just say hi in the markdown-here Google Group.