<commit_before>/*jshint devel: true, browser: true */
/*global chrome, console, $ */
(function() {
'use strict';

var boardOffsetTop = 0;

var prevScrollY = window.scrollY;
var SCROLL_NONE = 0;
var SCROLL_UP = 1;
var SCROLL_DOWN = 2;

var PAGE_TYPE_NONE = 0;
var PAGE_TYPE_BOARD = 1;
var PAGE_TYPE_MESSAGE = 2;

var pageType = PAGE_TYPE_NONE;
var boardIndex = 0;

var xhr = null;

function offsetTop(ele) {
  var top = 0;
  while (ele) {
    if (!isNaN(ele.offsetTop)) top += ele.offsetTop;
    ele = ele.offsetParent;
  }

  return top;
}

function getViewport() {
  var top = window.scrollY;
  return  { top:top, bottom:top + Math.max(document.documentElement.clientHeight, window.innerHeight || 0) };
}

function inViewport(ele) {
  var vp = getViewport();
  var eleTop = offsetTop(ele);
  var eleBottom = eleTop + ele.offsetHeight;

  return ((eleBottom <= vp.bottom) && (eleTop >= vp.top + boardOffsetTop));
}

function animateScrollTo(scrollTo, interval, onComplete) {
  var start = new Date().getTime();
  var startY = window.scrollY;
  var isUp = scrollTo < startY;

  function scroller() {
    var now = new Date().getTime();
    if (now - start >= interval) {
      window.scrollTo(0, scrollTo);
      if (onComplete) {
        onComplete.apply();
      }
    }
    else {
      window.scrollTo(0,
                      isUp?(Math.max(scrollTo, startY + (scrollTo - startY) * (now - start) / interval)):
                           (Math.min(scrollTo, startY + (scrollTo - startY) * (now - start) / interval)));
      window.setTimeout(scroller, 10);
    }
  }
  window.setTimeout(scroller, 20);
}

function animate(element, toOpts, interval, onComplete) {
  function initState() {
    var result = {};
    var computedStyle = [];
    if (window.getComputedStyle) {
      computedStyle = window.getComputedStyle(element);
    }
    for (var key in toOpts) {
      result[key] = computedStyle[key] || ('0' + (toOpts[key] + '').replace(/(.*\d+)/, ''));
      if (result[key].match(/\d$/)) {
        result[key] += 'px';
      }
    }

    return result;
  }

  var requestAnimationFrame =
    (
      requestAnimationFrame ||
      (
        function(/* function */ callback){
          window.setTimeout(callback, 1000 / 60);
        }
      )
    );
  var initOpts = initState();

  var start = new Date().getTime();

  function animator() {
    var now = new Date().getTime();

    if (!window.getComputedStyle || now - start >= interval) {
      for (var doneKey in toOpts) {
        var doneTo = parseFloat(toOpts[doneKey]);
        var doneUnit = (initOpts[doneKey] + '').match(/([^\d]*)$/);
        doneUnit = doneUnit?doneUnit[1].trim():'';
        element.style[doneKey] = doneTo + doneUnit;
      }
      if (onComplete) {
        onComplete.apply(element);
      }
    }
    else {
      for (var key in toOpts) {
        var from = initOpts[key];<commit_msg>use requestAnimationFrame instead of setTimeout<commit_after>/*jshint devel: true, browser: true */
/*global chrome, console, $ */
(function() {
'use strict';

var boardOffsetTop = 0;

var prevScrollY = window.scrollY;
var SCROLL_NONE = 0;
var SCROLL_UP = 1;
var SCROLL_DOWN = 2;

var PAGE_TYPE_NONE = 0;
var PAGE_TYPE_BOARD = 1;
var PAGE_TYPE_MESSAGE = 2;

var pageType = PAGE_TYPE_NONE;
var boardIndex = 0;

var xhr = null;

var requestAnimationFrame =
  (
    requestAnimationFrame ||
    (
      function(/* function */ callback){
        window.setTimeout(callback, 1000 / 60);
      }
    )
  );

function offsetTop(ele) {
  var top = 0;
  while (ele) {
    if (!isNaN(ele.offsetTop)) top += ele.offsetTop;
    ele = ele.offsetParent;
  }

  return top;
}

function getViewport() {
  var top = window.scrollY;
  return  { top:top, bottom:top + Math.max(document.documentElement.clientHeight, window.innerHeight || 0) };
}

function inViewport(ele) {
  var vp = getViewport();
  var eleTop = offsetTop(ele);
  var eleBottom = eleTop + ele.offsetHeight;

  return ((eleBottom <= vp.bottom) && (eleTop >= vp.top + boardOffsetTop));
}

function animateScrollTo(scrollTo, interval, onComplete) {
  var start = new Date().getTime();
  var startY = window.scrollY;
  var isUp = scrollTo < startY;

  function scroller() {
    var now = new Date().getTime();
    if (now - start >= interval) {
      window.scrollTo(0, scrollTo);
      if (onComplete) {
        onComplete.apply();
      }
    }
    else {
      window.scrollTo(0,
                      isUp?(Math.max(scrollTo, startY + (scrollTo - startY) * (now - start) / interval)):
                           (Math.min(scrollTo, startY + (scrollTo - startY) * (now - start) / interval)));
      requestAnimationFrame(scroller);
    }
  }
  requestAnimationFrame(scroller);
}

function animate(element, toOpts, interval, onComplete) {
  function initState() {
    var result = {};
    var computedStyle = [];
    if (window.getComputedStyle) {
      computedStyle = window.getComputedStyle(element);
    }
    for (var key in toOpts) {
      result[key] = computedStyle[key] || ('0' + (toOpts[key] + '').replace(/(.*\d+)/, ''));
      if (result[key].match(/\d$/)) {
        result[key] += 'px';
      }
    }

    return result;
  }

  var initOpts = initState();

  var start = new Date().getTime();

  function animator() {
    var now = new Date().getTime();

    if (!window.getComputedStyle || now - start >= interval) {
      for (var doneKey in toOpts) {
        var doneTo = parseFloat(toOpts[doneKey]);
        var doneUnit = (initOpts[doneKey] + '').match(/([^\d]*)$/);
        doneUnit = doneUnit?doneUnit[1].trim():'';
        element.style[doneKey] = doneTo + doneUnit;
      }
      if (onComplete) {
        onComplete.apply(element);
      }
    }
    else {
      for (var key in toOpts) {
        var from = initOpts[key];
{'fraction_non_alphanumeric': 0.14867440651533528, 'fraction_numerical': 0.007624328539247964, 'mean_word_length': 2.7190721649484537, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '1643674', 'n_tokens_mistral': 1961, 'n_tokens_neox': 1923, 'n_words': 451}