From bf93ae876f4180612fc0d8e1e4d306938567e04a Mon Sep 17 00:00:00 2001 From: suVene Date: Fri, 28 Nov 2008 22:00:13 +0000 Subject: *引数のサイトをカンマ区切りで同時に指定できるように対応 ex.) :mr alc,goo ANY_TEXT → 英辞朗とgoo辞書を同時に検索 git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@25308 d0d07461-0603-4401-acd4-de1884942a52 --- multi_requester.js | 144 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 81 insertions(+), 63 deletions(-) (limited to 'multi_requester.js') diff --git a/multi_requester.js b/multi_requester.js index fdd6994..6096c9d 100644 --- a/multi_requester.js +++ b/multi_requester.js @@ -4,9 +4,10 @@ * @description request, and the result is displayed to the buffer. * @description-ja リクエストの結果をバッファに出力する。 * @author suVene suvene@zeromemory.info - * @version 0.2.4 + * @version 0.3.0 * @minVersion 2.0pre * @maxVersion 2.0pre + * Last Change: 29-Nov-2008. * ==/VimperatorPlugin== * * Usage: @@ -15,9 +16,11 @@ * ! create new tab. * ANY_TEXT your input text * - * :mr alc ANY_TEXT -> request by the input text, and display to the buffer. - * :mr! goo {window.selection} -> request by the selected text, and display to the new tab. + * :mr alc[,goo,any1,any2…] ANY_TEXT -> request by the input text, and display to the buffer. + * :mr! goo[,any1,any2,…] {window.selection} -> request by the selected text, and display to the new tab. * + * other siteinfo by wedata. + * @see http://wedata.net/databases/Multi%20Requester/items * * CUSTOMIZE .vimperatorrc: * @@ -42,9 +45,6 @@ * ]; * EOM * - * other siteinfo by wedata. - * @see http://wedata.net/databases/Multi%20Requester/items - * * [MAPPINGS] * ex.) * javascript < -1 && !parsedArgs.str) return; - - // via. lookupDictionary.js - var ttbu = Components.classes['@mozilla.org/intl/texttosuburi;1'] - .getService(Components.interfaces.nsITextToSubURI); - url = url.replace(/%s/g, ttbu.ConvertAndEscape(urlEncode, parsedArgs.str)); - $U.log(url + '::' + siteinfo.xpath); - - if (special) { - liberator.open(url, liberator.NEW_TAB); - } else { - let req = new Request(url, null, { - encoding: srcEncode, - siteinfo: siteinfo, - args: { - args: args, - special: special, - count: count - } - }); - req.addEventListener('onException', $U.bind(this, this.onException)); - req.addEventListener('onSuccess', $U.bind(this, this.onSuccess)); - req.addEventListener('onFailure', $U.bind(this, this.onFailure)); - req.get(); + for (let i = 0, len = parsedArgs.count; i < len; i++) { - $U.echo('Loading ' + parsedArgs.name + ' ...', commandline.FORCE_SINGLELINE); - } + let info = siteinfo[i]; + var url = info.url; + // see: http://fifnel.com/2008/11/14/1980/ + var srcEncode = info.srcEncode || 'UTF-8'; + var urlEncode = info.urlEncode || srcEncode; + + var idxRepStr = url.indexOf('%s'); + if (idxRepStr > -1 && !parsedArgs.str) continue; + + // via. lookupDictionary.js + var ttbu = Components.classes['@mozilla.org/intl/texttosuburi;1'] + .getService(Components.interfaces.nsITextToSubURI); + url = url.replace(/%s/g, ttbu.ConvertAndEscape(urlEncode, parsedArgs.str)); + $U.log(url + '[' + srcEncode + '][' + urlEncode + ']::' + info.xpath); + + if (bang) { + liberator.open(url, liberator.NEW_TAB); + } else { + let req = new Request(url, null, { + encoding: srcEncode, + siteinfo: info, + args: { + args: args, + bang: bang, + count: count + } + }); + req.addEventListener('onException', $U.bind(this, this.onException)); + req.addEventListener('onSuccess', $U.bind(this, this.onSuccess)); + req.addEventListener('onFailure', $U.bind(this, this.onFailure)); + req.get(); + } + $U.echo('Loading ' + parsedArgs.names + ' ...', commandline.FORCE_SINGLELINE); + } }, - // return {name: '', siteinfo: {}, str: ''} or null + // return {names: '', str: '', count: 0, siteinfo: [{}]} parseArgs: function(args) { - if (!args) return null; + var self = this; + var ret = {}; + ret.names = ''; + ret.str = ''; + ret.count = 0; + ret.siteinfo = []; + + if (!args) return ret; var arguments = args.split(/ +/); var sel = $U.getSelectedString(); - if (arguments.length < 1) return null; + if (arguments.length < 1) return ret; + + ret.names = arguments.shift(); + ret.str = (arguments.length < 1 ? sel : arguments.join()).replace(/[\n\r]+/g, ''); - var siteName = arguments.shift(); - var str = (arguments.length < 1 ? sel : arguments.join()).replace(/[\n\r]+/g, ''); - var siteinfo = this.getSite(siteName); + ret.names.split(',').forEach(function(name) { + let site = self.getSite(name); + if (site) { + ret.count++; + ret.siteinfo.push(site); + } + }); - return {name: siteName, siteinfo: siteinfo, str: str}; + return ret; }, getSite: function(name) { if (!name) this.siteinfo[0]; @@ -539,6 +556,7 @@ var MultiRequester = { onSuccess: function(res) { var url, escapedUrl, xpath, doc, html; + $U.debug('success!!!' + res.request.url); try { -- cgit v1.2.3