Changeset 31392


Ignore:
Timestamp:
2017-02-09T10:40:39+13:00 (7 years ago)
Author:
davidb
Message:

Support for Catalog page added

File:
1 edited

Legend:

Unmodified
Added
Removed
  • other-projects/hathitrust/wcsa/vol-checker/WebContent/HT-HTRC_Mashup.user.js

    r31350 r31392  
    1010// @match       https://babel.hathitrust.org/cgi/ls*
    1111// @match       https://babel.hathitrust.org/cgi/mb*
     12// @match       https://catalog.hathitrust.org/Search/Home*
    1213// ==/UserScript==
    1314
     
    3031    var input=$('#q1-input').val();
    3132    if (input === "") {
    32                 return;
    33         }
     33                    return;
     34            }
    3435    event.preventDefault();
    3536
     
    4647
    4748    for (var i=0; i<word_len; i++) {
    48                 var word = input_words[i];
    49                 if (i>0) { full_url += "%2C"; } // append comma
    50                 full_url += word_front + word + word_end;
    51             }
     49                    var word = input_words[i];
     50                    if (i>0) { full_url += "%2C"; } // append comma
     51                    full_url += word_front + word + word_end;
     52                }
    5253
    5354    full_url += url_end;
     
    6566    var $login_button = $('#login-button');
    6667    if ($login_button.length) {
    67                 $login_button.css('font-size','95%');
    68                 $login_button.css('right','-45px');
    69                 $login_button.css('width','80px');
    70             }
     68                    $login_button.css('font-size','95%');
     69                    $login_button.css('right','-45px');
     70                    $login_button.css('width','80px');
     71                }
    7172    }
    7273
     
    8990    var $results_a = $('#results_A');
    9091    var results_a_exists = $results_a.length;
     92
     93    var result_class=".result";
     94    var result_access_link_class=".result-access-link";
    9195
    9296    if (!results_a_exists) {
     
    98102    }
    99103
     104     if (!results_a_exists) {
     105     // Perhaps a catalog page search?
     106         $results_a = $('form[name="addForm"]');
     107         results_a_exists = $results_a.length;
     108         result_class = ".resultitem";
     109         result_access_link_class = ".AccessLink";
     110    }
     111
    100112    if (results_a_exists) {
    101113    //console.log("*** results_a = " + $results_a.html());
     
    104116    //var file_safe_ids = [];
    105117
    106     $results_a.find('.result').each(function() {
    107                 var $result_access_link = $(this).find('.result-access-link');
    108                 //console.log("*** result access link = " + $result_access_link.html());
    109 
    110                 var $id_link = $result_access_link.find('ul>li>a').first();
    111                 //console.log("*** id_link = " + $id_link.html());
    112                 var data_clicklog = $id_link.attr("data_clicklog");
    113                 //console.log("*** data clicklog= " + data_clicklog);
    114 
    115                 var data_json_str = data_clicklog.replace(/^[a-z]+\|/,"");
    116                 //console.log("*** data json= " + data_json_str);
    117 
    118                 var id = null;
    119                 if (data_json_str !== "") {
    120                 var data_json = JSON.parse(data_json_str);
    121                 id = data_json.id;
    122                 //console.log("*** (catalog extracted) id= '" + id + "'");
    123                     }
    124                 else {
    125                 var $second_id_link = $result_access_link.find('ul>li>a').eq(1);
    126                 console.log("*** 2nd link len = " + $second_id_link);
    127                 var id_href = $second_id_link.attr("href");
    128                 console.log("*** id href = " + id_href);
    129                 id = id_href.replace(/^.*id=/,"");
    130                     }
    131 
    132                 ids.push(id);
    133                 //var file_safe_id = id.replace(/:/g,"+").replace(/\//g,"=");
    134                 //file_safe_ids.push(file_safe_id);
    135 
    136                 $result_access_link.attr("id","htrc-mashup-" + id);
    137                 //$result_access_link.attr("id","htrc-mashup-" + file_safe_id);
    138 
    139             });
     118    //$results_a.find('.result').each(function() {
     119    //            var $result_access_link = $(this).find('.result-access-link');
     120
     121    $results_a.find(result_class).each(function() {
     122                    var $result_access_link = $(this).find(result_access_link_class);
     123
     124                    //console.log("*** result access link = " + $result_access_link.html());
     125
     126                    var $id_link = $result_access_link.find('ul>li>a').first();
     127                    //console.log("*** id_link = " + $id_link.html());
     128                    var data_clicklog = $id_link.attr("data_clicklog");
     129                if (!data_clicklog) {
     130                    // fake one from the second <a> href (if present)
     131                    $id_link2 = $result_access_link.find('ul>li>a:eq(1)');
     132                    if ($id_link2.length>0) {
     133                        //console.log("*** id_link2 = " + $id_link2.html());
     134                        var id2_href = $id_link2.attr("href");
     135                        var id2 = id2_href.replace(/^https:\/\/hdl.handle.net\/\d+\//,"");
     136                        data_clicklog = "{\"id\":\"" + id2 + "\"}";
     137                    }
     138                    else {
     139                        data_clicklog="";
     140                    }
     141                }
     142                    //console.log("*** data clicklog= " + data_clicklog);
     143
     144
     145                    var data_json_str = data_clicklog.replace(/^[a-z]+\|/,"");
     146                    //console.log("*** data json= " + data_json_str);
     147
     148                    var id = null;
     149                    if (data_json_str !== "") {
     150                    var data_json = JSON.parse(data_json_str);
     151                    id = data_json.id;
     152                    //console.log("*** (catalog extracted) id= '" + id + "'");
     153                        }
     154                    else {
     155                    var $second_id_link = $result_access_link.find('ul>li>a').eq(1);
     156                    //console.log("*** 2nd link len = " + $second_id_link);
     157                    var id_href = $second_id_link.attr("href");
     158                    //console.log("*** id href = " + id_href);
     159                    if (id_href) {
     160                        //console.log("*** id href = " + id_href);
     161                        var encoded_id = id_href.replace(/^.*id=/,"");
     162                        id = decodeURIComponent(encoded_id);
     163                    }
     164                }
     165                if (id) {
     166                    ids.push(id);
     167
     168                    //var file_safe_id = id.replace(/:/g,"+").replace(/\//g,"=");
     169                    //file_safe_ids.push(file_safe_id);
     170
     171                    $result_access_link.attr("id","htrc-mashup-" + id);
     172                    //$result_access_link.attr("id","htrc-mashup-" + file_safe_id);
     173                }
     174                });
    140175
    141176    var ids_str = ids.join(",");
     
    147182    console.log("**** Away to request: " + https_servlet_url + "VolumeCheck?ids=" + encodeURIComponent(ids_str));
    148183
    149     var encoded_ids=encodeURIComponent(ids_str);
    150     var full_url = https_servlet_url + "VolumeCheck?ids=" + encoded_ids;
    151 
    152     $.ajax(full_url)
     184    var check_ids_url = https_servlet_url + "VolumeCheck";
     185    //var check_data = { "ids": encodeURIComponent(ids_str) };
     186    var check_data = { "ids": ids_str };
     187
     188    $.post(check_ids_url,check_data)
    153189        .done(function(data,textStatus,response) {
    154190        console.log("Adding in HTRC cross-checks");
    155191        var ids_exist = data;
    156192        for (var k in ids_exist) {
    157             //console.log("*** k = '" + k + "'");
    158 
    159             //var id_str = '#htrc-mashup-'+k;
    160             //console.log("*** id str = " + id_str);
    161             // var $id_div = $(id_str);
    162            
    163             //var $id_div = $('#'+'htrc-mashup-'+k);
    164             var id_div = document.getElementById('htrc-mashup-'+k);
    165             //console.log("*** id_div = " + id_div);
    166             var $id_div = $(id_div);
    167 
    168             if (ids_exist[k]) {
    169             var encoded_id=encodeURIComponent(k);
    170             var ef_url = https_servlet_url + "VolumeCheck?download-id=" + encoded_id;
    171             var atag = "<a href=\""+ ef_url +"\"><span class=\"icomoon icomoon-download\"></span>Download Extracted Features</a>";
    172 
    173             $id_div.find("ul").append("<li title=\""+k+"\" style=\"color: #924a0b;\">"+atag+"</li>"); // ✓
     193                //console.log("*** k = '" + k + "'");
     194
     195                //var id_str = '#htrc-mashup-'+k;
     196                //console.log("*** id str = " + id_str);
     197                // var $id_div = $(id_str);
     198
     199                //var $id_div = $('#'+'htrc-mashup-'+k);
     200                var id_div = document.getElementById('htrc-mashup-'+k);
     201                //console.log("*** id_div = " + id_div);
     202                var $id_div = $(id_div);
     203
     204                if (ids_exist[k]) {
     205                var encoded_id=encodeURIComponent(k);
     206                var ef_url = https_servlet_url + "VolumeCheck?download-id=" + encoded_id;
     207                var atag = "<a href=\""+ ef_url +"\"><span class=\"icomoon icomoon-download\"></span>Download Extracted Features</a>";
     208
     209                $id_div.find("ul").append("<li title=\""+k+"\" style=\"color: #924a0b;\">"+atag+"</li>"); // ✓
     210                    }
     211                else {
     212                // ✗, ✘
     213                $id_div.find("ul").append("<li title=\""+k+"\" style=\"color: red;\">HTRC unfriendly ✘</li>");
     214                    }
     215
     216                //console.log("*** id div len = " + $id_div.length);
     217
     218                //$.append("<li>HTRC friendly</li>");
    174219            }
    175             else {
    176             // ✗, ✘
    177             $id_div.find("ul").append("<li title=\""+k+"\" style=\"color: red;\">HTRC unfriendly ✘</li>");
    178             }
    179 
    180             //console.log("*** id div len = " + $id_div.length);
    181 
    182             //$.append("<li>HTRC friendly</li>");
    183         }
    184         })
     220            })
    185221        .fail(function(esponse,textStatus,errorThrown) {
    186222        alert( "error:"  + errorThrown);
    187         });
     223            });
    188224
    189225
     
    200236    var $workset_download_button = $('#col-to-workset-download');
    201237    $workset_download_button.click(function(event) {
    202             event.preventDefault();
     238                event.preventDefault();
    203239
    204240        var action = $download_form.attr("action");
    205241        //var action_url = action;
    206242
    207     var action_url = https_servlet_url + "VolumeCheck";
     243        var action_url = https_servlet_url + "VolumeCheck";
    208244
    209245        // Extract hidden elems from, e.g.
    210     //   <input type="hidden" name="c" value="464226859" />
     246        //   <input type="hidden" name="c" value="464226859" />
    211247        //   <input type="hidden" name="a" value="download" />
    212248        //   <input type="hidden" name="format" value="text" />
     
    223259
    224260            var $hidden_input = $(hidden_input);
    225         var hi_name = $hidden_input.attr("name");
    226         var hi_val  = $hidden_input.attr("value");
    227         if (hi_name === "c") {
    228         hi_name = "convert-col";
    229         }
    230             action_url += hi_name + "=" + hi_value;
     261            var hi_name = $hidden_input.attr("name");
     262            var hi_val  = $hidden_input.attr("value");
     263            if (hi_name === "c") {
     264            hi_name = "convert-col";
     265                }
     266            action_url += hi_name + "=" + hi_val;
    231267
    232268        }
    233269
    234 
    235         console.log("workset download url: " + action_url);
    236         window.location.href = action_url;
    237         });
     270        // <title>Collections: Ancestry and Genealogy | HathiTrust Digital Library</title>
     271        var all_col_title = $('title').text();
     272        var col_title = all_col_title.replace(/^Collections: /,"").replace(/ \|.*?$/,"");
     273        action_url += "&col-title=" + encodeURIComponent(col_title);
     274
     275            console.log("workset download url: " + action_url);
     276            window.location.href = action_url;
     277            });
    238278
    239279    }
Note: See TracChangeset for help on using the changeset viewer.