feedSomeKeysがGoogle Readerでうまく動かない

ので、IRCで聴きつつ調べた。
理由はよくわからないが、常に仮想キーコードを使うようにしたら動くっぽい。
http://www.kurinton.net/~snca/blogfiles/feedSomeKeys.js.diff

--- feedSomeKeys.js.orig
+++ feedSomeKeys.js
@@ -44,6 +44,7 @@
 liberator.plugins.feedKey = (function(){
 var origMaps = [];
 var feedMaps = [];
+const useVKeys = true;
 
 // keyTableの再定義...ひどく不毛...
 const keyTable = [
@@ -88,6 +89,59 @@
     [ KeyEvent.DOM_VK_F23, ["F23"] ],
     [ KeyEvent.DOM_VK_F24, ["F24"] ]
 ];
+const VKeyTable = {}
+with (KeyEvent) {
+    VKeyTable['0']  = DOM_VK_0;
+    VKeyTable['1']  = DOM_VK_1;
+    VKeyTable['2']  = DOM_VK_2;
+    VKeyTable['3']  = DOM_VK_3;
+    VKeyTable['4']  = DOM_VK_4;
+    VKeyTable['5']  = DOM_VK_5;
+    VKeyTable['6']  = DOM_VK_6;
+    VKeyTable['7']  = DOM_VK_7;
+    VKeyTable['8']  = DOM_VK_8;
+    VKeyTable['9']  = DOM_VK_9;
+    VKeyTable[';']  = DOM_VK_SEMICOLON;
+    VKeyTable['=']  = DOM_VK_EQUALS;
+    VKeyTable['a']  = DOM_VK_A;
+    VKeyTable['b']  = DOM_VK_B;
+    VKeyTable['c']  = DOM_VK_C;
+    VKeyTable['d']  = DOM_VK_D;
+    VKeyTable['e']  = DOM_VK_E;
+    VKeyTable['f']  = DOM_VK_F;
+    VKeyTable['g']  = DOM_VK_G;
+    VKeyTable['h']  = DOM_VK_H;
+    VKeyTable['i']  = DOM_VK_I;
+    VKeyTable['j']  = DOM_VK_J;
+    VKeyTable['k']  = DOM_VK_K;
+    VKeyTable['l']  = DOM_VK_L;
+    VKeyTable['m']  = DOM_VK_M;
+    VKeyTable['n']  = DOM_VK_N;
+    VKeyTable['o']  = DOM_VK_O;
+    VKeyTable['p']  = DOM_VK_P;
+    VKeyTable['q']  = DOM_VK_Q;
+    VKeyTable['r']  = DOM_VK_R;
+    VKeyTable['s']  = DOM_VK_S;
+    VKeyTable['t']  = DOM_VK_T;
+    VKeyTable['u']  = DOM_VK_U;
+    VKeyTable['v']  = DOM_VK_V;
+    VKeyTable['w']  = DOM_VK_W;
+    VKeyTable['x']  = DOM_VK_X;
+    VKeyTable['y']  = DOM_VK_Y;
+    VKeyTable['z']  = DOM_VK_Z;
+    VKeyTable['*']  = DOM_VK_MULTIPLY;
+    VKeyTable['+']  = DOM_VK_ADD;
+    VKeyTable['-']  = DOM_VK_SUBTRACT;
+    VKeyTable[',']  = DOM_VK_COMMA;
+    VKeyTable['.']  = DOM_VK_PERIOD;
+    VKeyTable['/']  = DOM_VK_SLASH;
+    VKeyTable['`']  = DOM_VK_BACK_QUOTE;
+    VKeyTable['{']  = DOM_VK_OPEN_BRACKET;
+    VKeyTable['\\'] = DOM_VK_BACK_SLASH;
+    VKeyTable['}']  = DOM_VK_CLOSE_BRACKET;
+    VKeyTable["'"]  = DOM_VK_QUOTE;
+}
+ 
 function getKeyCode(str) {
     str = str.toLowerCase();
     var ret = 0;
@@ -178,6 +232,9 @@
     }
     return root;
 }
+function getVKeyCode(key){
+    return VKeyTable[key.toLowerCase()];
+}
 function feedKeyIntoContent(keys){
     var frameNum = 0;
     [keys, frameNum] = parseKeys(keys);
@@ -186,9 +243,14 @@
     modes.passAllKeys = true;
     modes.passNextKey = false;
     for (var i=0; i<keys.length; i++){
-        var charCode = keys.charCodeAt(i);
-        var keyCode = 0;
-        var shift = false, ctrl = false, alt = false, meta = false;
+        var kc, shift = false, ctrl = false, alt = false, meta = false;
+        if (useVKeys && (kc = getVKeyCode(keys[i]))) {
+            var charCode = 0;
+            var keyCode = kc;
+        } else {
+            var charCode = keys.charCodeAt(i);
+            var keyCode = 0;
+        }
         if (charCode == 60){ // charCode:60 => "<"
             var matches = keys.substr(i + 1).match(/^((?:[ACMSacms]-)*)([^>]+)/);
             if (matches) {
@@ -199,10 +261,18 @@
                     meta  = /[mM]-/.test(matches[1]);
                 }
                 if (matches[2].length == 1) {
-                    if (!ctrl && !alt && !shift && !meta) return false;
-                    charCode = matches[2].charCodeAt(0);
+                    if (!ctrl && !alt && !shift && !meta) return false; 
+                    if (useVKeys) {
+                        keyCode = getVKeyCode(matches[2]);
+                    } else {
+                        charCode = matches[2].charCodeAt(0);
+                    }
                 } else if (matches[2].toLowerCase() == "space") {
-                    charCode = KeyEvent.DOM_VK_SPACE;
+                    if (useVKeys) {
+                        keyCode = KeyEvent.DOM_VK_SPACE;
+                    } else {
+                        charCode = KeyEvent.DOM_VK_SPACE;
+                    }
                 } else if (keyCode = getKeyCode(matches[2])) {
                     charCode = 0;
                 } else  {
@@ -214,6 +284,7 @@
             shift = (keys[i] >= "A" && keys[i] <= "Z");
         }
 
+        //liberator.log({ctrl:ctrl, alt:alt, shift:shift, meta:meta, keyCode:keyCode, charCode:charCode});
         var evt = content.document.createEvent('KeyEvents');
         evt.initKeyEvent('keypress', true, true, content, ctrl, alt, shift, meta, keyCode, charCode);
         destElem.document.dispatchEvent(evt);