<commit_before>console.log( "- josiah_easyscan.js START" );


var esyscn_flow_manager = new function() {
  /* Namespaces function calls.
   *
   * See <http://stackoverflow.com/a/881611> for module-pattern reference.
   * Only check_already_run() can be called publicly, and only via ```esyscn.check_already_run();```.
   *
   * Controller class flow description:
   * - Attempts to grab title from where it would be on an items-page -- FUTURE: don't grab title: always go for bibnumber
   * - If title blank, attempts to grab bibnumber from where it might be on a holdings-page
   * - If no bibnumber, attempts to grab bibnumber from bib-page's html, getting there via holdings page link
   * - Finds all item-rows and for each row:
   *   - Calls namespace `esyscn_row_processor` to process the row, which builds the links
   *   - Deletes item-barcode html
   *
   * Reference:
   * - items page: <http://josiah.brown.edu/record=b4069600>
   * - holdings page: <http://josiah.brown.edu/search~S7?/.b4069600/.b4069600/1,1,1,B/holdings~4069600&FF=&1,0,>
   * - results page: <http://josiah.brown.edu/search~S11/?searchtype=X&searcharg=zen&searchscope=11&sortdropdown=-&SORT=D&extended=1&SUBMIT=Search&searchlimits=&searchorigarg=tzen>
   */

  var cell_position_map = { "location": 0, "callnumber": 1, "availability": 2, "barcode": 3 };
  var bibnum = null;

  this.check_already_run = function() {
    /* Checks to see if javascript has already been run.
     * Called by document.ready()
     */
    var all_html = $("body").html().toString();  // jquery already loaded (whew)
    var index = all_html.indexOf( "Request Scan" );
    if (index != -1) {
      console.log( "- aready run" );
    } else {
      console.log( "- not already run" );
      grab_title();
    }
  }

  var grab_title = function() {
    /* Tries to grab bib title from `items` page; then continues processing.
     * Called by check_already_run()
     * FUTURE: no grabbing title, straight to attempted item-page bibnumber grab
     */
    var title = null;
    var els = document.querySelectorAll( ".bibInfoData" );
    if ( els.length > 0 ) {
      var el = els[0];
      title = el.textContent.trim();
    }
    console.log( "- title, " + title );
    if ( title == null ){
      grab_bib_from_holdings_html();
    } else {
      process_item_table( title );
    }
  }

  var grab_bib_from_holdings_html = function() {
    /* Tries to determine bibnum from holdings html; then continues processing.
     * Called by grab_title() if title is null.
     */
    var dvs = document.querySelectorAll(".additionalCopiesNav");  // first of two identical div elements
    if ( dvs.length > 0 ) {
      var dv = dvs[0];
      var el = dv.children[0];  // the div contains a link with the bibnum
      var text = el.toString();
      var t = text.split("/")[4];  // eg ".b4069600"
      if ( t.length == 9 && t.slice( 0,2 ) == ".b" ) {
        bibnum = t.slice( 1, 9 );  // updates module var
        console.log( "in grab_bib_from_holdings_html(); bibnum, " + bibnum );
        title = null;
        process_item_table( title );
      } else {
        grab_bib_from_holdings_html_2();
      }
    }
  }

  var grab_bib_from_holdings_html_2 = function() {
    /* Tries to load bib-page and grab bib from permalink element; then continues processing.
     * Called by grab_bib_from_holdings_html()
     */
    var dvs = document.querySelectorAll(".additionalCopiesNav");  // first of two identical div elements
    if ( dvs.length > 0 ) {
      var el = dvs[0].children[0];  // the div contains a link to the bib page
      var url = el.toString();
      $.ajaxSetup( {async: false} );  // otherwise "init" would immediately be returned while $.get makes it's request asynchronously
      $.get( url, function( data ) {
        div_temp = document.createElement( "div_temp" );
        div_temp.innerHTML = data;
        dvs_temp = div_temp.querySelectorAll( "#recordnum" );
        href = dvs_temp[0].href;
        bib_temp = href.split( "=" )[1];
        bibnum = bib_temp.slice( 0,8 );
        console.log( "- in grab_bib_from_holdings_html_2(); bib_num is, " + bibnum );
      } );
    }
    console.log( "- in grab_bib_from_holdings_html_2(); outside of if; bibnum is, " + bibnum );
    title = null;
    process_item_table( title );

  }

  // var grab_bib_from_holdings_html = function() {
  //   /* Tries to determine bibnum from holdings html; then continues processing.
  //    * Called by grab_title() if title is null.
  //    */
  //   var dvs = document.querySelectorAll(".additionalCopiesNav");  // first of two identical div elements
  //   if ( dvs.length > 0 ) {
  //     var dv = dvs[0];
  //     var el = dv.children[0];  // the div contains a link with the bibnum
  //     var text = el.toString();
  //     var t = text.split("/")[4];  // eg ".b4069600"
  //     bibnum = t.slice( 1, 9 );  // updates module var
  //   }
  //   console.log( "in grab_bib_from_holdings_html(); bibnum, " + bibnum );
  //   title = null;
  //   process_item_table( title );
  // }<commit_msg>refactors functions.<commit_after>console.log( "- josiah_easyscan.js START" );


var esyscn_flow_manager = new function() {
  /* Namespaces function calls.
   *
   * See <http://stackoverflow.com/a/881611> for module-pattern reference.
   * Only check_already_run() can be called publicly, and only via ```esyscn.check_already_run();```.
   *
   * Controller class flow description:
   * - Attempts to grab title from where it would be on an items-page -- FUTURE: don't grab title: always go for bibnumber
   * - If title blank, attempts to grab bibnumber from where it might be on a holdings-page
   * - If no bibnumber, attempts to grab bibnumber from bib-page's html, getting there via holdings page link
   * - Finds all item-rows and for each row:
   *   - Calls namespace `esyscn_row_processor` to process the row, which builds the links
   *   - Deletes item-barcode html
   *
   * Reference:
   * - items page: <http://josiah.brown.edu/record=b4069600>
   * - holdings page: <http://josiah.brown.edu/search~S7?/.b4069600/.b4069600/1,1,1,B/holdings~4069600&FF=&1,0,>
   * - results page: <http://josiah.brown.edu/search~S11/?searchtype=X&searcharg=zen&searchscope=11&sortdropdown=-&SORT=D&extended=1&SUBMIT=Search&searchlimits=&searchorigarg=tzen>
   */

  var cell_position_map = { "location": 0, "callnumber": 1, "availability": 2, "barcode": 3 };
  var bibnum = null;

  this.check_already_run = function() {
    /* Checks to see if javascript has already been run.
     * Called by document.ready()
     */
    var all_html = $("body").html().toString();  // jquery already loaded (whew)
    var index = all_html.indexOf( "Request Scan" );
    if (index != -1) {
      console.log( "- aready run" );
    } else {
      console.log( "- not already run" );
      grab_title();
    }
  }

  var grab_title = function() {
    /* Tries to grab bib title from `items` page; then continues processing.
     * Called by check_already_run()
     * FUTURE: no grabbing title, straight to attempted item-page bibnumber grab
     */
    var title = null;
    var els = document.querySelectorAll( ".bibInfoData" );
    if ( els.length > 0 ) {
      var el = els[0];
      title = el.textContent.trim();
    }
    console.log( "- title, " + title );
    if ( title == null ){
      check_holdings_html();
    } else {
      process_item_table( title );
    }
  }

  var check_holdings_html = function() {
    /* Looks for presence of bib-page link (link may or may not contain bibnum).
     * Called by grab_title() if title is null.
     */
    var dvs = document.querySelectorAll(".additionalCopiesNav");  // first of two identical div elements
    if ( dvs.length > 0 ) {
      var dv = dvs[0];
      var el = dv.children[0];  // the div contains a link with the bibnum
      var href_string = el.toString();
      console.log( "in check_holdings_html(); href_string, " + href_string );
      grab_bib_from_holdings_html( href_string )
    } else {
      title = null;
      process_item_table( title );
    }
  }

  var grab_bib_from_holdings_html = function( href_string ) {
    /* Tries to determine bibnum from holdings html; then continues processing.
     * Called by grab_title() if title is null.
     */
    var segment = href_string.split("/")[4];  // eg ".b4069600"
    if ( segment.length == 9 && segment.slice( 0,2 ) == ".b" ) {
      bibnum = segment.slice( 1, 9 );  // updates module var
      console.log( "in grab_bib_from_holdings_html(); bibnum, " + bibnum );
      title = null;
      process_item_table( title );
    } else {
      grab_bib_from_holdings_html_2( href_string );
    }
  }

  // var grab_bib_from_holdings_html = function() {
  //   /* Tries to determine bibnum from holdings html; then continues processing.
  //    * Called by grab_title() if title is null.
  //    */
  //   var dvs = document.querySelectorAll(".additionalCopiesNav");  // first of two identical div elements
  //   if ( dvs.length > 0 ) {
  //     var dv = dvs[0];
  //     var el = dv.children[0];  // the div contains a link with the bibnum
  //     var text = el.toString();
  //     var t = text.split("/")[4];  // eg ".b4069600"
  //     if ( t.length == 9 && t.slice( 0,2 ) == ".b" ) {
  //       bibnum = t.slice( 1, 9 );  // updates module var
  //       console.log( "in grab_bib_from_holdings_html(); bibnum, " + bibnum );
  //       title = null;
  //       process_item_table( title );
  //     } else {
  //       grab_bib_from_holdings_html_2();
  //     }
  //   }
  // }

  var grab_bib_from_holdings_html_2 = function( href_string ) {
    /* Tries to load bib-page and grab bib from permalink element; then continues processing.
     * Called by grab_bib_from_holdings_html()
     */
    $.ajaxSetup( {async: false} );  // otherwise processing would immediately continue while $.get() makes it's request asynchronously
    $.get( href_string, function(data) {
      var div_temp = document.createElement( "div_temp" );
      div_temp.innerHTML = data;
      var nodes = div_temp.querySelectorAll( "#recordnum" );
      var bib_href = nodes[0].href;
      var bib_temp = bib_href.split( "=" )[1];
      bibnum = bib_temp.slice( 0,8 );  // updates module's var
    } );
    console.log( "- in grab_bib_from_holdings_html_2(); outside of $.get(); bibnum is, " + bibnum );
    var title = null; process_item_table( title );
  }

  // var grab_bib_from_holdings_html_2 = function() {
  //   /* Tries to load bib-page and grab bib from permalink element; then continues processing.
  //    * Called by grab_bib_from_holdings_html()
  //    */
  //   var dvs = document.querySelectorAll(".additionalCopiesNav");  // first of two identical div elements
  //   if ( dvs.length > 0 ) {
  //     var el = dvs[0].children[0];  // the div contains a link to the bib page
  //     var url = el.toString();
  //     $.ajaxSetup( {async: false} );  // otherwise "init" would immediately be returned while $.get makes it's request asynchronously
  //     $.get( url, function( data ) {
  //       div_temp = document.createElement( "div_temp" );
  //       div_temp.innerHTML = data;
  //       dvs_temp = div_temp.querySelectorAll( "#recordnum" );
  //       href = dvs_temp[0].href;
  //       bib_temp = href.split( "=" )[1];
  //       bibnum = bib_temp.slice( 0,8 );
  //       console.log( "- in grab_bib_from_holdings_html_2(); bib_num is, " + bibnum );
  //     } );
  //   }
  //   console.log( "- in grab_bib_from_holdings_html_2(); outside of if; bibnum is, " + bibnum );
  //   title = null;
  //   process_item_table( title );
  // }

  // var grab_bib_from_holdings_html = function() {
  //   /* Tries to determine bibnum from holdings html; then continues processing.
  //    * Called by grab_title() if title is null.
  //    */
  //   var dvs = document.querySelectorAll(".additionalCopiesNav");  // first of two identical div elements
  //   if ( dvs.length > 0 ) {
  //     var dv = dvs[0];
  //     var el = dv.children[0];  // the div contains a link with the bibnum
  //     var text = el.toString();
  //     var t = text.split("/")[4];  // eg ".b4069600"
  //     bibnum = t.slice( 1, 9 );  // updates module var
  //   }
  //   console.log( "in grab_bib_from_holdings_html(); bibnum, " + bibnum );
  //   title = null;
  //   process_item_table( title );
  // }
{'fraction_non_alphanumeric': 0.13669472321139528, 'fraction_numerical': 0.01675299449660084, 'mean_word_length': 2.5921511627906977, 'pattern_counts': {'":': 8, '<': 11, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2119134', 'n_tokens_mistral': 4281, 'n_tokens_neox': 4002, 'n_words': 1114}