PageRenderTime 32ms CodeModel.GetById 27ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/WebVox/res/raw/mgmail.user.js

http://eyes-free.googlecode.com/
JavaScript | 64 lines | 46 code | 10 blank | 8 comment | 11 complexity | f7c212b77900f39dd888f6bb61020d03 MD5 | raw file
 1// ==UserScript==
 2// @name          Gmail
 3// @description   Gmail (Mobile) Script
 4// @author        Charles L. Chen
 5// @include       https://mail.google.com/mail/s/*
 6// ==/UserScript==
 7
 8var inputFocused = false;
 9
10function speak(textStr, queueMode, paramsArray){
11  window.ttsHelper.speak(textStr, queueMode);
12  //alert(textStr);
13}
14
15//TODO: Come up with a working escape sequence!
16function keyPressHandler(evt){
17  var keyCode = evt.keyCode;
18  if (inputFocused){
19    return true;
20  }
21  if (keyCode == 106) { // j
22    window.setTimeout(speakCurrentMessage,0);
23    return true;
24  }
25  if (keyCode == 107) { // k
26    window.setTimeout(speakCurrentMessage,0);
27    return true;
28  }
29  return true;
30}
31
32function findCurrentMessage(){
33  var messageNodes = document.getElementsByClassName("a H Id");
34  var message;
35  for (var i=0; message = messageNodes[i]; i++){
36    if (message.style.cssText.indexOf("visibility: visible;") != -1){
37      return message.parentNode;
38    }
39  }
40}
41
42function speakCurrentMessage(){
43  var message = findCurrentMessage();
44  speak(message.textContent, 2, null);
45}
46
47
48function focusHandler(evt){
49  if (evt.target.tagName && 
50      evt.target.tagName == 'INPUT'){
51      inputFocused = true;
52      }
53  return true;
54}
55
56function blurHandler(evt){
57  inputFocused = false;
58  return true;
59}
60
61
62document.addEventListener('keypress', keyPressHandler, true);
63document.addEventListener('focus', focusHandler, true);
64document.addEventListener('blur', blurHandler, true);