Changeset 25714
- Timestamp:
- 12/02/08 23:47:13 (7 months ago)
- Location:
- lang/javascript/vimperator-plugins
- Files:
-
- 2 modified
-
branches/1.2/multi_requester.js (modified) (16 diffs)
-
trunk/multi_requester.js (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/javascript/vimperator-plugins/branches/1.2/multi_requester.js
r25648 r25714 5 5 * @description-ja リクエストの結果をバッファに出力する。 6 6 * @author suVene suvene@zeromemory.info 7 * @version 0.4. 07 * @version 0.4.1 8 8 * @minVersion 1.2 9 9 * @maxVersion 1.2 10 * Last Change: 0 1-Dec-2008.10 * Last Change: 02-Dec-2008. 11 11 * ==/VimperatorPlugin== 12 12 * … … 36 36 * liberator.globalVariables.multi_requester_siteinfo = [ 37 37 * { 38 * name: 'ex', // required 39 * description: 'example', // required 40 * url: 'http://example.com/?%s', // required, %s <-- replace string 41 * xpath: '//*', // optional(default all) 42 * srcEncode: 'SHIFT_JIS', // optional(default UTF-8) 43 * urlEncode: 'SHIFT_JIS', // optional(default srcEncode) 44 * ignoreTags: 'img' // optional(default script), syntax 'tag1,tag2,……' 45 * extractLink: '//xpath' // optional extract permalink' 38 * map: ',me', // optional: keymap for this siteinfo call 39 * bang: true, // optional: 40 * args: 'any' // optional: 41 * name: 'ex', // required: subcommand name 42 * description: 'example', // required: commandline short help 43 * url: 'http://example.com/?%s', // required: %s <-- replace string 44 * xpath: '//*', // optional: default all 45 * srcEncode: 'SHIFT_JIS', // optional: default UTF-8 46 * urlEncode: 'SHIFT_JIS', // optional: default srcEncode 47 * ignoreTags: 'img', // optional: default script, syntax 'tag1,tag2,……' 48 * extractLink: '//xpath' // optional: extract permalink 46 49 * }, 47 50 * ]; … … 185 188 }, 186 189 addUserMaps: function(prefix, mapdef) { 187 mapdef.forEach(function([key, command, special, args]) {188 var cmd = prefix + ( special? '! ' : ' ') + command + ' ';189 liberator.mappings.addUserMap(190 [ liberator.modes.NORMAL, liberator.modes.VISUAL],190 mapdef.forEach(function([key, command, bang, args]) { 191 var cmd = prefix + (bang ? '! ' : ' ') + command + ' '; 192 mappings.addUserMap( 193 [modes.NORMAL, modes.VISUAL], 191 194 [key], 192 195 'user defined mapping', … … 330 333 }; 331 334 Response.prototype = { 332 initialize: function(req uest) {333 this.req uest = request;334 this.transport = req uest.transport;335 this.isSuccess = req uest.isSuccess();335 initialize: function(req) { 336 this.req = req; 337 this.transport = req.transport; 338 this.isSuccess = req.isSuccess(); 336 339 this.readyState = this.transport.readyState; 337 340 … … 357 360 this.htmlFragmentstr = this.responseText.replace(/^[\s\S]*?<html(?:[ \t\n\r][^>]*)?>|<\/html[ \t\r\n]*>[\S\s]*$/ig, '').replace(/[\r\n]+/g, ' '); 358 361 let ignoreTags = ['script']; 359 if (this.req uest.options.siteinfo.ignoreTags) {360 ignoreTags.concat(this.req uest.options.siteinfo.ignoreTags.split(','));362 if (this.req.options.siteinfo.ignoreTags) { 363 ignoreTags.concat(this.req.options.siteinfo.ignoreTags.split(',')); 361 364 } 362 365 this.htmlStripScriptFragmentstr = $U.stripTags(this.htmlFragmentstr, 'script'); … … 406 409 getSiteInfo: function() { 407 410 411 var self = this; 408 412 var useWedata = typeof liberator.globalVariables.multi_requester_use_wedata == 'undefined' ? 409 413 true : $U.eval(liberator.globalVariables.multi_requester_use_wedata); 414 415 if (liberator.globalVariables.multi_requester_siteinfo) { 416 liberator.globalVariables.multi_requester_siteinfo.forEach(function(site) { 417 if (!mergedSiteinfo[site.name]) mergedSiteinfo[site.name] = {}; 418 $U.extend(mergedSiteinfo[site.name], site); 419 if (site.map) { 420 CommandRegister.addUserMaps(MultiRequester.name[0], 421 [[site.map, site.name, site.bang, site.args]]); 422 } 423 }); 424 } 425 426 SITEINFO.forEach(function(site) { 427 if (!mergedSiteinfo[site.name]) mergedSiteinfo[site.name] = {}; 428 $U.extend(mergedSiteinfo[site.name], site); 429 if (site.map) { 430 CommandRegister.addUserMaps(MultiRequester.name[0], 431 [[site.map, site.name, site.bang, site.args]]); 432 } 433 }); 410 434 411 435 if (useWedata) { … … 417 441 }); 418 442 } 419 420 if (liberator.globalVariables.multi_requester_siteinfo) {421 liberator.globalVariables.multi_requester_siteinfo.forEach(function(site) {422 if (!mergedSiteinfo[site.name]) mergedSiteinfo[site.name] = {};423 $U.extend(mergedSiteinfo[site.name], site);424 });425 }426 427 SITEINFO.forEach(function(site) {428 if (!mergedSiteinfo[site.name]) mergedSiteinfo[site.name] = {};429 $U.extend(mergedSiteinfo[site.name], site);430 });431 443 432 444 return $U.A(mergedSiteinfo); … … 453 465 // main controller {{{ 454 466 var MultiRequester = { 455 doProcess: false,456 requestCount: 0,457 echoList: [],458 467 name: DataAccess.getCommand(), 459 468 description: 'request, and display to the buffer', 460 cmdAction: function(args, bang, count) { 469 doProcess: false, 470 requestNames: '', 471 requestCount: 0, 472 echoHash: {}, 473 cmdAction: function(args, bang, count) { // {{{ 461 474 462 475 if (MultiRequester.doProcess) return; … … 466 479 467 480 MultiRequester.doProcess = true; 481 MultiRequester.requestNames = parsedArgs.names; 468 482 MultiRequester.requestCount = 0; 469 MultiRequester.echo List = [];483 MultiRequester.echoHash = {}; 470 484 var siteinfo = parsedArgs.siteinfo; 471 485 for (let i = 0, len = parsedArgs.count; i < len; i++) { … … 549 563 }); 550 564 return ret; 551 }, 552 extractLink: function(res, extractLink) { 565 }, // }}} 566 extractLink: function(res, extractLink) { //{{{ 553 567 554 568 var el = res.getHTMLDocument(extractLink); … … 556 570 var a = el.firstChild; 557 571 var url = $U.pathToURL((a.href || a.action || a.value)); 558 var req = new Request(url, null, $U.extend(res.req uest.options, {extractLink: true}));572 var req = new Request(url, null, $U.extend(res.req.options, {extractLink: true})); 559 573 req.addEventListener('onException', $U.bind(this, this.onException)); 560 574 req.addEventListener('onSuccess', $U.bind(this, this.onSuccess)); … … 564 578 MultiRequester.doProcess = true; 565 579 566 }, 567 onSuccess: function(res) { 580 }, //}}} 581 onSuccess: function(res) { //{{{ 568 582 569 583 if (!MultiRequester.doProcess) { … … 572 586 } 573 587 574 $U.log('success!!! ' + res.request.url);588 $U.log('success!!!:' + res.req.url); 575 589 MultiRequester.requestCount--; 576 590 if (MultiRequester.requestCount == 0) { … … 584 598 if (!res.isSuccess || res.responseText == '') throw 'response is fail or null'; 585 599 586 url = res.req uest.url;600 url = res.req.url; 587 601 escapedUrl = liberator.util.escapeHTML(url); 588 xpath = res.req uest.options.siteinfo.xpath;589 extractLink = res.req uest.options.siteinfo.extractLink;590 591 if (extractLink && !res.req uest.options.extractLink) {602 xpath = res.req.options.siteinfo.xpath; 603 extractLink = res.req.options.siteinfo.extractLink; 604 605 if (extractLink && !res.req.options.extractLink) { 592 606 this.extractLink(res, extractLink); 593 607 return; … … 598 612 599 613 html = '<a href="' + escapedUrl + '" class="hl-Title" target="_self">' + escapedUrl + '</a>' + 600 (new XMLSerializer()).serializeToString(doc).replace(/<[^>]+>/g, 601 function(all) all.toLowerCase()); 602 603 MultiRequester.echoList.push(html); 614 (new XMLSerializer()).serializeToString(doc) 615 .replace(/<[^>]+>/g, function(all) all.toLowerCase()) 616 .replace(/<!--[^>]*-->/g, ''); 617 618 MultiRequester.echoHash[res.req.options.siteinfo.name] = html; 604 619 605 620 } catch (e) { 606 621 $U.log('error!!: ' + e); 607 MultiRequester.echoList.push('<span style="color: red;">error!!:' + e + '</span>'); 622 MultiRequester.echoHash[res.req.options.siteinfo.name] = 623 '<span style="color: red;">error!!: ' + e + '</span>'; 608 624 } 609 625 610 626 if (MultiRequester.requestCount == 0) { 611 let html = '<div style="white-space:normal;"><base href="' + escapedUrl + '"/>' + 612 MultiRequester.echoList.join('') + 613 '</div>'; 627 let echoList = []; 628 MultiRequester.requestNames.split(',').forEach(function(name) { 629 echoList.push(MultiRequester.echoHash[name]) 630 }); 631 html = '<div style="white-space:normal;"><base href="' + escapedUrl + '"/>' + 632 echoList.join('') + 633 '</div>'; 614 634 try { $U.echo(new XMLList(html)); } catch (e) { $U.log(e); $U.echo(html); } 615 635 } … … 623 643 MultiRequester.doProcess = false; 624 644 $U.echoerr('exception!!: ' + e); 625 } 645 }//}}} 626 646 }; 627 647 //}}} -
lang/javascript/vimperator-plugins/trunk/multi_requester.js
r25647 r25714 5 5 * @description-ja リクエストの結果をバッファに出力する。 6 6 * @author suVene suvene@zeromemory.info 7 * @version 0.4. 07 * @version 0.4.1 8 8 * @minVersion 2.0pre 9 9 * @maxVersion 2.0pre 10 * Last Change: 0 1-Dec-2008.10 * Last Change: 02-Dec-2008. 11 11 * ==/VimperatorPlugin== 12 12 * … … 36 36 * liberator.globalVariables.multi_requester_siteinfo = [ 37 37 * { 38 * name: 'ex', // required 39 * description: 'example', // required 40 * url: 'http://example.com/?%s', // required, %s <-- replace string 41 * xpath: '//*', // optional(default all) 42 * srcEncode: 'SHIFT_JIS', // optional(default UTF-8) 43 * urlEncode: 'SHIFT_JIS', // optional(default srcEncode) 44 * ignoreTags: 'img' // optional(default script), syntax 'tag1,tag2,……' 45 * extractLink: '//xpath' // optional extract permalink' 38 * map: ',me', // optional: keymap for this siteinfo call 39 * bang: true, // optional: 40 * args: 'any' // optional: 41 * name: 'ex', // required: subcommand name 42 * description: 'example', // required: commandline short help 43 * url: 'http://example.com/?%s', // required: %s <-- replace string 44 * xpath: '//*', // optional: default all 45 * srcEncode: 'SHIFT_JIS', // optional: default UTF-8 46 * urlEncode: 'SHIFT_JIS', // optional: default srcEncode 47 * ignoreTags: 'img', // optional: default script, syntax 'tag1,tag2,……' 48 * extractLink: '//xpath' // optional: extract permalink 46 49 * }, 47 50 * ]; … … 186 189 }, 187 190 addUserMaps: function(prefix, mapdef) { 188 mapdef.forEach(function([key, command, special, args]) {189 var cmd = prefix + ( special? '! ' : ' ') + command + ' ';191 mapdef.forEach(function([key, command, bang, args]) { 192 var cmd = prefix + (bang ? '! ' : ' ') + command + ' '; 190 193 mappings.addUserMap( 191 194 [modes.NORMAL, modes.VISUAL], … … 331 334 }; 332 335 Response.prototype = { 333 initialize: function(req uest) {334 this.req uest = request;335 this.transport = req uest.transport;336 this.isSuccess = req uest.isSuccess();336 initialize: function(req) { 337 this.req = req; 338 this.transport = req.transport; 339 this.isSuccess = req.isSuccess(); 337 340 this.readyState = this.transport.readyState; 338 341 … … 358 361 this.htmlFragmentstr = this.responseText.replace(/^[\s\S]*?<html(?:[ \t\n\r][^>]*)?>|<\/html[ \t\r\n]*>[\S\s]*$/ig, '').replace(/[\r\n]+/g, ' '); 359 362 let ignoreTags = ['script']; 360 if (this.req uest.options.siteinfo.ignoreTags) {361 ignoreTags.concat(this.req uest.options.siteinfo.ignoreTags.split(','));363 if (this.req.options.siteinfo.ignoreTags) { 364 ignoreTags.concat(this.req.options.siteinfo.ignoreTags.split(',')); 362 365 } 363 366 this.htmlStripScriptFragmentstr = $U.stripTags(this.htmlFragmentstr, 'script'); … … 407 410 getSiteInfo: function() { 408 411 412 var self = this; 409 413 var useWedata = typeof liberator.globalVariables.multi_requester_use_wedata == 'undefined' ? 410 414 true : $U.eval(liberator.globalVariables.multi_requester_use_wedata); 415 416 if (liberator.globalVariables.multi_requester_siteinfo) { 417 liberator.globalVariables.multi_requester_siteinfo.forEach(function(site) { 418 if (!mergedSiteinfo[site.name]) mergedSiteinfo[site.name] = {}; 419 $U.extend(mergedSiteinfo[site.name], site); 420 if (site.map) { 421 CommandRegister.addUserMaps(MultiRequester.name[0], 422 [[site.map, site.name, site.bang, site.args]]); 423 } 424 }); 425 } 426 427 SITEINFO.forEach(function(site) { 428 if (!mergedSiteinfo[site.name]) mergedSiteinfo[site.name] = {}; 429 $U.extend(mergedSiteinfo[site.name], site); 430 if (site.map) { 431 CommandRegister.addUserMaps(MultiRequester.name[0], 432 [[site.map, site.name, site.bang, site.args]]); 433 } 434 }); 411 435 412 436 if (useWedata) { … … 418 442 }); 419 443 } 420 421 if (liberator.globalVariables.multi_requester_siteinfo) {422 liberator.globalVariables.multi_requester_siteinfo.forEach(function(site) {423 if (!mergedSiteinfo[site.name]) mergedSiteinfo[site.name] = {};424 $U.extend(mergedSiteinfo[site.name], site);425 });426 }427 428 SITEINFO.forEach(function(site) {429 if (!mergedSiteinfo[site.name]) mergedSiteinfo[site.name] = {};430 $U.extend(mergedSiteinfo[site.name], site);431 });432 444 433 445 return $U.A(mergedSiteinfo); … … 454 466 // main controller {{{ 455 467 var MultiRequester = { 456 doProcess: false,457 requestCount: 0,458 echoList: [],459 468 name: DataAccess.getCommand(), 460 469 description: 'request, and display to the buffer', 461 cmdAction: function(args) { 470 doProcess: false, 471 requestNames: '', 472 requestCount: 0, 473 echoHash: {}, 474 cmdAction: function(args) { //{{{ 462 475 463 476 if (MultiRequester.doProcess) return; … … 471 484 472 485 MultiRequester.doProcess = true; 486 MultiRequester.requestNames = parsedArgs.names; 473 487 MultiRequester.requestCount = 0; 474 MultiRequester.echo List = [];488 MultiRequester.echoHash = {}; 475 489 var siteinfo = parsedArgs.siteinfo; 476 490 for (let i = 0, len = parsedArgs.count; i < len; i++) { … … 554 568 }); 555 569 return ret; 556 }, 557 extractLink: function(res, extractLink) { 570 },//}}} 571 extractLink: function(res, extractLink) { //{{{ 558 572 559 573 var el = res.getHTMLDocument(extractLink); … … 561 575 var a = el.firstChild; 562 576 var url = $U.pathToURL((a.href || a.action || a.value)); 563 var req = new Request(url, null, $U.extend(res.req uest.options, {extractLink: true}));577 var req = new Request(url, null, $U.extend(res.req.options, {extractLink: true})); 564 578 req.addEventListener('onException', $U.bind(this, this.onException)); 565 579 req.addEventListener('onSuccess', $U.bind(this, this.onSuccess)); … … 569 583 MultiRequester.doProcess = true; 570 584 571 }, 572 onSuccess: function(res) { 585 },//}}} 586 onSuccess: function(res) { //{{{ 573 587 574 588 if (!MultiRequester.doProcess) { … … 577 591 } 578 592 579 $U.log('success!!! ' + res.request.url);593 $U.log('success!!!:' + res.req.url); 580 594 MultiRequester.requestCount--; 581 595 if (MultiRequester.requestCount == 0) { … … 589 603 if (!res.isSuccess || res.responseText == '') throw 'response is fail or null'; 590 604 591 url = res.req uest.url;605 url = res.req.url; 592 606 escapedUrl = util.escapeHTML(url); 593 xpath = res.req uest.options.siteinfo.xpath;594 extractLink = res.req uest.options.siteinfo.extractLink;595 596 if (extractLink && !res.req uest.options.extractLink) {607 xpath = res.req.options.siteinfo.xpath; 608 extractLink = res.req.options.siteinfo.extractLink; 609 610 if (extractLink && !res.req.options.extractLink) { 597 611 this.extractLink(res, extractLink); 598 612 return; … … 603 617 604 618 html = '<a href="' + escapedUrl + '" class="hl-Title" target="_self">' + escapedUrl + '</a>' + 605 (new XMLSerializer()).serializeToString(doc).replace(/<[^>]+>/g, 606 function(all) all.toLowerCase()); 607 608 MultiRequester.echoList.push(html); 619 (new XMLSerializer()).serializeToString(doc) 620 .replace(/<[^>]+>/g, function(all) all.toLowerCase()) 621 .replace(/<!--[^>]*-->/g, ''); 622 623 MultiRequester.echoHash[res.req.options.siteinfo.name] = html; 609 624 610 625 } catch (e) { 611 626 $U.log('error!!: ' + e); 612 MultiRequester.echoList.push('<span style="color: red;">error!!:' + e + '</span>'); 627 MultiRequester.echoHash[res.req.options.siteinfo.name] = 628 '<span style="color: red;">error!!: ' + e + '</span>'; 613 629 } 614 630 615 631 if (MultiRequester.requestCount == 0) { 616 let html = '<div style="white-space:normal;"><base href="' + escapedUrl + '"/>' + 617 MultiRequester.echoList.join('') + 618 '</div>'; 619 try { $U.echo(new XMLList(html)); } catch (e) { $U.echo(html); } 632 let echoList = []; 633 MultiRequester.requestNames.split(',').forEach(function(name) { 634 echoList.push(MultiRequester.echoHash[name]) 635 }); 636 html = '<div style="white-space:normal;"><base href="' + escapedUrl + '"/>' + 637 echoList.join('') + 638 '</div>'; 639 try { $U.echo(new XMLList(html)); } catch (e) { $U.log(e); $U.echo(html); } 620 640 } 621 641 … … 628 648 MultiRequester.doProcess = false; 629 649 $U.echoerr('exception!!: ' + e); 630 } 650 }//}}} 631 651 }; 632 652 //}}}
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)