<commit_before>(function () {

  'use strict';

  var oAuth2Info;
  var googleOAuth2Result;

  var onGoogleClientConfig;

  window.onClientLoad = function () {
    console.log("Getting OAuth2 info...");

    $.ajax({
      url: apiBaseUrl + '/oauth2',
      type: 'GET',
      dataType: 'json'
    })
    .fail(onAjaxError)
    .done(onGetOAuth2Info);
  };

  window.authorize = function () {
    console.log("Checking to see if the user has already granted access to RadBus...");

    setTimeout(function() {
      gapi.auth.authorize({
        client_id: oAuth2Info.client_id,
        scope: oAuth2Info.scopes,
        immediate: true
      }, onAuthResult);
    }, 1);
  };

  window.invokeOAuthAuthorization = function (accessType) {
    console.log("Calling the Googles to get authorization...");

    var redirectUri = window.location.protocol + '//' + window.location.host + '/oauth2callback';

    var oauthUrl = 'https://accounts.google.com/o/oauth2/auth' +
      '?client_id=' + encodeURIComponent(oAuth2Info.client_id) +
      '&scope=' + encodeURIComponent(oAuth2Info.scopes) +
      '&immediate=false' +
      '&response_type=code' +
      '&redirect_uri=' + encodeURIComponent(redirectUri) +
      '&access_type=' + accessType +
      '&state=' + accessType +
      '&approval_prompt=force';

    window.location = oauthUrl;
  };

  function onAjaxError (jqXHR, textStatus, errorThrown) {
    if (jqXHR.status == 401) {
      // token expired - authorize again
      authorize();
    } else {
      alert("ERROR: " + jqXHR.status + ": " + textStatus + ": " + errorThrown);
    }
  }

  function onGetOAuth2Info (data, textStatus, jqXHR) {
    console.log("Configuring the Google API client...");

    oAuth2Info = data;

    gapi.client.setApiKey(oAuth2Info.client_secret);

    // needs to implemented by the host page
    window.onGoogleClientConfig();
  }

  function onAuthResult (authResult) {
    var authorizeButton = $('#authorize-button');

    if (authResult && !authResult.error) {
      console.log("User has already granted access.");

      googleOAuth2Result = authResult;
      hide(authorizeButton);

      show($('#getting-departures'));
      checkSchedule()
        .fail(onFirstCheckScheduleFail);

      // refresh depatures
      $('#refreshButton').click(function () {
        show($('#getting-departures'));
        hide($('#no-bus-schedule'));
        hide($('#departures'));
        $('#departures-list').empty();

        checkSchedule()
          .fail(onFirstCheckScheduleFail);
      });

      // edit scheduels
      $('#toggle-schedule-button').click(function () {
        $('#edit-schedule').toggleClass('hidden').toggleClass('show');
      });

      // upsert schedule route
      var upsertScheduleRouteButton = $('#upsert-schedule-route-button');
      var upsertScheduleRouteError = $('#upsert-schedule-route-error');

      upsertScheduleRouteButton.click(function () {
        upsertScheduleRouteButton.text('Working...');
        upsertScheduleRouteButton.prop('disabled', true);
        hide(upsertScheduleRouteError);<commit_msg>Fix bug where no departures message persists after refreshing the departures.<commit_after>(function () {

  'use strict';

  var oAuth2Info;
  var googleOAuth2Result;

  var onGoogleClientConfig;

  window.onClientLoad = function () {
    console.log("Getting OAuth2 info...");

    $.ajax({
      url: apiBaseUrl + '/oauth2',
      type: 'GET',
      dataType: 'json'
    })
    .fail(onAjaxError)
    .done(onGetOAuth2Info);
  };

  window.authorize = function () {
    console.log("Checking to see if the user has already granted access to RadBus...");

    setTimeout(function() {
      gapi.auth.authorize({
        client_id: oAuth2Info.client_id,
        scope: oAuth2Info.scopes,
        immediate: true
      }, onAuthResult);
    }, 1);
  };

  window.invokeOAuthAuthorization = function (accessType) {
    console.log("Calling the Googles to get authorization...");

    var redirectUri = window.location.protocol + '//' + window.location.host + '/oauth2callback';

    var oauthUrl = 'https://accounts.google.com/o/oauth2/auth' +
      '?client_id=' + encodeURIComponent(oAuth2Info.client_id) +
      '&scope=' + encodeURIComponent(oAuth2Info.scopes) +
      '&immediate=false' +
      '&response_type=code' +
      '&redirect_uri=' + encodeURIComponent(redirectUri) +
      '&access_type=' + accessType +
      '&state=' + accessType +
      '&approval_prompt=force';

    window.location = oauthUrl;
  };

  function onAjaxError (jqXHR, textStatus, errorThrown) {
    if (jqXHR.status == 401) {
      // token expired - authorize again
      authorize();
    } else {
      alert("ERROR: " + jqXHR.status + ": " + textStatus + ": " + errorThrown);
    }
  }

  function onGetOAuth2Info (data, textStatus, jqXHR) {
    console.log("Configuring the Google API client...");

    oAuth2Info = data;

    gapi.client.setApiKey(oAuth2Info.client_secret);

    // needs to implemented by the host page
    window.onGoogleClientConfig();
  }

  function onAuthResult (authResult) {
    var authorizeButton = $('#authorize-button');

    if (authResult && !authResult.error) {
      console.log("User has already granted access.");

      googleOAuth2Result = authResult;
      hide(authorizeButton);

      show($('#getting-departures'));
      checkSchedule()
        .fail(onFirstCheckScheduleFail);

      // refresh depatures
      $('#refreshButton').click(function () {
        show($('#getting-departures'));
        hide($('#no-bus-schedule'));
        hide($('#departures'));
        hide($('#no-departures'));
        $('#departures-list').empty();

        checkSchedule()
          .fail(onFirstCheckScheduleFail);
      });

      // edit scheduels
      $('#toggle-schedule-button').click(function () {
        $('#edit-schedule').toggleClass('hidden').toggleClass('show');
      });

      // upsert schedule route
      var upsertScheduleRouteButton = $('#upsert-schedule-route-button');
      var upsertScheduleRouteError = $('#upsert-schedule-route-error');

      upsertScheduleRouteButton.click(function () {
        upsertScheduleRouteButton.text('Working...');
        upsertScheduleRouteButton.prop('disabled', true);
        hide(upsertScheduleRouteError);
{'fraction_non_alphanumeric': 0.14709163346613546, 'fraction_numerical': 0.006055776892430279, 'mean_word_length': 2.972151898734177, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '4788757', 'n_tokens_mistral': 1938, 'n_tokens_neox': 1879, 'n_words': 342}