<commit_before>const WHITELIST = {
  folhadespaulo: {
    xhrBlocking: [
      'http://paywall.folha.uol.com.br/status.php',
      'https://paywall.folha.uol.com.br/status.php'
    ]
  }
};

const BLOCKLIST = {
  correiopopular: {
    scriptBlocking: [
      '*://correio.rac.com.br/includes/js/novo_cp/fivewall.js*',
    ]
  },
  diariocatarinense: {
    xhrBlocking: [
      'http://dc.clicrbs.com.br/jornal-2015/jsp/paywall.jspx*',
    ]
  },
  diariodesantamaria: {
    scriptBlocking: [
      '*://www.rbsonline.com.br/cdn/scripts/SLoader.js',
    ]
  },
  exame: {
    scriptBlocking: [
      '*://cdn.tinypass.com/api/tinypass.min.js',
    ]
  },
  folhadespaulo: {
    scriptBlocking: [
      '*://paywall.folha.uol.com.br/*',
      '*://static.folha.uol.com.br/paywall/*',
    ],
    xhrBlocking: [
      '*://paywall.folha.uol.com.br/*',
      '*://static.folha.uol.com.br/paywall/*',
    ]
  },
  financialtimes: {
    cookieBlocking: {
      urlFilter: '*://*.ft.com/*',
      blockAll: true
    },
    headerInjection: {
      name: 'Referer',
      value: 'https://www.google.com.br/',
      urlFilter: '*://www.ft.com/*'
    }
  },
  gazetadopovo: {
    scriptBlocking: [
      '*://www.netdeal.com.br/*',
    ]
  },
  gazetaonline: {
    cookieBlocking: {
      urlFilter: '*://www.gazetaonline.com.br/*',
      blockAll: true
    }
  },
  gauchazh: {
    scriptBlocking: [
      '*://gauchazh.clicrbs.com.br/static/main*',
      '*://www.rbsonline.com.br/cdn/scripts/special-paywall.min.js*',
      '*://www.rbsonline.com.br/cdn/scripts/paywall.min.js*',
    ]
  },
  gramophone: {
    scriptBlocking: [
      '*://api.tinypass.com/tpl/*',
    ]
  },
  jornaldesantacatarina: {
    scriptBlocking: [
      'http://jornaldesantacatarina.clicrbs.com.br/jornal/jsp/paywall*'
    ]
  },
  jornalnh: {
    scriptBlocking: [
      '*://*.jornalnh.com.br/includes/js/paywall.js*',
      '*://blockv2.fivewall.com.br/*',
    ]
  },
  jota: {
    cookieBlocking: {
      urlFilter: 'http://jota.info/*',
      cookie: {
        url: 'http://jota.info/*',
        name: 'articles'
      }
    }
  },
  medium: {
    cookieBlocking: {
      urlFilter: 'https://medium.com/*',
      blockAll: true
    }
  },
  nexo: {
    cookieBlocking: {
      urlFilter: '*://api.nexojornal.com.br/*',
      blockAll: true
    }
  },
  oestadodespaulo: {
    xhrBlocking: [
      '*://*.estadao.com.br/paywall/*',
    ]
  },
  oestadodomaranhao: {
    xhrBlocking: [
      '*://dashboard.tinypass.com/xbuilder/experience/load*',
      'http://assets.imirante.com/2.0/oestadoma/js/jquery.login.min.js',
    ]
  },
  oglobo: {
    urls: [
      /oglobo.globo.com/,
    ],
    allowScript: [
      '*://cdn.tinypass.com/api/tinypass.min.js',
    ],
    xhrBlocking:  [
      '*://static.infoglobo.com.br/paywall/register-piano/v2/scripts/nova-tela-register.js',
    ],
  },
  pioneiro: {
    scriptBlocking: [
      '*://www.rbsonline.com.br/cdn/scripts/SLoader.js',
    ]
  },
  quatrorodas: {
    scriptBlocking: [
      '*://cdn.tinypass.com/api/tinypass.min.js',
    ]
  },
  superinteressante: {
    scriptBlocking: [
      '*://cdn.tinypass.com/api/tinypass.min.js',
    ]
  },
  theeconomist: {
    scriptBlocking: [
      '*://cdn.tinypass.com/api/tinypass.min.js',
    ]
  },
  thenewyorktimes: {
    scriptBlocking: [
      '*://*.nytimes.com/js/mtr.js',
      '*://*.nyt.com/js/mtr.js',
    ]
  },
  thewashingtonpost: {
    scriptBlocking: [
      '*://*.washingtonpost.com/*pwapi/*.js*',
      '*://*.washingtonpost.com/*drawbridge/drawbridge.js?_*',
    ]
  },
  thewallstreetjournal: {
    cookieBlocking: {
      urlFilter: '*://*.wsj.com/*',
      blockAll: true
    },
    headerInjection: {
      name: 'Referer',
      value: 'https://www.facebook.com/',
      urlFilter: '*://*.wsj.com/*'
    }
  },
  uol: {
    scriptBlocking: [
      '*://tm.jsuol.com.br/modules/content-gate.js',
    ]
  },
  veja: {
    scriptBlocking: [
      '*://cdn.tinypass.com/api/tinypass.min.js',
    ]
  }
};

function onBeforeRequestScript(details) {
  for (let item in BLOCKLIST) {
    let urls = BLOCKLIST[item].urls;
    let scripts = BLOCKLIST[item].allowScript;
    if (urls != undefined) {
      for (let item in urls) {
        if (urls[item].test(details.initiator) ||
            urls[item].test(details.originUrl)) {
          for (let item in scripts) {
            if (details.url.match(matchPatternToRegExp(scripts[item])))
              return {cancel: false};
          }
        }
      }
    }
  }
  return {cancel: true};
}

function setScriptBlocking(enabledSites) {
  let urlFilters = [];

  for (let item in BLOCKLIST) {
    let script = BLOCKLIST[item].scriptBlocking;
    if (enabledSites && enabledSites[item] == false)
      continue;
    if (script == undefined)
      continue;
    urlFilters = urlFilters.concat(script);
  }

  chrome.webRequest.onBeforeRequest.addListener(
    onBeforeRequestScript,
    {
      urls: urlFilters,<commit_msg>Pula caso não haja uma lista de scripts a serem liberados<commit_after>const WHITELIST = {
  folhadespaulo: {
    xhrBlocking: [
      'http://paywall.folha.uol.com.br/status.php',
      'https://paywall.folha.uol.com.br/status.php'
    ]
  }
};

const BLOCKLIST = {
  correiopopular: {
    scriptBlocking: [
      '*://correio.rac.com.br/includes/js/novo_cp/fivewall.js*',
    ]
  },
  diariocatarinense: {
    xhrBlocking: [
      'http://dc.clicrbs.com.br/jornal-2015/jsp/paywall.jspx*',
    ]
  },
  diariodesantamaria: {
    scriptBlocking: [
      '*://www.rbsonline.com.br/cdn/scripts/SLoader.js',
    ]
  },
  exame: {
    scriptBlocking: [
      '*://cdn.tinypass.com/api/tinypass.min.js',
    ]
  },
  folhadespaulo: {
    scriptBlocking: [
      '*://paywall.folha.uol.com.br/*',
      '*://static.folha.uol.com.br/paywall/*',
    ],
    xhrBlocking: [
      '*://paywall.folha.uol.com.br/*',
      '*://static.folha.uol.com.br/paywall/*',
    ]
  },
  financialtimes: {
    cookieBlocking: {
      urlFilter: '*://*.ft.com/*',
      blockAll: true
    },
    headerInjection: {
      name: 'Referer',
      value: 'https://www.google.com.br/',
      urlFilter: '*://www.ft.com/*'
    }
  },
  gazetadopovo: {
    scriptBlocking: [
      '*://www.netdeal.com.br/*',
    ]
  },
  gazetaonline: {
    cookieBlocking: {
      urlFilter: '*://www.gazetaonline.com.br/*',
      blockAll: true
    }
  },
  gauchazh: {
    scriptBlocking: [
      '*://gauchazh.clicrbs.com.br/static/main*',
      '*://www.rbsonline.com.br/cdn/scripts/special-paywall.min.js*',
      '*://www.rbsonline.com.br/cdn/scripts/paywall.min.js*',
    ]
  },
  gramophone: {
    scriptBlocking: [
      '*://api.tinypass.com/tpl/*',
    ]
  },
  jornaldesantacatarina: {
    scriptBlocking: [
      'http://jornaldesantacatarina.clicrbs.com.br/jornal/jsp/paywall*'
    ]
  },
  jornalnh: {
    scriptBlocking: [
      '*://*.jornalnh.com.br/includes/js/paywall.js*',
      '*://blockv2.fivewall.com.br/*',
    ]
  },
  jota: {
    cookieBlocking: {
      urlFilter: 'http://jota.info/*',
      cookie: {
        url: 'http://jota.info/*',
        name: 'articles'
      }
    }
  },
  medium: {
    cookieBlocking: {
      urlFilter: 'https://medium.com/*',
      blockAll: true
    }
  },
  nexo: {
    cookieBlocking: {
      urlFilter: '*://api.nexojornal.com.br/*',
      blockAll: true
    }
  },
  oestadodespaulo: {
    xhrBlocking: [
      '*://*.estadao.com.br/paywall/*',
    ]
  },
  oestadodomaranhao: {
    xhrBlocking: [
      '*://dashboard.tinypass.com/xbuilder/experience/load*',
      'http://assets.imirante.com/2.0/oestadoma/js/jquery.login.min.js',
    ]
  },
  oglobo: {
    urls: [
      /oglobo.globo.com/,
    ],
    allowScript: [
      '*://cdn.tinypass.com/api/tinypass.min.js',
    ],
    xhrBlocking:  [
      '*://static.infoglobo.com.br/paywall/register-piano/v2/scripts/nova-tela-register.js',
    ],
  },
  pioneiro: {
    scriptBlocking: [
      '*://www.rbsonline.com.br/cdn/scripts/SLoader.js',
    ]
  },
  quatrorodas: {
    scriptBlocking: [
      '*://cdn.tinypass.com/api/tinypass.min.js',
    ]
  },
  superinteressante: {
    scriptBlocking: [
      '*://cdn.tinypass.com/api/tinypass.min.js',
    ]
  },
  theeconomist: {
    scriptBlocking: [
      '*://cdn.tinypass.com/api/tinypass.min.js',
    ]
  },
  thenewyorktimes: {
    scriptBlocking: [
      '*://*.nytimes.com/js/mtr.js',
      '*://*.nyt.com/js/mtr.js',
    ]
  },
  thewashingtonpost: {
    scriptBlocking: [
      '*://*.washingtonpost.com/*pwapi/*.js*',
      '*://*.washingtonpost.com/*drawbridge/drawbridge.js?_*',
    ]
  },
  thewallstreetjournal: {
    cookieBlocking: {
      urlFilter: '*://*.wsj.com/*',
      blockAll: true
    },
    headerInjection: {
      name: 'Referer',
      value: 'https://www.facebook.com/',
      urlFilter: '*://*.wsj.com/*'
    }
  },
  uol: {
    scriptBlocking: [
      '*://tm.jsuol.com.br/modules/content-gate.js',
    ]
  },
  veja: {
    scriptBlocking: [
      '*://cdn.tinypass.com/api/tinypass.min.js',
    ]
  }
};

function onBeforeRequestScript(details) {
  for (let item in BLOCKLIST) {
    let urls = BLOCKLIST[item].urls;
    let scripts = BLOCKLIST[item].allowScript;
    if (scripts == undefined)
      continue;
    if (urls != undefined) {
      for (let item in urls) {
        if (urls[item].test(details.initiator) ||
            urls[item].test(details.originUrl)) {
          for (let item in scripts) {
            if (details.url.match(matchPatternToRegExp(scripts[item])))
              return {cancel: false};
          }
        }
      }
    }
  }
  return {cancel: true};
}

function setScriptBlocking(enabledSites) {
  let urlFilters = [];

  for (let item in BLOCKLIST) {
    let script = BLOCKLIST[item].scriptBlocking;
    if (enabledSites && enabledSites[item] == false)
      continue;
    if (script == undefined)
      continue;
    urlFilters = urlFilters.concat(script);
  }

  chrome.webRequest.onBeforeRequest.addListener(
    onBeforeRequestScript,
    {
      urls: urlFilters,
{'fraction_non_alphanumeric': 0.18919728434504793, 'fraction_numerical': 0.001597444089456869, 'mean_word_length': 2.1519823788546257, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 8, 'lorem ipsum': 0, 'www.': 18, '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': '5860795', 'n_tokens_mistral': 4051, 'n_tokens_neox': 3961, 'n_words': 417}