Changeset 18667

Show
Ignore:
Timestamp:
09/02/08 22:21:06 (4 months ago)
Author:
maripo
Message:

エラー時(該当ノードがない/HTTPエラー)の処理追加

Files:
1 modified

Legend:

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

    r18622 r18667  
    292920080824 0.0.9 "excludeUrl" option 
    3030               Add 2 rules to SITEINFO (Yahoo! Chiebukuro, Hatena Keyword) 
     3120080824 0.0.10 Error handling (HTTP error / HTML node error) 
     32               Add a rule (Tabelog) 
     33 
    3134*/ 
    3235 
    33 var VERSION = '0.0.9'; 
     36var VERSION = '0.0.10'; 
    3437var DEFAULT_DELAY_MSEC = 400; 
    3538var HIDE_DELAY_MSEC = 400; 
    3639var DEBUG_MODE = false; 
     40var ERROR_MESSAGE_POPUP_ELEMENT_EMPTY = 'Error : No such node'; 
     41var ERROR_MESSAGE_HTTP = 'HTTP Error'; 
    3742 
    3843var popupTil = null; 
     44 
    3945 
    4046// == IMAGE == 
     
    313319            background: 'black', 
    314320            fontSize: '80%' 
     321        } 
     322    }, 
     323    { 
     324        description: 'Tabelog', 
     325        url: '^http://r\\.tabelog\\.com/.*', 
     326        linkElement: 'id("column-main")//div[@class="photo"]/a', 
     327        popupElement: 'id("column-main")//div[@class="menulst"][position()=1]/div[@class="item"][position()<6]', 
     328        delay: 500, 
     329        //stripe: true, 
     330        linkReplaceRule: { 
     331            pattern: '/rstdtl/', 
     332            replacement: '/rstdtlmenu/' 
     333        }, 
     334        style: { 
     335            padding: '4px', 
     336            background: 'white', 
     337            textAlign: 'left', 
     338            fontSize: '90%', 
     339            border: '1px solid #444' 
    315340        } 
    316341    } 
     
    440465                 if (http.readyState == 4) { 
    441466                    try { 
    442                         popupAreaObj._currentTarget = targetElement; 
    443                         var text = http.responseText; 
    444                         var xml = createHTMLDocumentByString(text); 
    445                         var elmContainer = document.createElement('DIV'); 
    446                         var elementList = getElementsByXPath(popupElementXPath, xml); 
    447                         // apply style 
    448                         if (option.style) { 
    449                             for (var j in option.style) { 
    450                                 elmContainer.style[j] = option.style[j]; 
    451                             } 
    452                         } 
    453                         if (option.containerHTML) { 
    454                             elmContainer.innerHTML = option.containerHTML; 
    455                             var tmpList = elmContainer.getElementsByTagName('popup:container'); 
    456                             if (tmpList.length == 1) { 
    457                                 for (var elementIndex in elementList) { 
    458                                     tmpList[0].parentNode.insertBefore(elementList[elementIndex], tmpList[0]); 
     467                            popupAreaObj._currentTarget = targetElement; 
     468                            var text = http.responseText; 
     469                            var xml = createHTMLDocumentByString(text); 
     470                            var elmContainer = document.createElement('DIV'); 
     471                            // apply style 
     472                            if (option.style) { 
     473                                for (var j in option.style) { 
     474                                    elmContainer.style[j] = option.style[j]; 
    459475                                } 
    460476                            } 
    461                         } else { 
    462                                 for (var elementIndex in elementList) { 
    463                                     elmContainer.appendChild(elementList[elementIndex]); 
     477                            if (http.status == 200) { 
     478                                var elementList = getElementsByXPath(popupElementXPath, xml); 
     479 
     480                                if (elementList.length > 0) { 
     481                                    // "popupElement" found 
     482                                    if (option.containerHTML) { 
     483                                        elmContainer.innerHTML = option.containerHTML; 
     484                                        var tmpList = elmContainer.getElementsByTagName('popup:container'); 
     485                                        if (tmpList.length == 1) { 
     486                                            for (var elementIndex in elementList) { 
     487                                                tmpList[0].parentNode.insertBefore(elementList[elementIndex], tmpList[0]); 
     488                                            } 
     489                                        } 
     490                                    } else { 
     491                                            for (var elementIndex in elementList) { 
     492                                                elmContainer.appendChild(elementList[elementIndex]); 
     493                                            } 
     494                                    } 
     495                                } else { 
     496                                    // nothing matched to "popupElement" 
     497                                    elmContainer.appendChild(document.createTextNode(ERROR_MESSAGE_POPUP_ELEMENT_EMPTY)); 
    464498                                } 
    465                         } 
    466                         targetElement._elementCache = elmContainer; 
    467                         elmContainer.addEventListener('mouseover', targetElement.lock, true); 
    468                         elmContainer.addEventListener('mouseout', targetElement.unlock, true); 
    469                         popupAreaObj.append(elmContainer); 
    470                         popupAreaObj.show(targetElement); 
     499                                targetElement._elementCache = elmContainer; 
     500                            } else { 
     501                                // HTTP Error 
     502                                elmContainer.appendChild(document.createTextNode(ERROR_MESSAGE_HTTP + http.status)); 
     503                            } 
     504                            elmContainer.addEventListener('mouseover', targetElement.lock, true); 
     505                            elmContainer.addEventListener('mouseout', targetElement.unlock, true); 
     506                            popupAreaObj.append(elmContainer); 
     507                            popupAreaObj.show(targetElement); 
    471508                    } catch (ex) {} 
    472509                 }