From 0d19a1e18f331d8a73a34839947209d1c58949b9 Mon Sep 17 00:00:00 2001
From: trapezoid
Date: Fri, 21 Mar 2008 01:50:19 +0000
Subject: lang/javascript/vimperator-plugins/lookupDictionary.js: 0.6pre対応版
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@8233 d0d07461-0603-4401-acd4-de1884942a52
---
lookupDictionary.js | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 110 insertions(+)
create mode 100755 lookupDictionary.js
(limited to 'lookupDictionary.js')
diff --git a/lookupDictionary.js b/lookupDictionary.js
new file mode 100755
index 0000000..fd27d85
--- /dev/null
+++ b/lookupDictionary.js
@@ -0,0 +1,110 @@
+/**
+ * lookup dictionary (vimperator plugin)
+ * For vimperator 0.5.3
+ * @author teramako teramako@gmail.com
+ * @version 0.1
+ *
+ * Lookup web dictionary
+ * And show the result in the bottom of the window
+ */
+(function(){
+const dictionalyList = [
+ {
+ names: ['eiji[ro]'],
+ url: 'http://eow.alc.co.jp/%s/UTF-8/',
+ shortHelp: '英辞郎',
+ xpath: '//*[@id="resultList"]'
+ },{
+ names: ['goo'],
+ url: 'http://dictionary.goo.ne.jp/search.php?MT=%s&kind=all&mode=0',
+ shortHelp: 'goo辞書',
+ encode: 'EUC-JP',
+ xpath: '//div[@id="incontents"]/*[@class="ch04" or @class="fs14" or contains(@class,"diclst")]',
+ multi: true
+ }
+];
+for (var i=0; i' + xs.serializeToString( result ), true);
+ });
+ },{}
+ );
+}
+/**
+ * @param {String} url
+ * @param {Function} callback
+ */
+function getHTML(url, callback){
+ var xhr= new XMLHttpRequest();
+ xhr.onreadystatechange = function(){
+ if (xhr.readyState == 4){
+ if (xhr.status == 200){
+ callback.call(this,xhr.responseText);
+ } else {
+ throw new Error(xhr.statusText);
+ }
+ }
+ };
+ xhr.open('GET',url,true);
+ xhr.send(null);
+}
+/**
+ * @param {String} str
+ * @return {DOMDocument}
+ */
+function createHTMLDocument(str){
+ str = str.replace(/^[\s\S]*?]*>|[\r\n]+|<\/html\s*>[\s\S]*$/ig, '');
+ var htmlFragment = document.implementation.createDocument(null,'html',null);
+ var range = document.createRange();
+ range.setStartAfter(window.content.document.body);
+ htmlFragment.documentElement.appendChild(htmlFragment.importNode(range.createContextualFragment(str),true));
+ return htmlFragment;
+}
+/**
+ * @param {String} xpath XPath Expression
+ * @param {DOMDocument} doc
+ * @param {Boolean} isMulti
+ * @return {Element}
+ */
+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 (nodesSnapshot.snapshotLength == 0) return;
+ result = document.createElementNS(null,'div');
+ for (var i=0; i