Changeset 24339

Show
Ignore:
Timestamp:
11/19/08 22:41:15 (5 years ago)
Author:
drry
Message:
  • fixed a regex.
  • et cetera.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/vimperator-plugins/branches/1.2/multi_requester.js

    r24329 r24339  
    4545 *   EOM 
    4646 * 
    47  *   other siteinfo by Wedata. 
     47 *   other siteinfo by wedata. 
    4848 *     @see http://wedata.net/databases/Multi%20Requester/items 
    4949 * 
     
    5454 *       [',ml', 'ex'],                  // == :mr  ex 
    5555 *       [',mg', 'goo', '!'],            // == :mr! goo 
    56  *       [',ma', 'alc',    , 'args'],    // == :mr  alc args (however, it use a selected_text with precedence.) 
     56 *       [',ma', 'alc',    , 'args'],    // == :mr  alc args (however, it uses a selected_text with precedence.) 
    5757 *   ]; 
    5858 *   EOM 
    5959 * 
    6060 * [OTHER OPTIONS] 
    61  *   let g:multi_requester_use_wedata = "false"             // default true 
     61 *   let g:multi_requester_use_wedata = "false"             // true by default 
    6262 * 
    6363 * 
    6464 * TODO: 
    65  *    - Wedata からのデータ取得を非同期に。 
    66  *    - Wedata local cache. 
     65 *    - wedata からのデータ取得を非同期に。 
     66 *    - wedata local cache. 
    6767 *    - 複数リクエスト対応。 
    6868 */ 
     
    124124    eval: function(text) { 
    125125        var fnc = window.eval; 
     126        var sandbox; 
    126127        try { 
    127             var sandbox = new Components.utils.Sandbox(window); 
     128            sandbox = new Components.utils.Sandbox(window); 
    128129            if (Components.utils.evalInSandbox("true", sandbox) === true) { 
    129                 fnc = function(text) { return Components.utils.evalInSandbox(text, sandbox); } 
     130                fnc = function(text) { return Components.utils.evalInSandbox(text, sandbox); }; 
    130131            } 
    131         } catch(e) { $U.log('warning: multi_requester.js is working with unsafe sandbox.'); } 
     132        } catch (e) { $U.log('warning: multi_requester.js is working with unsafe sandbox.'); } 
    132133 
    133134        return fnc(text); 
    134135    }, 
    135136    // via. sbmcommentsviwer.js 
    136     evalJson: function(str, toRemove){ 
     137    evalJson: function(str, toRemove) { 
     138        var json; 
    137139        try { 
    138             var json = Components.classes['@mozilla.org/dom/json;1'].getService(Components.interfaces.nsIJSON); 
     140            json = Components.classes['@mozilla.org/dom/json;1'].getService(Components.interfaces.nsIJSON); 
    139141            if (toRemove) str = str.substring(1, str.length - 1); 
    140142            return json.decode(str); 
     
    416418        if (useWedata) { 
    417419            $U.log('use Wedata'); 
    418             this.getWeData(function(site) { 
     420            this.getWedata(function(site) { 
    419421                if (!ret[site.name]) ret[site.name] = {}; 
    420422                $U.extend(ret[site.name], site); 
     
    440442        return result; 
    441443    }, 
    442     getWeData: function(func) { 
     444    getWedata: function(func) { 
    443445        var req = new Request( 
    444446            'http://wedata.net/databases/Multi%20Requester/items.json', 
     
    506508 
    507509        var isOptS = args.hasOwnProperty('-s'); 
    508         if ((isOptS && args.arguments.length < 1) && args.arguments.length < 2) return null; 
     510        if (isOptS && args.arguments.length < 1 && args.arguments.length < 2) return null; 
    509511 
    510512        var siteName = args.arguments.shift(); 
    511         var str = (isOptS ? $U.getSelectedString() : args.arguments.join()).replace(/[\n\r]/g, ''); 
     513        var str = (isOptS ? $U.getSelectedString() : args.arguments.join()).replace(/[\n\r]+/g, ''); 
    512514        var siteinfo = this.getSite(siteName); 
    513515 
     
    523525    }, 
    524526    onSuccess: function(res) { 
    525           
     527        var url, escapedUrl, xpath, doc, html; 
     528 
    526529        try { 
    527               
     530 
    528531            if (!res.isSuccess || res.responseText == '') throw 'response is fail or null'; 
    529532 
    530             var url = res.request.url; 
    531             var escapedUrl = liberator.util.escapeHTML(url); 
    532             var xpath = res.request.options.siteinfo.resultXpath; 
    533             var doc = res.getHTMLDocument(xpath); 
    534             if (!doc) throw 'xpath result is undefined or null.: xpath -> ' + xpath; 
    535                       
    536             var html = '<div style="white-space:normal;"><base href="' + escapedUrl + '" />' + 
    537                        '<a href="' + escapedUrl + '" class="hl-Title" target="_self">' + escapedUrl + '</a>' + 
    538                        (new XMLSerializer()).serializeToString(doc).replace(/<[^>]+>/g, function(all) all.toLowerCase()) + 
    539                        '</div>'; 
     533            url = res.request.url; 
     534            escapedUrl = liberator.util.escapeHTML(url); 
     535            xpath = res.request.options.siteinfo.resultXpath; 
     536            doc = res.getHTMLDocument(xpath); 
     537            if (!doc) throw 'XPath result is undefined or null.: XPath -> ' + xpath; 
     538 
     539            html = '<div style="white-space:normal;"><base href="' + escapedUrl + '"/>' + 
     540                   '<a href="' + escapedUrl + '" class="hl-Title" target="_self">' + escapedUrl + '</a>' + 
     541                   (new XMLSerializer()).serializeToString(doc).replace(/<[^>]+>/g, function(all) all.toLowerCase()) + 
     542                   '</div>'; 
    540543            $U.echo(new XMLList(html)); 
    541               
     544 
    542545        } catch (e) { 
    543546            $U.echoerr('error!!: ' + e);