/** * ==VimperatorPlugin== * @name lookup dictionary (Vimperator plugin) * @description Lookup words from Web dictionaries, and show the results in the bottom of the window * @description-ja Web上の辞書を引いた結果をコマンドライン・バッファへ出力します * @author teramako teramako@gmail.com * @version 0.3 * ==/VimperatorPlugin== */ (function () { const SITE_DEFINITION = [{ names: ['eiji[ro]'], url: 'http://eow.alc.co.jp/%s/UTF-8/', shortHelp: 'SPACE ALC (\u82F1\u8F9E\u6717 on the Web)', xpath: 'id("resultsList")', dictionary: 'en-US' },{ names: ['goo[dictionary]'], url: 'http://dictionary.goo.ne.jp/search.php?MT=%s&kind=all&mode=0&IE=UTF-8', shortHelp: 'goo \u8F9E\u66F8', xpath: 'id("incontents")/*[@class="ch04" or @class="fs14" or contains(@class,"diclst")]', multi: true, dictionary: 'en-US', srcEncode: 'EUC-jp', urlEncode: 'UTF-8' },{ names: ['answers'], url: 'http://www.answers.com/%s', shortHelp: 'Answers.com(\u82F1\u82F1\u8F9E\u66F8)', xpath: 'id("firstDs")', dictionary: 'en-US' },{ names: ['wikipe[diaja]'], url: 'http://ja.wikipedia.org/wiki/%s', shortHelp: 'Wikipedia lite(ja)', xpath: 'id("bodyContent")/p[1]', dictionary: 'ja' },{ names: ['wikipe[diaen]'], url: 'http://en.wikipedia.org/wiki/%s', shortHelp: 'Wikipedia lite(en)', xpath: 'id("bodyContent")/p[1]', dictionary: 'en' }]; let (siteDef = liberator.globalVariables.lookupDictionary_site_definition) { if (siteDef) { if (siteDef instanceof String) siteDef = eval(siteDef); if (siteDef.forEach instanceof Function) siteDef.forEach(function (obj) { SITE_DEFINITION.push(obj); }); else SITE_DEFINITION.push(siteDef); } } // class definition function SpellChecker() { this.initialize.apply(this, arguments); } SpellChecker.prototype = { initialize: function () { const MYSPELL = "@mozilla.org/spellchecker/myspell;1"; const HUNSPELL = "@mozilla.org/spellchecker/hunspell;1"; const ENGINE = "@mozilla.org/spellchecker/engine;1"; var spellclass = MYSPELL; if (HUNSPELL in Components.classes) spellclass = HUNSPELL; if (ENGINE in Components.classes) spellclass = ENGINE; this.engine = Components.classes[spellclass] .createInstance(Components.interfaces.mozISpellCheckingEngine); }, /** * @return {Array} */ getDictionaryList: function () { var dictionaries = {}; this.engine.getDictionaryList(dictionaries, {}); return dictionaries.value; }, /** * @return {String} */ dictionary: function () { var dict; try { dict = this.engine.dictionary; } catch (e) {} return dict ? dict : null; }, /** * @param {String} dict */ setDictionary: function (dict) { var dictionaries = this.getDictionaryList(); for (let i=0, max=dictionaries.length ; i' + xs.serializeToString( result ).replace(/<[^>]+>/g,function (all) all.toLowerCase() ) + ''), true); }, dictionary.srcEncode ? dictionary.srcEncode : null); }, { completer: function (arg) { if (!spellChecker || !dictionary.dictionary || !spellChecker.setDictionary(dictionary.dictionary)) return [0, []]; var suggestions = spellChecker.suggest(arg); var candidates = []; for (let i=0, max=suggestions.length ; i('^.{0,'+(n-1)+'}$'),function(s)lz('0'+s,n)); function dateTime () { with (new Date()) return lz(getFullYear(), 4) + '/' + lz(getMonth() + 1, 2) + '/' + lz(getDate(), 2) + ' ' + lz(getHours(), 2) + ':' + lz(getMinutes(), 2); } function filepath () { let result = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile); result.initWithPath(localfilepath); return result; } function puts (line) { line = dateTime() + "\t" + line + "\n"; let out = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream); let conv = Cc['@mozilla.org/intl/converter-output-stream;1']. createInstance(Ci.nsIConverterOutputStream); out.init(filepath(), 0x02 | 0x10 | 0x08, 0664, 0); conv.init(out, charset, line.length, Components.interfaces.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER); conv.writeString(line); conv.close(); out.close(); } function gets () { let file = Cc['@mozilla.org/network/file-input-stream;1'].createInstance(Ci.nsIFileInputStream); file.init(filepath(), 1, 0, false); let conv = Cc['@mozilla.org/intl/converter-input-stream;1'].createInstance(Ci.nsIConverterInputStream); conv.init(file, charset, file.available(), conv.DEFAULT_REPLACEMENT_CHARACTER); let result = {}; conv.readString(file.available(), result); conv.close(); file.close(); return result.value; } commands.addUserCommand( ['memo'], 'Write memo', function (arg) { if (arg.string) { puts(arg.string); } else { liberator.echo(gets()); } } ); })();