<commit_before>/**
 * ajax.js
 * @author <NAME> [Ajnasz] {@link http://ajnasz.hu http://ajnasz.hu} <EMAIL>
 * @license GPL v2
 * for more detials see the licence.txt file
 */
/**
 * Creates an AJAX request
 * @author <NAME> [Ajnasz] http://ajnasz.hu <EMAIL>
 * @class HupAjax sends request to the {@link http://hup.hu hup.hu} site
 * @constructor
 * @param {Object} pars object to overwrite the default parameters
 */
var HupAjax = function(pars, el) {
  if(typeof pars.url == 'undefined') {
    return false;
  }

  var stChg = function(ob, p) {
    return function() { ob.handler(p); }
  }

  this.el = el;
  this.url = pars.url;
  this.pars = typeof pars.pars != 'undefined' ? pars.pars : this.pars;
  this.handler = typeof pars.handler != 'undefined' ? pars.handler : this.handler;
  this.method = typeof pars.method != 'undefined' ? pars.method : 'get';
  this.successHandler = typeof pars.successHandler != 'undefined' ? pars.successHandler : this.successHandler;
  this.errorHandler = typeof pars.errorHandler != 'undefined' ? pars.errorHandler : this.errorHandler;
  this.loadHandler = typeof pars.loadHandler != 'undefined' ? pars.loadHandler : this.loadHandler;

  this.req = new XMLHttpRequest();
  this.req.open(this.method, this.url, true);
  this.req.setRequestHeader('User-Agent', this.agent);
  this.req.setRequestHeader('Accept-Charset','utf-8');
  this.req.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
  this.req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

  this.req.onreadystatechange = stChg(this, false);
  this.req.send(this.pars);
  return true;
};
HupAjax.prototype = {
  url: null,
  pars: null,
  req: null,
  el: null,
  method: 'get',
  agent: 'Hupper Firefox extension ###VERSION###',
  /**
   * Runs on statechange
   * @param {Object} pars
   * @return The error or load or successhandler state
   */
  handler: function(pars) {
    try {
      if (this.req.readyState == 4) {
        if(this.req.status != 'undefined') {
          if(this.req.status == 200) {
            return this.successHandler();
          }
          else {
            return this.errorHandler('status code - ' + this.req.status);
          }
        }
        else {
          return this.errorHandler('no status code');
        }
      }
      else {
        return this.loadHandler();
      }
    }
    catch(e) {
      return this.errorHandler('no readyState', e);
    }
  },
  /**
   * runs if the request was success
   */
  successHandler: function() {
    return this.req.responseText;
  },
  /**
   * runs if the request was not success
   * @param {String} msg Error message string
   * @param {Int} er Error code
   */
  errorHandler: function(msg, er) {
    Hog.log('Ajax error: ' + msg + ' || ' + er);
    HLog.log(this.url);
    return false;
  },
  /**
   * runs the request doesn't finished
   */
  loadHandler: function() {
    return true;
  }
};<commit_msg>[svn]  - set content type header only if necessary<commit_after>/**
 * ajax.js
 * @author <NAME> [Ajnasz] {@link http://ajnasz.hu http://ajnasz.hu} <EMAIL>
 * @license GPL v2
 * for more detials see the licence.txt file
 */
/**
 * Creates an AJAX request
 * @author <NAME> [Ajnasz] http://ajnasz.hu <EMAIL>
 * @class HupAjax sends request to the {@link http://hup.hu hup.hu} site
 * @constructor
 * @param {Object} pars object to overwrite the default parameters
 */
var HupAjax = function(pars, el) {
  if(typeof pars.url == 'undefined') {
    return false;
  }

  var stChg = function(ob, p) {
    return function() { ob.handler(p); }
  }

  this.el = el;
  this.url = pars.url;
  this.pars = typeof pars.pars != 'undefined' ? pars.pars : this.pars;
  this.handler = typeof pars.handler != 'undefined' ? pars.handler : this.handler;
  this.method = typeof pars.method != 'undefined' ? pars.method : 'get';
  this.successHandler = typeof pars.successHandler != 'undefined' ? pars.successHandler : this.successHandler;
  this.errorHandler = typeof pars.errorHandler != 'undefined' ? pars.errorHandler : this.errorHandler;
  this.loadHandler = typeof pars.loadHandler != 'undefined' ? pars.loadHandler : this.loadHandler;

  this.req = new XMLHttpRequest();
  this.req.open(this.method, this.url, true);
  this.req.setRequestHeader('User-Agent', this.agent);
  this.req.setRequestHeader('Accept-Charset','utf-8');
  this.req.setRequestHeader('X-Requested-With', 'XMLHttpRequest');

  if(this.method.toLowerCase() == 'post') {
    this.req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  }

  this.req.onreadystatechange = stChg(this, false);
  this.req.send(this.pars);
  return true;
};
HupAjax.prototype = {
  url: null,
  pars: null,
  req: null,
  el: null,
  method: 'get',
  agent: 'Hupper Firefox extension ###VERSION###',
  /**
   * Runs on statechange
   * @param {Object} pars
   * @return The error or load or successhandler state
   */
  handler: function(pars) {
    try {
      if (this.req.readyState == 4) {
        if(this.req.status != 'undefined') {
          if(this.req.status == 200) {
            return this.successHandler();
          }
          else {
            return this.errorHandler('status code - ' + this.req.status);
          }
        }
        else {
          return this.errorHandler('no status code');
        }
      }
      else {
        return this.loadHandler();
      }
    }
    catch(e) {
      return this.errorHandler('no readyState', e);
    }
  },
  /**
   * runs if the request was success
   */
  successHandler: function() {
    return this.req.responseText;
  },
  /**
   * runs if the request was not success
   * @param {String} msg Error message string
   * @param {Int} er Error code
   */
  errorHandler: function(msg, er) {
    HUP.L.log('Ajax error: ' + msg + ' || ' + er);
    HUP.L.log(this.url);
    return false;
  },
  /**
   * runs the request doesn't finished
   */
  loadHandler: function() {
    return true;
  }
};
{'fraction_non_alphanumeric': 0.15051407382437215, 'fraction_numerical': 0.0020225855385133996, 'mean_word_length': 2.8557504873294346, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5508059', 'n_tokens_mistral': 1984, 'n_tokens_neox': 1919, 'n_words': 467}