<commit_before>var contentBlocker = (function(configModule) {
  var dce = function(tagName) { return document.createElement(tagName); };

  var extensionId = chrome.runtime.id;
  var ContentBlocker = function(
      webview,
      form,
      submitButton,
      urlPatternInput,
      resetButton,
      consoleElement,
      opt_cancelResourceTypes) {
    this.urlPattern = null;
    this.webview = webview;
    this.form = form;
    this.submitButton = submitButton;
    this.urlPatternInput = urlPatternInput;
    this.resetButton = resetButton;
    this.consoleElement = consoleElement;
    this.cancelResourceTypes = opt_cancelResourceTypes || [
      'stylesheet',
      'object',
      'xmlhttprequest',
      'other',
      'main_frame',
      'sub_frame',
      'script'
    ];

    this.init();
  };

  ContentBlocker.prototype.init = function() {
    (function(cb) {
      // Respond to messages triggered by declarative web request API rules
      cb.webview.request.onMessage.addListener(function(details) {
        var data = JSON.parse(details.message);
        var msgDiv = dce('div');
        var patternPre = dce('pre');
        var prefixSpan = dce('span');
        var postfixSpan = dce('span');
        prefixSpan.innerText = '"' + data.type + '" matching ';
        patternPre.innerText = '/' + data.urlPattern + '/';
        postfixSpan.innerText = ' ' + data.action;
        msgDiv.appendChild(prefixSpan);
        msgDiv.appendChild(patternPre);
        msgDiv.appendChild(postfixSpan);
        cb.consoleElement.appendChild(msgDiv);
        cb.consoleElement.scrollTop = cb.consoleElement.scrollHeight;

        // Cannot redirect immediately to package-local resources; (see
        // http://crbug.com/379733); use message-send + message-listener instead
        if (data.type == 'main_frame' || data.type == 'sub_frame') {
          cb.webview.src = 'blocked.html';
        }
      });

      // Bind to reset button event: load state from config
      cb.resetButton.addEventListener('click', function(e) {
          cb.removeRules();

          var urlPattern = configModule.urlPattern;
          cb.urlPattern = urlPattern;
          cb.urlPatternInput.value = urlPattern;

          chrome.storage.local.set({'urlPattern': urlPattern});

          cb.refreshRules();
          cb.addRules();

          cb.consoleElement.innerHTML = '';

          cb.webview.src = configModule.homepage;
      });

      // Update state and reload when committing to URL
      cb.form.addEventListener('submit', function(e) {
        e.preventDefault();

        cb.removeRules();

        var urlPattern = cb.urlPatternInput.value;
        cb.urlPattern = urlPattern;

        chrome.storage.local.set({'urlPattern': urlPattern});

        cb.refreshRules();
        cb.addRules();

        cb.webview.reload();
      });

      // Load state from local storage or else config
      console.log('Fetching local storage data');
      chrome.storage.local.get(
        ['urlPattern'],
        function(data) {
          console.log('Local storage data fetched');
          var urlPattern = data.urlPattern ?
              data.urlPattern :
              configModule.urlPattern;
          cb.urlPattern = urlPattern;
          cb.urlPatternInput.value = urlPattern;

          cb.submitButton.removeAttribute('disabled');
          cb.urlPatternInput.removeAttribute('disabled');
          cb.resetButton.removeAttribute('disabled');

          cb.refreshRules();
          cb.addRules();

          cb.webview.src = configModule.homepage;
        });
    }(this));
  };

  ContentBlocker.prototype.removeRules = function() {
    var ruleIds = this.rules.map(function(rule) { return rule.id; });
    console.log('Removing rules: ', ruleIds);
    this.webview.request.onRequest.removeRules(
        ruleIds,
        function(details) { console.log('Removed rules; details: ', details); });
  };

  ContentBlocker.prototype.addRules = function() {
    console.log('Adding rules');

    this.webview.request.onRequest.addRules(
        this.rules,
        function(details) { console.log('Added rules; details: ', details); });
  };

  ContentBlocker.prototype.refreshRules = function() {
    console.log('Refresh rules; url pattern: ', this.urlPattern);

    // Construct individual blockers for each cancel-able resource type
    this.rules = (function(cb) {
      return cb.cancelResourceTypes.map(function(type) {
        return { // Cancel request for blocked resource and send a message<commit_msg>Remove unnecessary calls to console.log()<commit_after>var contentBlocker = (function(configModule) {
  var dce = function(tagName) { return document.createElement(tagName); };

  var extensionId = chrome.runtime.id;
  var ContentBlocker = function(
      webview,
      form,
      submitButton,
      urlPatternInput,
      resetButton,
      consoleElement,
      opt_cancelResourceTypes) {
    this.urlPattern = null;
    this.webview = webview;
    this.form = form;
    this.submitButton = submitButton;
    this.urlPatternInput = urlPatternInput;
    this.resetButton = resetButton;
    this.consoleElement = consoleElement;
    this.cancelResourceTypes = opt_cancelResourceTypes || [
      'stylesheet',
      'object',
      'xmlhttprequest',
      'other',
      'main_frame',
      'sub_frame',
      'script'
    ];

    this.init();
  };

  ContentBlocker.prototype.init = function() {
    (function(cb) {
      // Respond to messages triggered by declarative web request API rules
      cb.webview.request.onMessage.addListener(function(details) {
        var data = JSON.parse(details.message);
        var msgDiv = dce('div');
        var patternPre = dce('pre');
        var prefixSpan = dce('span');
        var postfixSpan = dce('span');
        prefixSpan.innerText = '"' + data.type + '" matching ';
        patternPre.innerText = '/' + data.urlPattern + '/';
        postfixSpan.innerText = ' ' + data.action;
        msgDiv.appendChild(prefixSpan);
        msgDiv.appendChild(patternPre);
        msgDiv.appendChild(postfixSpan);
        cb.consoleElement.appendChild(msgDiv);
        cb.consoleElement.scrollTop = cb.consoleElement.scrollHeight;

        // Cannot redirect immediately to package-local resources; (see
        // http://crbug.com/379733); use message-send + message-listener instead
        if (data.type == 'main_frame' || data.type == 'sub_frame') {
          cb.webview.src = 'blocked.html';
        }
      });

      // Bind to reset button event: load state from config
      cb.resetButton.addEventListener('click', function(e) {
          cb.removeRules();

          var urlPattern = configModule.urlPattern;
          cb.urlPattern = urlPattern;
          cb.urlPatternInput.value = urlPattern;

          chrome.storage.local.set({'urlPattern': urlPattern});

          cb.refreshRules();
          cb.addRules();

          cb.consoleElement.innerHTML = '';

          cb.webview.src = configModule.homepage;
      });

      // Update state and reload when committing to URL
      cb.form.addEventListener('submit', function(e) {
        e.preventDefault();

        cb.removeRules();

        var urlPattern = cb.urlPatternInput.value;
        cb.urlPattern = urlPattern;

        chrome.storage.local.set({'urlPattern': urlPattern});

        cb.refreshRules();
        cb.addRules();

        cb.webview.reload();
      });

      // Load state from local storage or else config
      chrome.storage.local.get(
        ['urlPattern'],
        function(data) {
          var urlPattern = data.urlPattern ?
              data.urlPattern :
              configModule.urlPattern;
          cb.urlPattern = urlPattern;
          cb.urlPatternInput.value = urlPattern;

          cb.submitButton.removeAttribute('disabled');
          cb.urlPatternInput.removeAttribute('disabled');
          cb.resetButton.removeAttribute('disabled');

          cb.refreshRules();
          cb.addRules();

          cb.webview.src = configModule.homepage;
        });
    }(this));
  };

  ContentBlocker.prototype.removeRules = function() {
    var ruleIds = this.rules.map(function(rule) { return rule.id; });
    this.webview.request.onRequest.removeRules(ruleIds);
  };

  ContentBlocker.prototype.addRules = function() {
    this.webview.request.onRequest.addRules(this.rules);
  };

  ContentBlocker.prototype.refreshRules = function() {
    // Construct individual blockers for each cancel-able resource type
    this.rules = (function(cb) {
      return cb.cancelResourceTypes.map(function(type) {
        return { // Cancel request for blocked resource and send a message
{'fraction_non_alphanumeric': 0.1198471514590088, 'fraction_numerical': 0.0013895321908290875, 'mean_word_length': 2.519559902200489, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '2558243', 'n_tokens_mistral': 2409, 'n_tokens_neox': 2340, 'n_words': 469}