Changeset 5971

Show
Ignore:
Timestamp:
02/01/08 00:40:50 (5 years ago)
Author:
hetappi
Message:

lang/javascript/userscripts/crossbooksearch.user.js: added a part of code to deal with strange sites, that needed to open the detail page with post method, like the edogawa city library

Files:
1 modified

Legend:

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

    r5963 r5971  
    2525// @include        http://books.yahoo.co.jp/book_detail/* 
    2626// @include        http://www.asahiya.com/book_search/book_search_BookDetail.asp 
     27// @include        http://lib.city.shinagawa.tokyo.jp/cgi-bin/Sopcsvis.sh 
    2728// ==/UserScript== 
    2829 
     
    127128      xpaths: { 
    128129        isbn10: '//table[@class="BookDetails"]//tr[contains(th/text(), "ISBN")]/td[string-length(text())=10]/text()' 
     130    } }, 
     131    { url: "^http://lib\\.city\\.shinagawa\\.tokyo\\.jp/cgi-bin/Sopcsvis\\.sh", 
     132      xpaths: { 
     133        isbn10: 'translate(//tr[contains(td, "ISBN")]/td[3], "-", "")' 
    129134    } } 
    130135  ]; 
     
    184189                  }, 
    185190                  funcs: { 
    186                     detail: function(html, lib) { 
    187                       return ( 
    188                         /dispDetail\((\d+),0,0\)/.test(html) 
    189                           ? catUrl([lib.url, lib.context, 'Sopcsvis.sh?hit_cnt=1&idx=1&kgrn=0&ryno=&tso=on&ksno=']) + RegExp.$1 
    190                           : null); 
     191                      detail: function(html, lib) { 
     192                        return (/dispDetail\((\d+),0,0\)/.test(html) 
     193                          // deprecated: informal format 
     194                          ? { 
     195                            method: 'post', 
     196                            url: catUrl([lib.url, lib.context, 'Sopcsvis.sh']), 
     197                            params: 'hit_cnt=1&idx=1&kgrn=0&ryno=&tso=on&ksno=' + RegExp.$1 
     198                          } 
     199                          : null 
     200                        ); 
     201//                    detail: function(html, lib) { 
     202//                      return ( 
     203//                        /dispDetail\((\d+),0,0\)/.test(html) 
     204//                          ? catUrl([lib.url, lib.context, 'Sopcsvis.sh?hit_cnt=1&idx=1&kgrn=0&ryno=&tso=on&ksno=']) + RegExp.$1 
     205//                          : null); 
    191206                } } } 
    192207              ] 
     
    532547      cursor: move; 
    533548    } 
     549    div.cbs_link_enabled { 
     550      display:inline; 
     551      cursor: pointer; 
     552      text-decoration: underline; 
     553      font-size: 12px; 
     554      color: blue; 
     555    } 
     556    div.cbs_link_enabled:hover { 
     557      text-decoration: underline; 
     558    } 
     559    div.cbs_link_notenabled { 
     560      display:inline; 
     561      cursor: pointer; 
     562      text-decoration: underline; 
     563      font-size: 12px; 
     564      color: gray; 
     565    } 
     566    div.cbs_link_notenabled:hover { 
     567      text-decoration: underline; 
     568    } 
    534569  ]]></css>; 
    535570 
     
    683718    targets = eval(targets); 
    684719    var names = keys(targets); 
    685  
     720    var resps = {}; 
    686721    next(); 
    687722 
    688723    function response(resp) { 
    689724      GM_log(arguments.callee.name); 
    690       GM_log(resp.name + ', ' + resp.owned + ', ' + resp.enabled + ', ' + resp.detail); 
     725      GM_log( 
     726        resp.name + ', ' + resp.owned + ', ' + resp.enabled + ', ' + 
     727        (typeof resp.detail == 'string' ? resp.detail : uneval(resp.detail))); 
    691728 
    692729      var unit = document.createElement('div'); 
    693730      unit.className = 'cbs_unit'; 
    694731 
    695       if (resp.owned) { 
    696         var txt = resp.name; 
    697         if (resp.price) 
    698           txt += '(' + resp.price + ')'; 
    699         var link = document.createElement('a'); 
    700         link.className = resp.enabled ? 'cbs_enabled' : 'cbs_notenabled'; 
    701         link.href = resp.detail; 
    702         link.appendChild(document.createTextNode(txt)); 
    703         unit.appendChild(link); 
    704       } else { 
    705         unit.appendChild(document.createTextNode(resp.name)); 
    706       } 
     732      var link = (function(r) { 
     733        if (r.owned) { 
     734          var txt = r.name; 
     735          if (r.price) 
     736            txt += '(' + r.price + ')'; 
     737          if (typeof r.detail == 'string') { 
     738            var link = document.createElement('a'); 
     739            link.className = r.enabled ? 'cbs_enabled' : 'cbs_notenabled'; 
     740            link.href = r.detail; 
     741            link.appendChild(document.createTextNode(txt)); 
     742            return link; 
     743          } else { 
     744            var link = document.createElement('div'); 
     745            link.className = r.enabled ? 'cbs_link_enabled' : 'cbs_link_notenabled'; 
     746            link.id = resp.key; 
     747            link.appendChild(document.createTextNode(txt)); 
     748            link.addEventListener('click', function(e) { 
     749              request(resps[e.currentTarget.id].detail); 
     750            }, false); 
     751            return link; 
     752          } 
     753        } else { 
     754          return document.createTextNode(r.name); 
     755        } 
     756      })(resp); 
     757 
     758      unit.appendChild(link); 
    707759      bar.lastChild.appendChild(unit); 
     760 
     761      resps[resp.key] = resp; 
    708762      next(); 
    709763    } 
     
    721775      var cs = name.split('.'); 
    722776      var target = LIBINFO[cs[0]][cs[1]].targets[cs[2]]; 
    723       GM_log(target.name); 
     777      target.key = name; 
    724778 
    725779      target.func(book, target, response); 
     
    731785    var ks = []; 
    732786    for (var key in obj) { 
    733       GM_log('key: ' + key); 
    734787      ks.push(key); 
    735       } 
    736       GM_log('ks.length: ' + ks.length); 
     788    } 
    737789    return ks; 
    738790  } 
     
    771823  } 
    772824 
     825  function request(req) { 
     826    var form = document.createElement('form'); 
     827    form.id = 'cbs_form'; 
     828    form.method = req.method || 'get'; 
     829    form.action = req.url; 
     830    form.target = '_blank'; 
     831 
     832    if (req.params) { 
     833      for (var pairs = req.params.split('&'), i = 0, m = pairs.length; i < m; ++i) { 
     834        var pair = pairs[i].split('='); 
     835        var input = document.createElement('input'); 
     836        input.type = 'hidden'; 
     837        input.name = pair[0]; 
     838        input.value = pair.length > 1 ? pair[1] : ''; 
     839        form.appendChild(input); 
     840      } 
     841    } 
     842 
     843    document.body.appendChild(form); 
     844    form.submit(); 
     845    document.body.removeChild(form); 
     846  } 
     847 
    773848  // patternA 
    774849  // chuo, nerima, arakawa, setagaya, toshima 
     
    777852    GM_log(lib.name); 
    778853 
    779     var result = { name: lib.name }; 
     854    var result = { key: lib.key, name: lib.name }; 
    780855    var isbn = getIsbn(lib.keys, book); 
    781856    if (!isbn) { 
     
    833908    GM_log(lib.name); 
    834909 
    835     var result = { name: lib.name }; 
     910    var result = { key: lib.key, name: lib.name }; 
    836911    var isbn = getIsbn(lib.keys, book); 
    837912    if (!isbn) { 
     
    880955    GM_log(lib.name); 
    881956 
    882     var result = { name: lib.name }; 
     957    var result = { key: lib.key, name: lib.name }; 
    883958    var isbn = getIsbn(lib.keys, book); 
    884959    if (!isbn) {