Changeset 19907
- Timestamp:
- 09/25/08 20:43:51 (5 years ago)
- Files:
-
- 1 modified
-
lang/javascript/opera-userjs/oAutoPagerize.js (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/javascript/opera-userjs/oAutoPagerize.js
r17059 r19907 2 2 // @name oAutoPagerize 3 3 // @namespace http://ss-o.net/ 4 // @description loading next page and inserting into current page. (opera-optimized and Safari3 support..)4 // @description loading next page and inserting into current page. oAutoPagerize Support for Opera9.50, GreaseKit(Safari/WebKit) and Greasemetal(Google Chrome). 5 5 // @checkurl http://svn.coderepos.org/share/lang/javascript/opera-userjs/oAutoPagerize.js 6 6 // @include http://* … … 22 22 // 23 23 // UPDATE INFO (Only Japanese) http://d.hatena.ne.jp/os0x/searchdiary?word=%2a%5boAutoPagerize%5d 24 // 24 // 25 25 26 26 (function(){ … … 53 53 var URL = 'http://d.hatena.ne.jp/os0x/searchdiary?word=%2a%5boAutoPagerize%5d'; 54 54 var UPDATE_URL = window.opera ? 'http://ss-o.net/userjs/0AutoPagerize.SITEINFO.js' : 'http://ss-o.net/userjs/0AutoPagerize.SITEINFO.user.js'; 55 var VERSION = '1.1. 2';55 var VERSION = '1.1.3'; 56 56 var AUTO_START = Set.AUTO_START || true; 57 57 //var CACHE_EXPIRE = 24 * 60 * 60 * 1000; … … 84 84 error : '#ff00ff' 85 85 }; 86 var ICON_SIZE = Set.ICON_SIZE || 16;86 var ICON_SIZE = Set.ICON_SIZE || 8; 87 87 if (Set.COLOR) (function(c){ 88 88 for (var i in c) { … … 110 110 } 111 111 112 var forEach = function(arr,fun,obj) {113 for(var i=0,l=arr.length;i<l;i++) fun.call(obj,arr[i],i,arr);114 };115 var forMap = function(arr,callback,obj) {116 var _arr = [];117 for(var i = 0, len = arr.length; i < len; i++) {118 _arr.push(callback.call(obj,arr[i],i,arr));119 }120 return _arr;121 };122 112 var TOP_SITEINFO = Set.TOP_SITEINFO.concat([ 123 113 /* … … 197 187 var autopager = function() { 198 188 if (miscellaneous.length) { 199 forEach(miscellaneous,function(f){f();});189 miscellaneous.forEach(function(f){f();}); 200 190 } 201 191 log('autopagerize loading'); 192 var docRoot = document.documentElement.clientHeight < document.body.clientHeight ? document.documentElement : document.body; 202 193 203 194 var AutoPager = function() {this.initialize.apply(this, arguments);}; … … 228 219 this.initHelp(); 229 220 this.icon.addEventListener("mouseover", function(){self.viewHelp()}, false); 230 var scrollHeight = getScrollHeight();221 var scrollHeight = docRoot.scrollHeight; 231 222 var bottom = getElementPosition(this.insertPoint).top || this.getPageElementsBottom() || (Math.round(scrollHeight * 0.8)); 232 223 this.remainHeight = scrollHeight - bottom + BASE_REMAIN_HEIGHT; … … 334 325 } 335 326 ,checkRemain:function() { 336 var remain = doc ument.documentElement.scrollHeight - window.innerHeight - window.pageYOffset;327 var remain = docRoot.scrollHeight - window.innerHeight - window.pageYOffset; 337 328 if (this.state && remain < this.remainHeight) { 338 329 this.request(); … … 431 422 } 432 423 ,loaded:function(htmlDoc) { 433 forEach(AutoPager.documentFilters,function(i) {424 AutoPager.documentFilters.forEach(function(i) { 434 425 i(htmlDoc, this.requestURL, this.info) 435 426 }, this); … … 464 455 } 465 456 if (this.createHTMLDocumentMode && !window.opera) { 466 pages = forMap(pages,function (page) {457 pages = pages.map(function (page) { 467 458 page = document.importNode(page, true); 468 459 return page; … … 471 462 this.loadedURLs[this.requestURL] = true; 472 463 this.addPage(htmlDoc, pages); 473 forEach(AutoPager.filters,function(i) {464 AutoPager.filters.forEach(function(i) { 474 465 i(pages); 475 466 }); … … 505 496 insertParentNode.insertBefore(root, this.insertPoint); 506 497 var self = this; 507 forEach(pages,function(i) {498 pages.forEach(function(i) { 508 499 insertParentNode.insertBefore(i, self.insertPoint); 509 }) 500 }); 510 501 } 511 502 ,initIcon:function() { … … 554 545 var setTargetBlank = function(doc) { 555 546 var anchers = getElementsByXPath('descendant-or-self::a[@href and not(contains(@class,"autopagerize_link") or starts-with(@href,"javascript:") or starts-with(@href,"#"))]', doc); 556 forEach(anchers,function(i) {547 anchers.forEach(function(i) { 557 548 i.target = TARGET_WINDOW_NAME; 558 549 }); … … 565 556 var s = (new Date).getTime(); 566 557 var nlist = []; 567 var m = [];568 558 for (var i = 0;i < list.length;++i) { 569 559 try { … … 571 561 _item.regurl = new RegExp(_item.url); 572 562 if (!_item.nextLink || !_item.pageElement) continue; 573 if (!_item.regurl.test('http://a')) { 574 m.push(_item.url); 575 } else { 563 if (_item.regurl.test('http://a')) { 576 564 MICROFORMATs.push(_item); 577 565 } … … 581 569 } 582 570 } 583 var regexp = new RegExp(m.join('|')); 584 if (regexp.test(locationHref)) { 585 for (var i = 0,l = nlist.length;i < l; ++i) { 586 var info = nlist[i]; 587 try { 588 if (ap) { 589 } else if (!info.regurl.test(locationHref)) { 590 } else if (!getFirstElementByXPath(info.nextLink)) { 591 // ignore microformats case. 592 if (!info.regurl.test('http://a')) { 593 debug("nextLink not found.", list[i]) 594 } 595 } else if (!getFirstElementByXPath(info.pageElement)) { 596 if (!info.regurl.test('http://a')) { 597 debug("pageElement not found.", list[i]) 598 } 599 } else { 600 ap = new AutoPager(info); 601 window.AutoPagerize.AutoPagerObject = ap; 602 break; 571 for (var i = 0,l = nlist.length;i < l; ++i) { 572 var info = nlist[i]; 573 try { 574 if (ap) { 575 } else if (!info.regurl.test(locationHref)) { 576 } else if (!getFirstElementByXPath(info.nextLink)) { 577 // ignore microformats case. 578 if (!info.regurl.test('http://a')) { 579 debug("nextLink not found.", list[i]) 603 580 } 604 } catch(e) { 605 log('error at launchAutoPager()'+e); 606 continue; 607 } 581 } else if (!getFirstElementByXPath(info.pageElement)) { 582 if (!info.regurl.test('http://a')) { 583 debug("pageElement not found.", list[i]) 584 } 585 } else { 586 ap = new AutoPager(info); 587 window.AutoPagerize.AutoPagerObject = ap; 588 break; 589 } 590 } catch(e) { 591 log('error at launchAutoPager()'+e); 592 continue; 608 593 } 609 594 } 610 595 log('launchAutoPager...fin:'+((new Date).getTime()-s)); 611 forEach(MICROFORMATs,function(format){596 MICROFORMATs.forEach(function(format){ 612 597 if (!ap && getFirstElementByXPath(format.nextLink) && getFirstElementByXPath(format.pageElement)) { 613 598 ap = new AutoPager(format); … … 630 615 var ap = null; 631 616 launchAutoPager(TOP_SITEINFO.concat(SITEINFO,BOTTOM_SITEINFO)); 632 SITEINFO = null;633 617 634 618 // utility functions. … … 646 630 var html = String(str);// Thx! jAutoPagerize#HTMLResource.createDocumentFromString http://svn.coderepos.org/share/lang/javascript/userscripts/jautopagerize.user.js 647 631 html = html.replace(/<script[^>]*>[\S\s]*?<\/script\s*>|<\/?(?:i?frame|html|script|object)(?:\s*|\s+[^<>]+)>/gi, " "); 648 var htmlDoc = document.implementation.createHTMLDocument ?632 var htmlDoc = document.implementation.createHTMLDocument ? 649 633 document.implementation.createHTMLDocument('hogehoge') : 650 634 document.implementation.createDocument(null, 'html', null); … … 661 645 662 646 function createDocumentFragmentByString(str,htmlDoc) { 663 var range = htmlDoc.createRange();664 range.se lectNodeContents(htmlDoc.documentElement);647 var range = document.createRange(); 648 range.setStartAfter(document.body); 665 649 return range.createContextualFragment(str); 666 650 } … … 719 703 'paddingTop', 'paddingBottom', 720 704 'marginTop', 'marginBottom']; 721 forEach(prop,function(i) {705 prop.forEach(function(i) { 722 706 var h = parseInt(c_style[i]); 723 707 if (typeof h == 'number') { … … 727 711 var top = getElementPosition(elem).top; 728 712 return top ? (top + height) : null; 729 }730 function getScrollHeight() {731 return Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);732 713 } 733 714 function pathToURL(path) { … … 738 719 function $X(exp, context, type /* want type */) { 739 720 if ($X.forceRelative) { 740 exp = exp.replace(/id\(\s*(["'])([^"']+)\1\s*\)/g, './/*[@id="$2"]'); 721 exp = exp.replace(/id\(\s*(["'])([^"']+)\1\s*\)/g, './/*[@id="$2"]'); 741 722 exp = exp.indexOf("(//") == 0 742 723 ? "(.//" + exp.substring(3)
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)