Changeset 19907

Show
Ignore:
Timestamp:
09/25/08 20:43:51 (5 years ago)
Author:
os0x
Message:
  • ver 1.1.3
  • Opera9.5以降用に最適化(Array#forEachなど)
  • デフォルトのICONサイズを16から8に変更
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/opera-userjs/oAutoPagerize.js

    r17059 r19907  
    22// @name           oAutoPagerize 
    33// @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). 
    55// @checkurl       http://svn.coderepos.org/share/lang/javascript/opera-userjs/oAutoPagerize.js 
    66// @include        http://* 
     
    2222// 
    2323// UPDATE INFO (Only Japanese) http://d.hatena.ne.jp/os0x/searchdiary?word=%2a%5boAutoPagerize%5d 
    24 //  
     24// 
    2525 
    2626(function(){ 
     
    5353        var URL = 'http://d.hatena.ne.jp/os0x/searchdiary?word=%2a%5boAutoPagerize%5d'; 
    5454        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'; 
    5656        var AUTO_START = Set.AUTO_START || true; 
    5757        //var CACHE_EXPIRE = 24 * 60 * 60 * 1000; 
     
    8484                error      : '#ff00ff' 
    8585        }; 
    86         var ICON_SIZE = Set.ICON_SIZE || 16; 
     86        var ICON_SIZE = Set.ICON_SIZE || 8; 
    8787        if (Set.COLOR) (function(c){ 
    8888                for (var i in c) { 
     
    110110        } 
    111111 
    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         }; 
    122112        var TOP_SITEINFO = Set.TOP_SITEINFO.concat([ 
    123113                /* 
     
    197187        var autopager = function() { 
    198188                if (miscellaneous.length) { 
    199                         forEach(miscellaneous,function(f){f();}); 
     189                        miscellaneous.forEach(function(f){f();}); 
    200190                } 
    201191                log('autopagerize loading'); 
     192                var docRoot = document.documentElement.clientHeight < document.body.clientHeight ? document.documentElement : document.body; 
    202193 
    203194                var AutoPager = function() {this.initialize.apply(this, arguments);}; 
     
    228219                                this.initHelp(); 
    229220                                this.icon.addEventListener("mouseover", function(){self.viewHelp()}, false); 
    230                                 var scrollHeight = getScrollHeight(); 
     221                                var scrollHeight = docRoot.scrollHeight; 
    231222                                var bottom = getElementPosition(this.insertPoint).top || this.getPageElementsBottom() || (Math.round(scrollHeight * 0.8)); 
    232223                                this.remainHeight = scrollHeight - bottom + BASE_REMAIN_HEIGHT; 
     
    334325                        } 
    335326                        ,checkRemain:function() { 
    336                                 var remain = document.documentElement.scrollHeight - window.innerHeight - window.pageYOffset; 
     327                                var remain = docRoot.scrollHeight - window.innerHeight - window.pageYOffset; 
    337328                                if (this.state && remain < this.remainHeight) { 
    338329                                        this.request(); 
     
    431422                        } 
    432423                        ,loaded:function(htmlDoc) { 
    433                                 forEach(AutoPager.documentFilters,function(i) { 
     424                                AutoPager.documentFilters.forEach(function(i) { 
    434425                                        i(htmlDoc, this.requestURL, this.info) 
    435426                                }, this); 
     
    464455                                } 
    465456                                if (this.createHTMLDocumentMode && !window.opera) { 
    466                                         pages = forMap(pages,function (page) { 
     457                                        pages = pages.map(function (page) { 
    467458                                                page = document.importNode(page, true); 
    468459                                                return page; 
     
    471462                                this.loadedURLs[this.requestURL] = true; 
    472463                                this.addPage(htmlDoc, pages); 
    473                                 forEach(AutoPager.filters,function(i) { 
     464                                AutoPager.filters.forEach(function(i) { 
    474465                                        i(pages); 
    475466                                }); 
     
    505496                                insertParentNode.insertBefore(root, this.insertPoint); 
    506497                                var self = this; 
    507                                 forEach(pages,function(i) { 
     498                                pages.forEach(function(i) { 
    508499                                        insertParentNode.insertBefore(i, self.insertPoint); 
    509                                 }) 
     500                                }); 
    510501                        } 
    511502                        ,initIcon:function() { 
     
    554545                        var setTargetBlank = function(doc) { 
    555546                                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) { 
    557548                                        i.target = TARGET_WINDOW_NAME; 
    558549                                }); 
     
    565556                        var s = (new Date).getTime(); 
    566557                        var nlist = []; 
    567                         var m = []; 
    568558                        for (var i = 0;i < list.length;++i) { 
    569559                                try { 
     
    571561                                        _item.regurl = new RegExp(_item.url); 
    572562                                        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')) { 
    576564                                                MICROFORMATs.push(_item); 
    577565                                        } 
     
    581569                                } 
    582570                        } 
    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]) 
    603580                                                } 
    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; 
    608593                                } 
    609594                        } 
    610595                        log('launchAutoPager...fin:'+((new Date).getTime()-s)); 
    611                         forEach(MICROFORMATs,function(format){ 
     596                        MICROFORMATs.forEach(function(format){ 
    612597                                if (!ap && getFirstElementByXPath(format.nextLink) && getFirstElementByXPath(format.pageElement)) { 
    613598                                        ap = new AutoPager(format); 
     
    630615                var ap = null; 
    631616                launchAutoPager(TOP_SITEINFO.concat(SITEINFO,BOTTOM_SITEINFO)); 
    632                 SITEINFO = null; 
    633617 
    634618                // utility functions. 
     
    646630                        var html = String(str);// Thx! jAutoPagerize#HTMLResource.createDocumentFromString http://svn.coderepos.org/share/lang/javascript/userscripts/jautopagerize.user.js 
    647631                        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 ? 
    649633                                        document.implementation.createHTMLDocument('hogehoge') : 
    650634                                        document.implementation.createDocument(null, 'html', null); 
     
    661645 
    662646                function createDocumentFragmentByString(str,htmlDoc) { 
    663                         var range = htmlDoc.createRange(); 
    664                         range.selectNodeContents(htmlDoc.documentElement); 
     647                        var range = document.createRange(); 
     648                        range.setStartAfter(document.body); 
    665649                        return range.createContextualFragment(str); 
    666650                } 
     
    719703                                'paddingTop', 'paddingBottom', 
    720704                                'marginTop', 'marginBottom']; 
    721                         forEach(prop,function(i) { 
     705                        prop.forEach(function(i) { 
    722706                                var h = parseInt(c_style[i]); 
    723707                                if (typeof h == 'number') { 
     
    727711                        var top = getElementPosition(elem).top; 
    728712                        return top ? (top + height) : null; 
    729                 } 
    730                 function getScrollHeight() { 
    731                         return Math.max(document.documentElement.scrollHeight, document.body.scrollHeight); 
    732713                } 
    733714                function pathToURL(path) { 
     
    738719                function $X(exp, context, type /* want type */) { 
    739720                        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"]'); 
    741722                                exp = exp.indexOf("(//") == 0 
    742723                                        ? "(.//" + exp.substring(3)