<commit_before>!function($) {
  var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver
  var Observer = function(target, selector, onAdded, onRemoved) {
    var self    = this
    this.target = target
    
    var childsOnly = selector[0] === '>'
      , search = childsOnly ? selector.substr(1) : selector
      
    function apply(nodes, callback) {
      Array.prototype.slice.call(nodes).forEach(function(node) {
        if (childsOnly && self.target[0] !== $(node).parent()[0]) return
        if ($(node).is(search)) callback.call(node)
        if (childsOnly) return
        $(selector, node).each(function() {
          callback.call(this)
        })
      })
    }
    
    this.observer = new MutationObserver(function(mutations) {
      self.disconnect()
      
      mutations.forEach(function(mutation) {
        if (onAdded)   apply(mutation.addedNodes,   onAdded)
        if (onRemoved) apply(mutation.removedNodes, onRemoved)
      })
  
      self.observe()
    })
    
    // call onAdded for existing elements
    $(selector, target).each(function() {
      onAdded.call(this)
    })
    
    this.observe()
  }
  
  Observer.prototype.disconnect = function() {
    this.observer.disconnect()
  }
  
  Observer.prototype.observe = function() {
    var self = this
    this.target.forEach(function(target) {
      self.observer.observe(target, { childList: true, subtree: true })
    })
  }
  
  $.fn.observe = function(selector, onAdded, onRemoved) {
    if (!this.length) return
    var contracts = this.data('contracts')
    if (!contracts) contracts = []
    var contract = contracts.filter(function(c) { return c.selector === selector })
    if (contract.length) {
      contract[0].onAdded   = onAdded
      contract[0].onRemoved = onRemoved
      return
    }
    var target = 'makeArray' in $ ? $.makeArray(this) : this
    var observer = new Observer(target, selector, onAdded, onRemoved)
    contracts.push(observer)
    this.data('contracts', contracts)
    return this
  }
}(window.Zepto || window.jQuery)<commit_msg>remove jQuery/Zepto dependency<commit_after>var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver
function matches(el, selector) {
  return (el.matches || el.matchesSelector || el.msMatchesSelector || el.mozMatchesSelector || el.webkitMatchesSelector || el.oMatchesSelector).call(el, selector)
}
function toArr(nodeList) {
  return Array.prototype.slice.call(nodeList)
}

var SelectorObserver = function(targets, selector, onAdded, onRemoved) {
  var self     = this
  this.targets = targets instanceof NodeList
                   ? Array.prototype.slice.call(targets)
                   : [targets]

  // support selectors starting with the childs only selector `>`
  var childsOnly = selector[0] === '>'
    , search = childsOnly ? selector.substr(1) : selector

  function apply(nodes, callback) {
    toArr(nodes).forEach(function(node) {
      // if looking for childs only, the node's parentNode
      // should be one of our targets
      if (childsOnly && self.targets.indexOf(node.parentNode) === -1) {
        return
      }

      // test if the node itself matches the selector
      if (matches(node, search)) {
        callback.call(node)
      }

      if (childsOnly) return

      toArr(node.querySelectorAll(selector)).forEach(function(node) {
        callback.call(node)
      })
    })
  }

  this.observer = new MutationObserver(function(mutations) {
    self.disconnect()

    mutations.forEach(function(mutation) {
      if (onAdded)   apply(mutation.addedNodes,   onAdded)
      if (onRemoved) apply(mutation.removedNodes, onRemoved)
    })

    self.observe()
  })

  // call onAdded for existing elements
  if (onAdded) apply(this.targets, onAdded)

  this.observe()
}

SelectorObserver.prototype.disconnect = function() {
  this.observer.disconnect()
}

SelectorObserver.prototype.observe = function() {
  var self = this
  this.targets.forEach(function(target) {
    self.observer.observe(target, { childList: true, subtree: true })
  })
}

if (typeof exports !== 'undefined') {
  module.exports = SelectorObserver
}
{'fraction_non_alphanumeric': 0.12425612949297786, 'fraction_numerical': 0.0021423470602237563, 'mean_word_length': 3.067763794772507, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '4705361', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1248, 'n_words': 260}