Changeset 18597

Show
Ignore:
Timestamp:
09/02/08 00:06:54 (3 months ago)
Author:
drry
Message:
  • 正規表現を修正しました。
  • ほか。
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/userscripts/poptip.user.js

    r18591 r18597  
    2828               Add 2 rules to SITEINFO (Slashdot.org, YouTube in Hatena Bookmark) 
    292920080824 0.0.9 "excludeUrl" option 
    30                Add 2 rules to SITEINFO (Yahoo Chiebukuro, Hatena Keyword) 
     30               Add 2 rules to SITEINFO (Yahoo! Chiebukuro, Hatena Keyword) 
    3131*/ 
    3232 
     
    4646var SITEINFO = [ 
    4747    { 
    48         url: '^http://mixi\\.jp/*', 
     48        url: '^http://mixi\\.jp/', 
    4949        linkElement: 'id("mymixiList")//td/a', 
    5050        popupElement: 'id("profile")', 
    5151        disabled: false, 
    52         style : {  
    53             backgroundColor : 'white', 
    54             borderWidth : '1px', 
    55             borderColor: 'orange', 
    56             borderStyle: 'solid' 
    57         } 
    58     }, 
    59     { 
    60         url: '^http://mixi\\.jp/*', 
     52        style: { 
     53            backgroundColor: 'white', 
     54            border: '1px solid orange' 
     55        } 
     56    }, 
     57    { 
     58        url: '^http://mixi\\.jp/', 
    6159        targetElement: 'id("myProfile")//div[@class="contents01"]/img', 
    6260        linkElement: 'id("myProfile")//div[@class="contents03"]//a', 
    6361        popupElement: 'id("editPhotoArea")', 
    6462        disabled: false, 
    65         style : {  
    66             backgroundColor : 'white', 
    67             borderWidth : '1px', 
    68             borderColor: 'orange', 
    69             borderStyle: 'solid' 
     63        style: { 
     64            backgroundColor: 'white', 
     65            border: '1px solid orange' 
    7066        } 
    7167    }, 
    7268    { 
    7369        description: 'mixi community recent topics', 
    74         url: '^http://mixi\\.jp/*', 
     70        url: '^http://mixi\\.jp/', 
    7571        linkElement: 'id("communityList")//td/a', 
    7672        popupElement: 'id("newCommunityTopic")//dl', 
    77         style : {  
    78             backgroundColor : 'white', 
    79             borderWidth : '1px', 
    80             padding : '8px', 
    81             borderColor: 'orange', 
    82             borderStyle: 'solid' 
     73        style: { 
     74            backgroundColor: 'white', 
     75            border: '1px solid orange', 
     76            padding: '8px' 
    8377        }, 
    8478        containerHTML: '<h2>Recent Topics</h2><popup:container/>' 
     
    8983        linkElement: 'id("log_color")/ul/li/a', 
    9084        popupElement: 'id("profile")', 
    91         style : { 
    92                 border: "solid 1px gray", 
     85        style: { 
     86                border: "1px solid gray", 
    9387                width: "400px" 
    9488        } 
    9589    }, 
    9690    { 
    97         url: '^http://(www|)flickr\\.com/.*', 
     91        url: '^http://(?:www\\.)?flickr\\.com/', 
    9892        linkElement: '//span[@class="photo_container pc_s"]/a', 
    9993        popupElement: '//div[@class="photoImgDiv"]//img', 
    100         style : { 
     94        style: { 
    10195            padding: '0px' 
    10296        } 
     
    10498    { 
    10599        descript: 'Flickr Exif info', 
    106         url: '^http://(www|)flickr\\.com/.*', 
     100        url: '^http://(?:www\\.)?flickr\\.com/', 
    107101        linkElement: '//li[@class="Stats"]/a[.="More properties"]', 
    108102        popupElement: 'id("GoodStuff")', 
    109103        stripe: true, 
    110         style : { 
    111             backgroundColor : 'white', 
    112             padding : '4px;', 
    113             margin : '4px;', 
    114             border : 'solid 1px #444' 
    115         } 
    116     }, 
    117     { 
    118         url: '^http://(www|)flickr\\.com/.*', 
     104        style: { 
     105            backgroundColor: 'white', 
     106            padding: '4px;', 
     107            margin: '4px;', 
     108            border: '1px solid #444' 
     109        } 
     110    }, 
     111    { 
     112        url: '^http://(?:www\\.)?flickr\\.com/', 
    119113        linkElement: '//span[@class="photo_container pc_s"]/a', 
    120114        popupElement: '//div[@class="photoImgDiv"]//img', 
    121         style : {  
    122             backgroundColor : 'white' 
     115        style: { 
     116            backgroundColor: 'white' 
    123117        } 
    124118    }, 
     
    129123        linkElement: '//div[@class="inner"]/ul/li/nobr/a', 
    130124        popupElement: '//div[@class="inner"]/ul', 
    131        stripe: true, 
     125        stripe: true, 
    132126        style: { 
    133127            fontSize: '80%', 
    134128            textAlign: 'left', 
    135             padding : '4px;', 
    136             margin : '4px;', 
    137             border : 'solid 1px #444' 
     129            padding: '4px;', 
     130            margin: '4px;', 
     131            border: '1px solid #444' 
    138132        } 
    139133    }, 
    140134    { 
    141135        description: 'Hatena Bookmark', 
    142         url: '^http://b\\.hatena\\.ne\\.jp/*', 
     136        url: '^http://b\\.hatena\\.ne\\.jp/', 
    143137        linkElement: '//div[@class="entry-footer"]//*//a', 
    144138        popupElement: 'id("entry-info")//blockquote', 
    145139        delay: 1000, 
    146        stripe: true, 
     140        stripe: true, 
    147141        style: { 
    148142            fontSize: '80%' 
     
    151145    { 
    152146        description: 'Hatena Bookmark', 
    153         url: '^http://b\\.hatena\\.ne\\.jp/*', 
     147        url: '^http://b\\.hatena\\.ne\\.jp/', 
    154148        linkElement: '//dd[@class="users"]//a', 
    155149        popupElement: 'id("entry-info")//blockquote', 
     
    157151        style: { 
    158152            fontSize: '80%', 
    159             border: 'solid 1px blue' 
     153            border: '1px solid blue' 
    160154        } 
    161155    }, 
    162156    { 
    163157        description: 'Hatena Diary Keyword', 
    164         url: '^http://d\\.hatena\\.ne\\.jp/*', 
    165         excludeUrl: '^http://d\\.hatena\\.ne\\.jp/keyword/.*', 
     158        url: '^http://d\\.hatena\\.ne\\.jp/', 
     159        excludeUrl: '^http://d\\.hatena\\.ne\\.jp/keyword/', 
    166160        linkElement: '//a[@class="keyword"]', 
    167161        popupElement: '//div[@class="box-curve-bar"]//div[@class="section"]', 
    168162        delay: 1000, 
    169        stripe: true, 
     163        stripe: true, 
    170164        style: { 
    171165            fontSize: '80%', 
    172166            padding: '2px', 
    173             border: 'solid 1px blue', 
     167            border: '1px solid blue', 
    174168            color: 'black', 
    175169            backgroundColor: 'white', 
     
    179173    { 
    180174        description: 'Hatena Keyword', 
    181         url: '^http://d\\.hatena\\.ne\\.jp/keyword/.*', 
     175        url: '^http://d\\.hatena\\.ne\\.jp/keyword/', 
    182176        linkElement: '//a[@class="keyword"]', 
    183177        popupElement: 'id("body")//div[@class="keyword-body"]/div[@class="section"]/p', 
    184178        delay: 1000, 
    185        stripe: true, 
     179        stripe: true, 
    186180        style: { 
    187181            fontSize: '80%', 
    188182            padding: '2px', 
    189             border: 'solid 1px blue', 
     183            border: '1px solid blue', 
    190184            color: 'black', 
    191185            backgroundColor: 'white', 
     
    194188    }, 
    195189    { 
    196         url: '^http://mixi\\.jp/(search|list)_community\\.pl.*', 
     190        url: '^http://mixi\\.jp/(?:search|list)_community\\.pl', 
    197191        linkElement: '//div[@class="iconList03"]//a', 
    198192        popupElement: 'id("newCommunityTopic")//dl', 
    199         style : {  
    200             backgroundColor : 'white', 
    201             borderWidth : '1px', 
    202             padding : '8px', 
    203             borderColor: 'orange', 
    204             borderStyle: 'solid' 
    205         } 
    206     }, 
    207     { 
    208         description: 'Yahoo Chiebukuro related question', 
     193        style: { 
     194            backgroundColor: 'white', 
     195            border: '1px solid orange', 
     196            padding: '8px' 
     197        } 
     198    }, 
     199    { 
     200        description: 'Yahoo! Chiebukuro related question', 
    209201        url: '^http://detail\\.chiebukuro\\.yahoo\\.co\\.jp/qa/question_detail/.+', 
    210202        linkElement: 'id("recommend")//dd[@class="recombox"]/a', 
    211203        popupElement: '//div[@class="bestAnswer Extends-details"]//div[@class="qa"]', 
    212         style : {  
    213             backgroundColor : 'white', 
    214             borderWidth : '1px', 
    215             padding : '8px', 
    216             borderColor: 'blue', 
    217             fontSize: '80%', 
    218             textAlign: 'left', 
    219             borderStyle: 'solid' 
     204        style: { 
     205            backgroundColor: 'white', 
     206            borderWidth: '1px solid blue', 
     207            padding: '8px', 
     208            fontSize: '80%', 
     209            textAlign: 'left' 
    220210        }, 
    221211        containerHTML: '<h2>Best Answer</h2><popup:container/>' 
    222212    }, 
    223  
    224213    { 
    225214        description: 'Twitter icon enlargement', 
    226         url: '^http://twitter\\.com/*', 
     215        url: '^http://twitter\\.com/', 
    227216        targetElement: '//td[@class="thumb vcard author"]//img[@class="photo fn"]', 
    228         linkElement:  '//td[@class="thumb vcard author"]//a[@class="url"]', 
     217        linkElement: '//td[@class="thumb vcard author"]//a[@class="url"]', 
    229218        linkReplaceRule: { 
    230             pattern : 'http://twitter.com/', 
    231             replacement : 'http://twitter.com/account/profile_image/' 
     219            pattern: 'http://twitter.com/', 
     220            replacement: 'http://twitter.com/account/profile_image/' 
    232221        }, 
    233222        popupElement: 'id("content")/div/p/img', 
     
    235224    { 
    236225        description: 'Twitter timeline', 
    237         url: '^http://twitter\\.com/*', 
    238         linkElement:  'id("content")//td[@class="content"]/strong/a', 
     226        url: '^http://twitter\\.com/', 
     227        linkElement: 'id("content")//td[@class="content"]/strong/a', 
    239228        popupElement: 'id("side")', 
    240229        disabled: true, 
     
    246235    { 
    247236        description: 'Twitter following & followers', 
    248         url: '^http://twitter\\.com.*/(friends|followers)', 
     237        url: '^http://twitter\\.com/.+?/(?:friends|followers)', 
    249238        targetElement: '//td[@class="thumb"]//img[@class="photo fn"]', 
    250         linkElement:  '//td[@class="thumb"]//a[@rel="contact"]', 
     239        linkElement: '//td[@class="thumb"]//a[@rel="contact"]', 
    251240        popupElement: 'id("side")', 
    252241        style: { 
     
    257246    { 
    258247        description: 'Hatena Fotolife', 
    259         url: '^http://f\\.hatena\\.ne\\.jp/.*', 
     248        url: '^http://f\\.hatena\\.ne\\.jp/', 
    260249        linkElement: '//ul[@class="fotolist"]/li/a', 
    261250        popupElement: 'id("container")/div[2]/div[3]/img', 
    262         style : { 
     251        style: { 
    263252        } 
    264253    }, 
    265254    { 
    266255        description: 'Pixiv thumbnails', 
    267         url: '^http://www\\.pixiv\\.net/tags\\.php\\?tag=.*', 
     256        url: '^http://www\\.pixiv\\.net/tags\\.php\\?tag=', 
    268257        linkElement: 'id("illust_c5")/ul/li/a[1]', 
    269258        popupElement: 'id("content2")/div[6]/a/img', 
    270         style : { 
    271             border : 'solid 1px black' 
     259        style: { 
     260            border: '1px solid black' 
    272261        } 
    273262    }, 
    274263    { 
    275264        description: 'Amazon.co.jp ListMania', 
    276         url: '^http://www\\.amazon\\.co\\.jp/.*/lm/.*', 
     265        url: '^http://www\\.amazon\\.co\\.jp/.+?/lm/', 
    277266        targetElement: '//td[@class="listItem"]/a/img[position()=1]', 
    278         linkElement:  '//td[@class="listItem"]//strong/a', 
     267        linkElement: '//td[@class="listItem"]//strong/a', 
    279268        popupElement: 'id("productDescription")', 
    280269        stripe: true, 
    281         style : { 
    282             fontSize : '80%', 
    283             width : '500px', 
    284             padding : '5px', 
    285             border : 'solid 1px orange' 
     270        style: { 
     271            fontSize: '80%', 
     272            width: '500px', 
     273            padding: '5px', 
     274            border: '1px solid orange' 
    286275        } 
    287276    }, 
    288277    { 
    289278        description: 'Amazon.co.jp SearchResult', 
    290         url: '^http://www\\.amazon\\.co\\.jp/s/.*', 
    291         linkElement:  '//td[@class="imageColumn"]//a', 
     279        url: '^http://www\\.amazon\\.co\\.jp/s/', 
     280        linkElement: '//td[@class="imageColumn"]//a', 
    292281        popupElement: 'id("productDescription")', 
    293282        delay: 300, 
    294283        stripe: true, 
    295         style : { 
    296             fontSize : '80%', 
    297             width : '500px', 
    298             padding : '5px', 
    299             border : 'solid 1px orange' 
     284        style: { 
     285            fontSize: '80%', 
     286            width: '500px', 
     287            padding: '5px', 
     288            border: '1px solid orange' 
    300289        } 
    301290    }, 
    302291    { 
    303292        description: 'slashdot.jp recent 3 stories', 
    304         url: '^http://slashdot\\.(jp|org)/topics\\.(pl|shtml)', 
     293        url: '^http://slashdot\\.(?:jp|org)/topics\\.(?:pl|shtml)', 
    305294        exampleUrl: 'http://slashdot.jp/topics.pl', 
    306295        targetElement: '//div[@class="generalbody"]/table//td[@align="center"]/a/img', 
    307296        linkElement: '//div[@class="generalbody"]/table//td[@align="center"]/a', 
    308297        popupElement: '//div[@class="search-results"][position()<4]', 
    309         style : { 
    310             border : 'solid 1px black', 
    311             padding : '4px', 
    312             fontSize : '80%' 
     298        style: { 
     299            border: '1px solid black', 
     300            padding: '4px', 
     301            fontSize: '80%' 
    313302        } 
    314303    }, 
    315304    { 
    316305        description: 'Youtube in Hatena Bookmark', 
    317         url: '^http://b\\.hatena\\.ne\\.jp/.*', 
     306        url: '^http://b\\.hatena\\.ne\\.jp/', 
    318307        linkElement: '//a[contains(@href,"youtube.com/") and contains(text(),"users")]', 
    319308        popupElement: 'id("video")', 
     
    348337        // Right 
    349338        popupAreaObj.style.left = targetDimension.left + targetDimension.width + 'px'; 
    350         popupAreaObj.style.top = targetDimension.top +  'px'; 
     339        popupAreaObj.style.top = targetDimension.top + 'px'; 
    351340        var dimension = getDimension(this); 
    352341        if (dimension.width > targetDimension.offsetRight) popupAreaObj.style.width = targetDimension.offsetRight + 'px'; 
     
    371360    if (popupAreaObj._currentTarget == target) this.style.display = 'none'; 
    372361}; 
    373 popupAreaObj.append = function (elm) { 
     362popupAreaObj.append = function(elm) { 
    374363    while (this.childNodes.length > 0) this.removeChild(this.firstChild); 
    375364    this.appendChild(elm); 
    376 } 
     365}; 
    377366popupAreaObj._currentTarget = null; 
    378367 
    379 function PopupManager () { 
    380     this.init = function () { 
     368function PopupManager() { 
     369    this.init = function() { 
    381370        document.body.appendChild(popupAreaObj); 
    382371        this.maxZIndex = 0; 
     
    388377            } 
    389378        } 
    390         popupAreaObj.style.zIndex = this.maxZIndex + 2; 
     379        popupAreaObj.style.zIndex = this.maxZIndex + 2; 
    391380 
    392381        for (var i in SITEINFO) { 
    393382            if (SITEINFO[i].disabled) continue; 
    394             if (!location.href.match(new RegExp(SITEINFO[i].url)) || (SITEINFO[i].excludeUrl && location.href.match(new RegExp(SITEINFO[i].excludeUrl)))) continue;  
     383            if (!location.href.match(new RegExp(SITEINFO[i].url)) || (SITEINFO[i].excludeUrl && location.href.match(new RegExp(SITEINFO[i].excludeUrl)))) continue; 
    395384            var targetElementList = getElementsByXPath((SITEINFO[i].targetElement)?SITEINFO[i].targetElement:SITEINFO[i].linkElement); 
    396385            var linkElementList = getElementsByXPath(SITEINFO[i].linkElement); 
     
    409398                    if (rule.pattern && rule.replacement) url = url.replace(new RegExp(rule.pattern), rule.replacement); 
    410399                } 
    411                 this.setEvent (targetElementList[j], url, SITEINFO[i].popupElement,  
     400                this.setEvent (targetElementList[j], url, SITEINFO[i].popupElement, 
    412401                    { 
    413402                        style:SITEINFO[i].style, 
     
    427416        targetElement.lock = function() { 
    428417            targetElement._locked = true; 
    429         } 
     418        }; 
    430419        targetElement.unlock = function(e) { 
    431420            targetElement._locked = false; 
    432421            if (targetElement._mouseOut) targetElement.removePopupElement(); 
    433         } 
     422        }; 
    434423 
    435424        targetElement.removePopupElement = function() { 
    436                     setTimeout(function () { 
     425                    setTimeout(function() { 
    437426                        if (!targetElement._mouseOut) return; 
    438427                        if (!targetElement._locked) popupAreaObj.hide(targetElement); 
    439428                    }, HIDE_DELAY_MSEC); 
    440              
    441         } 
    442         targetElement.addPopupElement = function () { 
     429 
     430        }; 
     431        targetElement.addPopupElement = function() { 
    443432            if (targetElement._elementCache != null) { 
    444433                popupAreaObj.append(targetElement._elementCache); 
     
    462451                            } 
    463452                        } 
    464                         if (option.containerHTML) { 
     453                        if (option.containerHTML) { 
    465454                            elmContainer.innerHTML = option.containerHTML; 
    466455                            var tmpList = elmContainer.getElementsByTagName('popup:container'); 
     
    470459                                } 
    471460                            } 
    472                         } else { 
     461                        } else { 
    473462                                for (var elementIndex in elementList) { 
    474463                                    elmContainer.appendChild(elementList[elementIndex]); 
    475464                                } 
    476                         } 
     465                        } 
    477466                        targetElement._elementCache = elmContainer; 
    478467                        elmContainer.addEventListener('mouseover', targetElement.lock, true); 
     
    482471                    } catch (ex) {} 
    483472                 } 
    484             } 
     473            }; 
    485474            http.send(null); 
    486475        }; 
    487476        targetElement.addEventListener ('mouseout', 
    488             function(){ 
     477            function() { 
    489478                try { 
    490479                    targetElement._mouseOut = true; 
    491480                    targetElement.removePopupElement(); 
    492                 } catch (ex){} 
     481                } catch (ex) {} 
    493482            }, 
    494483            true); 
    495484 
    496485        targetElement.addEventListener ('mouseover', 
    497             function(){ 
     486            function() { 
    498487                targetElement._mouseOut = false; 
    499                 setTimeout(function () { 
     488                setTimeout(function() { 
    500489                    if (targetElement._mouseOut) return; 
    501490                    targetElement.addPopupElement(); 
     
    503492            }, 
    504493            true); 
    505     } 
     494    }; 
    506495} 
    507496 
    508497(new PopupManager()).init(); 
    509498 
    510 function DimensionInfo (left, top, width, height) { 
     499function DimensionInfo(left, top, width, height) { 
    511500    this.top = top; 
    512501    this.left = left; 
     
    530519    var dimension; 
    531520    if (elm) { 
    532         dimension = new DimensionInfo(elm.offsetLeft,elm.offsetTop,elm.offsetWidth,elm.offsetHeight); 
     521        dimension = new DimensionInfo(elm.offsetLeft, elm.offsetTop, elm.offsetWidth, elm.offsetHeight); 
    533522        if (elm.offsetParent ) { 
    534523            tmp = _getDimension(elm.offsetParent); 
     
    545534 
    546535function createHTMLDocumentByString(str) { 
    547     var html = str.replace(/<!DOCTYPE.*?>/, '').replace(/<html.*?>/, '').replace(/<\/html>.*/, '') 
    548     var htmlDoc  = document.implementation.createDocument(null, 'html', null) 
    549     var fragment = createDocumentFragmentByString(html) 
     536    var html = str.replace(/<!DOCTYPE\s[^>]+>|<html(?:\s[^>]*)?>|<\/html\s*>.*/, ''); 
     537    var htmlDoc  = document.implementation.createDocument(null, 'html', null); 
     538    var fragment = createDocumentFragmentByString(html); 
    550539    try { 
    551         fragment = htmlDoc.adoptNode(fragment) 
    552     } catch(e) { 
    553         fragment = htmlDoc.importNode(fragment, true) 
    554     } 
    555     htmlDoc.documentElement.appendChild(fragment) 
    556    return htmlDoc 
     540        fragment = htmlDoc.adoptNode(fragment); 
     541    } catch (e) { 
     542        fragment = htmlDoc.importNode(fragment, true); 
     543    } 
     544    htmlDoc.documentElement.appendChild(fragment); 
     545    return htmlDoc; 
    557546} 
    558547 
    559548function createDocumentFragmentByString(str) { 
    560     var range = document.createRange() 
    561     range.setStartAfter(document.body) 
    562     return range.createContextualFragment(str) 
     549    var range = document.createRange(); 
     550    range.setStartAfter(document.body); 
     551    return range.createContextualFragment(str); 
    563552} 
    564553 
    565554function getElementsByXPath(xpath, node) { 
    566     var node = node || document 
    567     var doc = node.ownerDocument ? node.ownerDocument : node 
     555    var node = node || document; 
     556    var doc = node.ownerDocument ? node.ownerDocument : node; 
    568557    var nodesSnapshot = doc.evaluate(xpath, node, null, 
    569         XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null) 
    570     var data = [] 
    571     for (var i = 0; i < nodesSnapshot.snapshotLength; i++) { 
    572         data.push(nodesSnapshot.snapshotItem(i)) 
    573     } 
    574     return data 
    575 } 
     558        XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 
     559    var data = []; 
     560    for (var i = 0, l = nodesSnapshot.snapshotLength; i < l; i++) { 
     561        data.push(nodesSnapshot.snapshotItem(i)); 
     562    } 
     563    return data; 
     564}