Changeset 27108
- Timestamp:
- 12/20/08 03:24:47 (4 years ago)
- Location:
- lang/javascript/vimperator-plugins
- Files:
-
- 3 modified
-
branches/1.2/multi_requester.js (modified) (4 diffs)
-
trunk/_libly.js (modified) (10 diffs)
-
trunk/multi_requester.js (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/javascript/vimperator-plugins/branches/1.2/multi_requester.js
r26980 r27108 6 6 <description lang="ja">リクエストの結果をバッファに出力する。</description> 7 7 <author mail="suvene@zeromemory.info" homepage="http://zeromemory.sblo.jp/">suVene</author> 8 <version>0.4. 4</version>8 <version>0.4.6</version> 9 9 <minVersion>1.2</minVersion> 10 10 <maxVersion>1.2</maxVersion> 11 11 <detail><![CDATA[ 12 12 == Needs Library == 13 - _libly.js(ver.0.1. 4)13 - _libly.js(ver.0.1.11) 14 14 @see http://coderepos.org/share/browser/lang/javascript/vimperator-plugins/trunk/_libly.js 15 15 … … 346 346 var el = res.getHTMLDocument(extractLink); 347 347 if (!el) throw 'extract link failed.: extractLink -> ' + extractLink; 348 var url = $U.pathToURL(el[0] );348 var url = $U.pathToURL(el[0], res.req.url); 349 349 var req = new libly.Request(url, null, $U.extend(res.req.options, {extractLink: true})); 350 350 req.addEventListener('onException', $U.bind(this, this.onException)); … … 369 369 } 370 370 371 var url, escapedUrl, xpath, doc, html, extractLink ;371 var url, escapedUrl, xpath, doc, html, extractLink, ignoreTags; 372 372 373 373 try { … … 384 384 return; 385 385 } 386 varignoreTags = ['script'].concat(libly.$U.A(res.req.options.siteinfo.ignoreTags));386 ignoreTags = ['script'].concat(libly.$U.A(res.req.options.siteinfo.ignoreTags)); 387 387 doc = document.createElementNS(null, 'div'); 388 res.getHTMLDocument(xpath, null, ignoreTags, function(node, i) { doc.appendChild(node) } ); 388 res.getHTMLDocument(xpath, null, ignoreTags, function(node, i) { 389 if (node.tagName.toLowerCase() != 'html') 390 doc.appendChild(node); 391 }); 389 392 if (!doc) throw 'XPath result is undefined or null.: XPath -> ' + xpath; 393 394 $U.getNodesFromXPath('descendant-or-self::a | descendant-or-self::img', doc, function(node) { 395 var tagName = node.tagName.toLowerCase(); 396 if (tagName == 'a') { 397 node.href = $U.pathToURL(node, url, res.doc); 398 } else if (tagName == 'img') { 399 node.src = $U.pathToURL(node, url, res.doc); 400 } 401 }); 390 402 391 403 html = '<a href="' + escapedUrl + '" class="hl-Title" target="_self">' + escapedUrl + '</a>' + -
lang/javascript/vimperator-plugins/trunk/_libly.js
r26826 r27108 6 6 <description lang="ja">適当なライブラリっぽいものたち。</description> 7 7 <author mail="suvene@zeromemory.info" homepage="http://zeromemory.sblo.jp/">suVene</author> 8 <version>0.1.1 0</version>8 <version>0.1.11</version> 9 9 <minVersion>1.2</minVersion> 10 10 <maxVersion>2.0pre</maxVersion> … … 55 55 56 56 == HTML, XML, DOM, E4X == 57 pathToURL( path):57 pathToURL(a, baseURL, doc): 58 58 相対パスを絶対パスに変換します。 59 59 getHTMLFragment(html): … … 63 63 str から tags で指定されたタグを取り除いて返却します。 64 64 tags は文字列、または配列で指定して下さい。 65 createHTMLDocument(str ):65 createHTMLDocument(str, xmlns): 66 66 引数 str より、HTMLFragment を作成します。 67 67 getFirstNodeFromXPath(xpath, context): 68 68 xpath を評価しオブジェクトをを返却します。 69 getNodesFromXPath(xpath, context, callback, obj):69 getNodesFromXPath(xpath, context, callback, thisObj): 70 70 xpath を評価し snapshot の配列を返却します。 71 71 xmlSerialize(xml): … … 80 80 </VimperatorPlugin>; 81 81 //}}} 82 if (!liberator.plugins.libly) {82 //if (!liberator.plugins.libly) { 83 83 84 84 liberator.plugins.libly = {}; … … 215 215 // }}} 216 216 // HTML, XML, DOM, E4X {{{ 217 pathToURL: function(a, doc) {217 pathToURL: function(a, baseURL, doc) { 218 218 if (!a) return ''; 219 var path = (a.href || a.action || a.value || a); 219 var XHTML_NS = "http://www.w3.org/1999/xhtml" 220 var XML_NS = "http://www.w3.org/XML/1998/namespace" 221 //var path = (a.href || a.getAttribute('src') || a.action || a.value || a); 222 var path = (a.getAttribute('href') || a.getAttribute('src') || a.action || a.value || a); 220 223 if (/^https?:\/\//.test(path)) return path; 221 var link = (doc || window.content.documtent).createElement('a'); 222 link.href = path; 224 var link = (doc || window.content.documtent).createElementNS(XHTML_NS, 'a'); 225 link.setAttributeNS(XML_NS, 'xml:base', baseURL) 226 link.href = path 223 227 return link.href; 224 228 }, … … 231 235 return str.replace(new RegExp('<' + ignoreTags + '(?:[ \\t\\n\\r][^>]*|/)?>([\\S\\s]*?)<\/' + ignoreTags + '[ \\t\\r\\n]*>', 'ig'), ''); 232 236 }, 233 createHTMLDocument: function(str, doc) {237 createHTMLDocument: function(str, xmlns, doc) { 234 238 doc = doc || window.content.document; 235 239 var htmlFragment = doc.implementation.createDocument(null, 'html', null); … … 245 249 return result.singleNodeValue ? result.singleNodeValue : null; 246 250 }, 247 getNodesFromXPath: function(xpath, context, callback, obj) {251 getNodesFromXPath: function(xpath, context, callback, thisObj) { 248 252 var ret = []; 249 253 if (!xpath) return ret; … … 251 255 var nodesSnapshot = (context.ownerDocument || context).evaluate(xpath, context, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 252 256 for (let i = 0, l = nodesSnapshot.snapshotLength; i < l; i++) { 253 if (typeof callback == 'function') callback.call( obj, nodesSnapshot.snapshotItem(i), i);257 if (typeof callback == 'function') callback.call(thisObj, nodesSnapshot.snapshotItem(i), i); 254 258 ret.push(nodesSnapshot.snapshotItem(i)); 255 259 } … … 443 447 } catch (e) { return ''; } 444 448 }, 445 getHTMLDocument: function(xpath, xmlns, ignoreTags, callback ) {449 getHTMLDocument: function(xpath, xmlns, ignoreTags, callback, thisObj) { 446 450 if (!this.doc) { 451 //if (doc.documentElement.nodeName != 'HTML') { 452 // return new DOMParser().parseFromString(str, 'application/xhtml+xml'); 453 //} 447 454 this.htmlFragmentstr = libly.$U.getHTMLFragment(this.responseText); 448 455 this.htmlStripScriptFragmentstr = libly.$U.stripTags(this.htmlFragmentstr, ignoreTags); … … 450 457 } 451 458 if (!xpath) xpath = '//*'; 452 return libly.$U.getNodesFromXPath(xpath, this.doc, callback );459 return libly.$U.getNodesFromXPath(xpath, this.doc, callback, thisObj); 453 460 } 454 461 }; 455 462 //}}} 456 463 457 }464 //} 458 465 // vim: set fdm=marker sw=4 ts=4 sts=0 et: 459 466 -
lang/javascript/vimperator-plugins/trunk/multi_requester.js
r26980 r27108 6 6 <description lang="ja">リクエストの結果をバッファに出力する。</description> 7 7 <author mail="suvene@zeromemory.info" homepage="http://zeromemory.sblo.jp/">suVene</author> 8 <version>0.4. 5</version>8 <version>0.4.6</version> 9 9 <minVersion>2.0pre</minVersion> 10 10 <maxVersion>2.0pre</maxVersion> 11 11 <detail><![CDATA[ 12 12 == Needs Library == 13 - _libly.js(ver.0.1. 4)13 - _libly.js(ver.0.1.11) 14 14 @see http://coderepos.org/share/browser/lang/javascript/vimperator-plugins/trunk/_libly.js 15 15 … … 350 350 var el = res.getHTMLDocument(extractLink); 351 351 if (!el) throw 'extract link failed.: extractLink -> ' + extractLink; 352 var url = $U.pathToURL(el[0] );352 var url = $U.pathToURL(el[0], res.req.url); 353 353 var req = new libly.Request(url, null, $U.extend(res.req.options, {extractLink: true})); 354 354 req.addEventListener('onException', $U.bind(this, this.onException)); … … 373 373 } 374 374 375 var url, escapedUrl, xpath, doc, html, extractLink ;375 var url, escapedUrl, xpath, doc, html, extractLink, ignoreTags; 376 376 377 377 try { … … 388 388 return; 389 389 } 390 varignoreTags = ['script'].concat(libly.$U.A(res.req.options.siteinfo.ignoreTags));390 ignoreTags = ['script'].concat(libly.$U.A(res.req.options.siteinfo.ignoreTags)); 391 391 doc = document.createElementNS(null, 'div'); 392 res.getHTMLDocument(xpath, null, ignoreTags, function(node, i) { doc.appendChild(node) } ); 392 res.getHTMLDocument(xpath, null, ignoreTags, function(node, i) { 393 if (node.tagName.toLowerCase() != 'html') 394 doc.appendChild(node); 395 }); 393 396 if (!doc) throw 'XPath result is undefined or null.: XPath -> ' + xpath; 397 398 $U.getNodesFromXPath('descendant-or-self::a | descendant-or-self::img', doc, function(node) { 399 var tagName = node.tagName.toLowerCase(); 400 if (tagName == 'a') { 401 node.href = $U.pathToURL(node, url, res.doc); 402 } else if (tagName == 'img') { 403 node.src = $U.pathToURL(node, url, res.doc); 404 } 405 }); 394 406 395 407 html = '<a href="' + escapedUrl + '" class="hl-Title" target="_self">' + escapedUrl + '</a>' +
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)