Changeset 34082

Show
Ignore:
Timestamp:
06/21/09 21:43:33 (4 years ago)
Author:
drry
Message:
  • HTTP URL の判定を修正しました。
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/vimperator-plugins/trunk/account_switcher.js

    r34051 r34082  
    66 * @minVersion     2.1a1pre 
    77 * @author         masa138 
    8  * @version        0.0.4 
     8 * @version        0.0.5 
    99 * ==/VimperatorPlugin== 
    1010 * 
     
    2626    var afterSLine = targetElem.nextSibling; 
    2727    var sbPannel   = document.createElementNS(ns, 'statusbarpannel'); 
     28    var img        = sbPannel.appendChild(document.createElementNS(ns, 'image')); 
    2829    sbPannel.id    = 'account-switcher-pannel'; 
    29     var img        = document.createElementNS(ns, 'image'); 
    30     sbPannel.appendChild(img); 
    3130 
    3231    var _services = { 
     
    8988 
    9089    function changeAccount(user) { 
     90        var service = services[accounts[user].host]; 
     91        if (service.host == null || service.logout == null) return; 
     92 
    9193        var username = accounts[user].username; 
    9294        var password = accounts[user].password; 
    93         var service  = services[accounts[user].host]; 
    94  
    9595        var req = new XMLHttpRequest(); 
    96         if (service.host   == null) return; 
    97         if (service.logout == null) return; 
    98         var url = (service.logout.indexOf('http') == -1) ? service.host + service.logout : service.logout; 
     96        var url = (service.logout.indexOf('http') != 0) ? service.host + service.logout : service.logout; 
    9997        req.open("POST", url, true); 
    10098        req.onload = function(e) { 
     99            if (service.login == null || service.id == null || service.pw == null) return; 
    101100            var req = new XMLHttpRequest(); 
    102             if (service.login == null) return; 
    103             var url = (service.login.indexOf('http') == -1) ? service.host + service.login : service.login; 
     101            var url = (service.login.indexOf('http') != 0) ? service.host + service.login : service.login; 
    104102            req.open("POST", url, true); 
    105103            req.onload = function(e) { 
     
    110108                    content.location.reload(); 
    111109                } 
    112                 if (service.host.match(/hatena\.ne\.jp/)) { 
     110                var needle = '.hatena.ne.jp'; 
     111                if (service.host.toLowerCase().lastIndexOf(needle) == service.host.length - needle.length) { 
    113112                    img.setAttribute('src', 'http://www.hatena.ne.jp/users/' + username.substr(0, 2) + '/' + username + '/profile_s.gif'); 
    114113                    if (!document.getElementById('account_switcher_pannel')) { 
     
    120119                    } 
    121120                } 
    122             } 
    123             req.onerror = function(e) { liberator.echoerr('Login error in account_switcher.js'); } 
     121            }; 
     122            req.onerror = function(e) { liberator.echoerr('Login error in account_switcher.js'); }; 
    124123            req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
    125             if (service.id == null || service.pw == null) return; 
    126124            req.send( 
    127125                service.id + '=' + encodeURIComponent(username) + '&' + 
     
    129127            ); 
    130128            nowLogin[user.substr(user.lastIndexOf('@') + 1)] = user; 
    131         } 
    132         req.onerror = function(e) { liberator.echoerr('Logout error in account_switcher.js'); } 
     129        }; 
     130        req.onerror = function(e) { liberator.echoerr('Logout error in account_switcher.js'); }; 
    133131        req.send(null); 
    134132    } 
     
    136134    commands.addUserCommand(["account"], "Change Account", 
    137135        function(args) { 
    138             if ( !args ) { 
     136            if (!args) { 
    139137                liberator.echo("Usage: account {username}@{servicename}"); 
    140138            } else { 
     
    156154                        var user = args[i]; 
    157155                        if (user != '') { 
    158                             compls = compls.filter(function(c) { return c[0].indexOf(user) != -1 }); 
     156                            compls = compls.filter(function(c) c[0].indexOf(user) != -1); 
    159157                        } 
    160158                    }