<commit_before>/**
 * @fileOverview Interfaces the application with its current architecture.
 * This could be an extension, mobile app, or a hosted web server.
 *
 **/
 
/**
 * @namespace
 */
var privlyNetworkService = {
  
  /**
   * Permissions the user may have on creating and updating content.
   * Each of these permissions are associated with a network request.
   * They should only be set to "true" if the associated get/post/delete
   * request could be made without harming the remote server. You can usually
   * establish that the request will not harm data stored remotely by 
   * doing a get request that affirms the user's right to perform certain
   * operations.
   */
  permissions: {
    canCreate: false,
    canDestroy: false,
    canUpdate: false,
    canShare: false,
    canShow: false
  },
  
  /**
   * If this variable is assigned, it will be appended as a get parameter
   * on all requests, eg, `?auth_token=AUTH_TOKEN_HERE`. This should never
   * be referenced by anything but the auth token setters.
   */
  authToken: "",
  
  /**
   * Set the authentication token if a parameter is supplied, or the
   * current platform has a setter function. This may be called from the
   * context of mobile applications or browser extensions.
   */
  setAuthTokenString: function(authTokenString) {
    if (authTokenString !== undefined) {
      privlyNetworkService.authToken = "auth_token=" + authTokenString;
    } else if(privlyNetworkService.platformName() === "ANDROID") {
      privlyNetworkService.authToken = "auth_token=" + 
                                              androidJsBridge.fetchAuthToken();
    }
  },
  
  /**
   * Adds the auth token to the current URL. If the auth token has not been
   * assigned, nothing is added. If the auth token is assigned, it is added
   * as a get parameter.
   *
   * @param string url the URL that may need an auth token added.
   *
   */
  getAuthenticatedUrl: function(url) {
    
    // get the parameter string for the auth token
    privlyNetworkService.setAuthTokenString();
    
    // Don't change the URL if there is no auth token, or the URL
    // is not for the content server
    if( privlyNetworkService.authToken === "" || 
      url.indexOf(privlyNetworkService.contentServerDomain()) !== 0 ) {
      return url;
    }
    
    // if query parameters already exist on the URL
    if (url.indexOf("?") >= 0 && (url.indexOf("?") < url.indexOf("#") ||
      url.indexOf("#") === -1)) {
      return url.replace("?", "?" + privlyNetworkService.authToken + "&");
      
    // else if there is an anchor
    } else if(url.indexOf("#") >= 0) {
      return url.replace("#", "?" + privlyNetworkService.authToken + "#");
    } else {
      return url + "?" + privlyNetworkService.authToken;
    }
  },
  
  /**
   * Determines which platform the script is runing on. This helps determine
   * which request function should be used. The current values are "CHROME"
   * for the Google Chrome extension, and "HOSTED" for all other architectures.
   * HOSTED functions use standard same-origin AJAX requests.
   *
   * @return {string} the name of the platform.
   */
  platformName: function() {
    if (navigator.userAgent.indexOf("iPhone") >= 0 || navigator.userAgent.indexOf("iPad") >= 0) {
      return "IOS";
    } else if(typeof androidJsBridge !== "undefined") {
      return "ANDROID";
    }  else if (typeof chrome !== "undefined" && typeof chrome.extension !== "undefined") {
      return "CHROME";
    } else {
      return "HOSTED";
    }
  },
  
  /**
   * Helper for determining the protocol+domain of a
   * URL.
   *
   * @param {string} url the URL for which we want the domain and protocl
   * @return {string} The string of the protocol and domain.
   */
  getProtocolAndDomain: function(url) {
    var domainGrabber = document.createElement("a");
    domainGrabber.href = url;
    return domainGrabber.protocol + "//" + domainGrabber.host;
  },
  
  /**
   * The cross-site request forgery tokens for servers initialized via 
   * initPrivlyService.
   */<commit_msg>fixed platform name detection for iphone safari and uiwebview<commit_after>/**
 * @fileOverview Interfaces the application with its current architecture.
 * This could be an extension, mobile app, or a hosted web server.
 *
 **/
 
/**
 * @namespace
 */
var privlyNetworkService = {
  
  /**
   * Permissions the user may have on creating and updating content.
   * Each of these permissions are associated with a network request.
   * They should only be set to "true" if the associated get/post/delete
   * request could be made without harming the remote server. You can usually
   * establish that the request will not harm data stored remotely by 
   * doing a get request that affirms the user's right to perform certain
   * operations.
   */
  permissions: {
    canCreate: false,
    canDestroy: false,
    canUpdate: false,
    canShare: false,
    canShow: false
  },
  
  /**
   * If this variable is assigned, it will be appended as a get parameter
   * on all requests, eg, `?auth_token=AUTH_TOKEN_HERE`. This should never
   * be referenced by anything but the auth token setters.
   */
  authToken: "",
  
  /**
   * Set the authentication token if a parameter is supplied, or the
   * current platform has a setter function. This may be called from the
   * context of mobile applications or browser extensions.
   */
  setAuthTokenString: function(authTokenString) {
    if (authTokenString !== undefined) {
      privlyNetworkService.authToken = "auth_token=" + authTokenString;
    } else if(privlyNetworkService.platformName() === "ANDROID") {
      privlyNetworkService.authToken = "auth_token=" + 
                                              androidJsBridge.fetchAuthToken();
    }
  },
  
  /**
   * Adds the auth token to the current URL. If the auth token has not been
   * assigned, nothing is added. If the auth token is assigned, it is added
   * as a get parameter.
   *
   * @param string url the URL that may need an auth token added.
   *
   */
  getAuthenticatedUrl: function(url) {
    
    // get the parameter string for the auth token
    privlyNetworkService.setAuthTokenString();
    
    // Don't change the URL if there is no auth token, or the URL
    // is not for the content server
    if( privlyNetworkService.authToken === "" || 
      url.indexOf(privlyNetworkService.contentServerDomain()) !== 0 ) {
      return url;
    }
    
    // if query parameters already exist on the URL
    if (url.indexOf("?") >= 0 && (url.indexOf("?") < url.indexOf("#") ||
      url.indexOf("#") === -1)) {
      return url.replace("?", "?" + privlyNetworkService.authToken + "&");
      
    // else if there is an anchor
    } else if(url.indexOf("#") >= 0) {
      return url.replace("#", "?" + privlyNetworkService.authToken + "#");
    } else {
      return url + "?" + privlyNetworkService.authToken;
    }
  },
  
  /**
   * Determines which platform the script is runing on. This helps determine
   * which request function should be used. The current values are "CHROME"
   * for the Google Chrome extension, and "HOSTED" for all other architectures.
   * HOSTED functions use standard same-origin AJAX requests.
   *
   * @return {string} the name of the platform.
   */
  platformName: function() {
    if (navigator.userAgent.indexOf("iPhone") >= 0 || 
      navigator.userAgent.indexOf("iPad") >= 0) {
      if( navigator.userAgent.indexOf("Safari") >= 0 ) return "HOSTED";
      return "IOS";
    } else if(typeof androidJsBridge !== "undefined") {
      return "ANDROID";
    }  else if (typeof chrome !== "undefined" && typeof chrome.extension !== "undefined") {
      return "CHROME";
    } else {
      return "HOSTED";
    }
  },
  
  /**
   * Helper for determining the protocol+domain of a
   * URL.
   *
   * @param {string} url the URL for which we want the domain and protocl
   * @return {string} The string of the protocol and domain.
   */
  getProtocolAndDomain: function(url) {
    var domainGrabber = document.createElement("a");
    domainGrabber.href = url;
    return domainGrabber.protocol + "//" + domainGrabber.host;
  },
  
  /**
   * The cross-site request forgery tokens for servers initialized via 
   * initPrivlyService.
   */
{'fraction_non_alphanumeric': 0.10745799589024538, 'fraction_numerical': 0.0015713767677988637, 'mean_word_length': 2.814661134163209, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6597412', 'n_tokens_mistral': 2370, 'n_tokens_neox': 2319, 'n_words': 845}