<commit_before>// interface to the use of the google 'botguard' javascript added to the intel site


iitc_bg = Object();

iitc_bg.DISABLED = false; //if set, botguard is disabld. no b/c params sent in requests, no processing of responses

iitc_bg.init = function() {
  if (iitc_bg.DISABLED) return;

// stock site - 'ad.e()' constructor
//function Ad() {
//  this.Eb = {}; // a map, indexed by 'group-[ab]-actions', each entry containing an array of 'yd' objects (simple object, with 'gf' and 'cb' members). a queue of data to process?
//  this.Oa = {}; // a map, indexed by 'group-[ab]-actions', each entry containing an object with an 'invoke' method
//  this.Zc = {}; // a map, indexed by group, witn constructors for botguard
//  this.eb = ""; // the 'key' - B
//  this.Kh = e;  // e is defined in the main web page as "var e = function(w) {eval(w);};"
//}

  var botguard_eval = e;

  iitc_bg.data_queue = {};    //.lb - indexed by group
  iitc_bg.instance_queue = {}; //.ya - indexed by group
  iitc_bg.key = "";      //.cb
  iitc_bg.botguard = {}; //.qc - indexed by key
  iitc_bg.evalFunc = botguard_eval;

// stock site code
//Ad.prototype.U = function(a, b) {
//  Bd(this, a);
//  for (var c in b) if ("group-b-actions" == c || "group-a-actions" == c) {
//    for (var d = 0; d < b[c].length; ++d) Dd(this, c, new Ed(b[c][d], a));
//    Fd(this, c);
//  }
//};
// and.. Ed - a simple object that holds it's parameters and the timestamp it was created
//function Ed(a, b) {
//  var c = w();
//  this.mg = a;
//  this.eb = b;
//  this.Ki = c;
//}


  // to initialise, we need four things
  // B - a key(?). set in the main web page HTML, name isn't changed on site updates
  // CS - initialisation data for botguard - again in the main page, again name is constant


  var botguard_key = B;
  var botguard_data = CS;

  iitc_bg.process_key(botguard_key);

  for (var group in botguard_data) {
    // TODO? filter this loop by group-[ab]-actions only? the stock site does, but this seems unnecessary

    // the stock site has code to create the emtpy arrays with the group index as and when needed
    // however, it makes more sense to do it here just once, rather than testing every time
    iitc_bg.data_queue[group] = [];
    iitc_bg.instance_queue[group] = [];

    for (var i=0; i < botguard_data[group].length; i++) {
      iitc_bg.push_queue(group, botguard_data[group][i], botguard_key);
    }

    iitc_bg.process_queue(group);
  }
};

//TODO: better name - will do for now...
iitc_bg.push_queue = function(group, data, key) {
//stock site code
//a=='this', b==group-[ab]-actions, c==object with .mg==data, .eb==key, .Ki==current timestamp
//function Dd(a, b, c) {
//  var d = c.eb && a.Zc[c.eb];
//  if ("dkxm" == c.mg || d) a.Eb[b] || (a.Eb[b] = []), a.Eb[b].push(c);
//}

  // Niantic have changed how the server returns data items to the client a few times, which cause
  // bad non-string items to come into here. this breaks things badly
  if (typeof data !== "string") throw "Error: iitc_bg.process_queue got dodgy data - expected a string";

  var botguard_instance = iitc_bg.key && iitc_bg.botguard[iitc_bg.key];

  if (data == "dkxm" || botguard_instance) {
    // NOTE: we pre-create empty per-group arrays on init
    iitc_bg.data_queue[group].push( {data: data, key: key, time: Date.now()} );
  }
};


// called both on initialisation and on processing responses from the server
// 
iitc_bg.process_key = function(key,serverEval) {
  if (iitc_bg.DISABLED) return;


// stock site code
//function Bd(a, b, c) {
//  if (a.Zc[b]) a.eb = b; else {
//    var d = !0;
//    if (c) try {
//      a.Kh(c);
//    } catch (f) {
//      d = !1;
//    }
//    d && (a.Zc[b] = botguard.bg, a.eb = b);
//  }
//}

  if (iitc_bg.botguard[key]) {
    iitc_bg.key = key;
  } else {
    var noCatch = true;

    if (serverEval) {
      // server wants us to eval some code! risky, and impossible to be certain we can do it safely
      // however... reports say that it only interacts with the botguard.bg code, so we might be fine just running it
      // (but this is only when we don't send the correct params to the server? no reports of this code triggering yet...)
      try {
        console.warn('botguard: Server-generated javascript eval requested:\n'+serverEval);
debugger;
if (!confirm('The server asked IITC to run (eval) some javascript. This may or may not be safe. Run and continue?\n\nScript:\n'+serverEval)) { console.error('server javascript eval cancelled') } else
        iitc_bg.evalFunc(serverEval);
        console.log('botguard: Server-generated javascript ran OK');
      } catch(e) {
        console.warn('botguard: Server-generated javascript - threw an exception');
        console.warn(e);
        noCatch = false;
      }
    }
    if (noCatch) {
      iitc_bg.botguard[key] = botguard.bg;
      iitc_bg.key = key;
    }
  }
};


//convert a method name to the group-[ab]-actions value, or return 'undefined' for no group
//NOTE: the stock code separates the 'in any group' and 'which group' test, but it's cleaner to combine them
//UPDATE: the 'not in any group' case was removed from the stock site logic
iitc_bg.get_method_group = function(method) {
//stock site
//function Cd(a) {<commit_msg>remove confirm prompt on server-returned javascript<commit_after>// interface to the use of the google 'botguard' javascript added to the intel site


iitc_bg = Object();

iitc_bg.DISABLED = false; //if set, botguard is disabld. no b/c params sent in requests, no processing of responses

iitc_bg.init = function() {
  if (iitc_bg.DISABLED) return;

// stock site - 'ad.e()' constructor
//function Ad() {
//  this.Eb = {}; // a map, indexed by 'group-[ab]-actions', each entry containing an array of 'yd' objects (simple object, with 'gf' and 'cb' members). a queue of data to process?
//  this.Oa = {}; // a map, indexed by 'group-[ab]-actions', each entry containing an object with an 'invoke' method
//  this.Zc = {}; // a map, indexed by group, witn constructors for botguard
//  this.eb = ""; // the 'key' - B
//  this.Kh = e;  // e is defined in the main web page as "var e = function(w) {eval(w);};"
//}

  var botguard_eval = e;

  iitc_bg.data_queue = {};    //.lb - indexed by group
  iitc_bg.instance_queue = {}; //.ya - indexed by group
  iitc_bg.key = "";      //.cb
  iitc_bg.botguard = {}; //.qc - indexed by key
  iitc_bg.evalFunc = botguard_eval;

// stock site code
//Ad.prototype.U = function(a, b) {
//  Bd(this, a);
//  for (var c in b) if ("group-b-actions" == c || "group-a-actions" == c) {
//    for (var d = 0; d < b[c].length; ++d) Dd(this, c, new Ed(b[c][d], a));
//    Fd(this, c);
//  }
//};
// and.. Ed - a simple object that holds it's parameters and the timestamp it was created
//function Ed(a, b) {
//  var c = w();
//  this.mg = a;
//  this.eb = b;
//  this.Ki = c;
//}


  // to initialise, we need four things
  // B - a key(?). set in the main web page HTML, name isn't changed on site updates
  // CS - initialisation data for botguard - again in the main page, again name is constant


  var botguard_key = B;
  var botguard_data = CS;

  iitc_bg.process_key(botguard_key);

  for (var group in botguard_data) {
    // TODO? filter this loop by group-[ab]-actions only? the stock site does, but this seems unnecessary

    // the stock site has code to create the emtpy arrays with the group index as and when needed
    // however, it makes more sense to do it here just once, rather than testing every time
    iitc_bg.data_queue[group] = [];
    iitc_bg.instance_queue[group] = [];

    for (var i=0; i < botguard_data[group].length; i++) {
      iitc_bg.push_queue(group, botguard_data[group][i], botguard_key);
    }

    iitc_bg.process_queue(group);
  }
};

//TODO: better name - will do for now...
iitc_bg.push_queue = function(group, data, key) {
//stock site code
//a=='this', b==group-[ab]-actions, c==object with .mg==data, .eb==key, .Ki==current timestamp
//function Dd(a, b, c) {
//  var d = c.eb && a.Zc[c.eb];
//  if ("dkxm" == c.mg || d) a.Eb[b] || (a.Eb[b] = []), a.Eb[b].push(c);
//}

  // Niantic have changed how the server returns data items to the client a few times, which cause
  // bad non-string items to come into here. this breaks things badly
  if (typeof data !== "string") throw "Error: iitc_bg.process_queue got dodgy data - expected a string";

  var botguard_instance = iitc_bg.key && iitc_bg.botguard[iitc_bg.key];

  if (data == "dkxm" || botguard_instance) {
    // NOTE: we pre-create empty per-group arrays on init
    iitc_bg.data_queue[group].push( {data: data, key: key, time: Date.now()} );
  }
};


// called both on initialisation and on processing responses from the server
// 
iitc_bg.process_key = function(key,serverEval) {
  if (iitc_bg.DISABLED) return;


// stock site code
//function Bd(a, b, c) {
//  if (a.Zc[b]) a.eb = b; else {
//    var d = !0;
//    if (c) try {
//      a.Kh(c);
//    } catch (f) {
//      d = !1;
//    }
//    d && (a.Zc[b] = botguard.bg, a.eb = b);
//  }
//}

  if (iitc_bg.botguard[key]) {
    iitc_bg.key = key;
  } else {
    var noCatch = true;

    if (serverEval) {
      // server wants us to eval some code! risky, and impossible to be certain we can do it safely
      // seems to always be the same javascript as already found in the web page source.
      try {
        console.warn('botguard: Server-generated javascript eval requested:\n'+serverEval);
        iitc_bg.evalFunc(serverEval);
        console.log('botguard: Server-generated javascript ran OK');
      } catch(e) {
        console.warn('botguard: Server-generated javascript - threw an exception');
        console.warn(e);
        noCatch = false;
      }
    }
    if (noCatch) {
      iitc_bg.botguard[key] = botguard.bg;
      iitc_bg.key = key;
    }
  }
};


//convert a method name to the group-[ab]-actions value, or return 'undefined' for no group
//NOTE: the stock code separates the 'in any group' and 'which group' test, but it's cleaner to combine them
//UPDATE: the 'not in any group' case was removed from the stock site logic
iitc_bg.get_method_group = function(method) {
//stock site
//function Cd(a) {
{'fraction_non_alphanumeric': 0.14858211894446632, 'fraction_numerical': 0.0007877116975187081, 'mean_word_length': 2.805545147995504, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '1973558', 'n_tokens_mistral': 3630, 'n_tokens_neox': 3499, 'n_words': 1206}