// ==UserScript==
// @name           Gmail Fix Focus
// @namespace      http://ed.agadak.net/
// @description    Fix focus issues that prevent keyboard shortcuts from working - Edward Lee (Mr. AwesomeBar)
// @include        http://mail.google.com/*
// @include        https://mail.google.com/*
// ==/UserScript==

// Focus issues happen when the top document is focused, so pass focus
// to the content iframe that is visible
if (document == top.document) {
  document.addEventListener("focus", function() {
    var iframes = document.getElementsByTagName("iframe");
    for (var i = iframes.length; --i > 0; ) {
      if (iframes[i].clientWidth > 0) {
        iframes[i].contentWindow.focus();
        break;
      }
    }
  }, false);
}