vimperator plugin の autoIgnoreKey.js の改良

ページをロードした時と選択した時vimperatorのキーをオフに出来るのは良いけど、逆にオフになった状態から別のタブを選択したときオフのまんまなんだよね、と今更気付いた。

ということで、リストにないURLだった場合にはオンになるように改良。そして、名前も変更。

HOME/vimperator/plugin/autoSwitchKey.js

/**
 * Auto switch vimperator key navigation
 * @author teramako teramako@gmail.com
 * @version 0.3
 */

(function(){
/*
 * String or RegExp
 * e.g)
 *  * /^https?:\/\/mail\.google\.com\//
 *  * 'http://reader.livedoor.com/reader/'
 */
var ignorePageList = [
    /^https?:\/\/mail\.google\.com\//,
    'http://reader.livedoor.com/reader/'
];
document.getElementById('appcontent').addEventListener('DOMContentLoaded',function(event){
    if (event.target.documentURI != gBrowser.currentURI.spec) return;
    if ( isMatch(event.target.documentURI) ){
        vimperator.addMode(null, vimperator.modes.ESCAPE_ALL_KEYS);
    } else {
        vimperator.setMode(vimperator.modes.NORMAL);
    }
},false);
getBrowser().mTabBox.addEventListener('TabSelect',function(event){
    var uri = this.parentNode.currentURI.spec;
    if ( isMatch(uri) ){
        vimperator.addMode(null, vimperator.modes.ESCAPE_ALL_KEYS);
    } else {
        vimperator.setMode(vimperator.modes.NORMAL);
    }
},false);
function isMatch(uri){
    return ignorePageList.some(function(e,i,a){
        if (typeof e == 'string'){
            return uri.indexOf(e) != -1;
        } else if (e instanceof RegExp){
            return e.test(uri);
        }
    });
}
})();

追記(2008/02/11)

バックグラウンドで開いときを考慮して少し変更しました。詳しくはコメント欄をご覧ください。