From ec057accb1ea955d90ded48305569c01d4119041 Mon Sep 17 00:00:00 2001 From: drry Date: Fri, 24 Oct 2008 19:17:41 +0000 Subject: * fixed regexes. * added and fixed dictionaries. * et cetera. git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@22081 d0d07461-0603-4401-acd4-de1884942a52 --- lookupDictionary.js | 66 +++++++++++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 30 deletions(-) (limited to 'lookupDictionary.js') diff --git a/lookupDictionary.js b/lookupDictionary.js index fa6d8d0..050f353 100644 --- a/lookupDictionary.js +++ b/lookupDictionary.js @@ -7,33 +7,39 @@ * @version 0.3 * ==/VimperatorPlugin== */ -(function(){ +(function () { const SITE_DEFINITION = [{ names: ['eiji[ro]'], url: 'http://eow.alc.co.jp/%s/UTF-8/', shortHelp: 'SPACE ALC (英辞郎 on the Web)', xpath: 'id("resultList")', - dictionary: 'en-US', + dictionary: 'en-US' },{ - names: ['goo'], + names: ['goo[dictionary]'], url: 'http://dictionary.goo.ne.jp/search.php?MT=%s&kind=all&mode=0&IE=UTF-8', shortHelp: 'goo 辞書', xpath: 'id("incontents")/*[@class="ch04" or @class="fs14" or contains(@class,"diclst")]', multi: true, - dictionary: 'en-US', + dictionary: 'en-US' },{ names: ['answers'], url: 'http://www.answers.com/%s', shortHelp: 'Answers.com(英英辞書)', xpath: 'id("firstDs")', - dictionary: 'en-US', + dictionary: 'en-US' },{ - names: ['wikipe[dia]'], + names: ['wikipe[diaja]'], url: 'http://ja.wikipedia.org/wiki/%s', - shortHelp: 'Wikipedia(ja) lite', + shortHelp: 'ウィキペディア lite', xpath: 'id("bodyContent")/p[1]', - dictionary: 'en-US', + dictionary: 'ja' +},{ + names: ['wikipe[diaen]'], + url: 'http://en.wikipedia.org/wiki/%s', + shortHelp: 'Wikipedia lite', + xpath: 'id("bodyContent")/p[1]', + dictionary: 'en' }]; let (siteDef = liberator.globalVariables.lookupDictionary_site_definition) { @@ -90,8 +96,8 @@ SpellChecker.prototype = { * @param {String} dict */ setDictionary: function (dict) { - var dictionaries = this.getDictionaryList() - for (var i=0, max=dictionaries.length ; i' + xs.serializeToString( result ).replace(/<\/?[^>]+>/g,function(all) all.toLowerCase() ) + ''), true); + liberator.echo(new XMLList('
' + xs.serializeToString( result ).replace(/<[^>]+>/g,function (all) all.toLowerCase() ) + '
'), true); }, dictionary.encode ? dictionary.encode : null); }, { @@ -176,7 +182,7 @@ SITE_DEFINITION.forEach(function(dictionary){ var suggestions = spellChecker.suggest(arg); var candidates = []; - for (var i=0, max=suggestions.length ; i]+?)?>|<\/html\s*>[\S\s]*$/ig,'').replace(/[\r\n]+/g,' '); +function createHTMLDocument(str) { + str = str.replace(/^[\s\S]*?]*)?>[ \t\n\r]*|[ \t\n\r]*<\/html[ \t\r\n]*>[\S\s]*$/ig,'').replace(/[\r\n]+/g,' '); var htmlFragment = content.document.implementation.createDocument(null,'html',null); var range = content.document.createRange(); range.setStartAfter(window.content.document.body); @@ -233,16 +239,16 @@ function createHTMLDocument(str){ * @param {Boolean} isMulti * @return {Element} */ -function getNodeFromXPath(xpath,doc,isMulti){ +function getNodeFromXPath(xpath,doc,isMulti) { if (!xpath || !doc) return; var result; - if (isMulti){ - var nodesSnapshot = doc.evaluate(xpath,doc.documentElement,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null); + if (isMulti) { + let nodesSnapshot = doc.evaluate(xpath,doc.documentElement,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null); if (nodesSnapshot.snapshotLength == 0) return; result = document.createElementNS(null,'div'); - for (var i=0; i