<commit_before>/*
 Author:     <NAME>
             <EMAIL>
 All rights reserved.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
 1. Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
 2. Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.
 3. The name of the author may not be used to endorse or promote products
    derived from this software without specific prior written permission.

 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

var tab_array = [];
var forbidden_url = ["chrome://", "chrome-extension://", "chrome-devtools://"];
var TIMEOUT_TIMER = 15;
if (localStorage.getItem("timer") !== null)
    TIMEOUT_TIMER = localStorage["timer"];

if (localStorage.getItem("exclude_list") !== null)
    forbidden_url = forbidden_url.concat(localStorage["exclude_list"].split('\n'));

window.addEventListener("storage", update_storage, false);
chrome.alarms.create({periodInMinutes: 1.0});

// When users changes the options, update the timer value
function update_storage(event_storage) {
    if (event_storage.key !== "timer") return;
    TIMEOUT_TIMER = event_storage.new_value;
}

// Returns true if a url is forbidden, false otherwise
function is_forbidden(url) {
    var found = false;
    forbidden_url.forEach(function(f_url) {
        if (url.indexOf(f_url) !== -1)
            found = true;
    });
    return found;
}

function findById(source, id) {
    return source.filter(function( obj ) {
        // coerce both obj.id and id to numbers
        // for val & type comparison
        return +obj.id === +id;
    })[ 0 ];
}

// On startup, get all tabs already created
chrome.windows.getAll({populate: true}, function (windows){
    windows.forEach(function(cwindow) {
        cwindow.tabs.forEach(function(tab) {
            if (is_forbidden(tab.url) == true) return;
            tab_array.push({id: tab.id, timer: 0, killed: false });
        });
    });
});

// When a tab gets a suitable URL and is not already in our array, add it.
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
    var new_tab = findById(tab_array, tabId);
    if (is_forbidden(tab.url) == true){
        // Tab does not exists<commit_msg>Reload forbidden_url array on save<commit_after>/*
 Author:     <NAME>
             <EMAIL>
 All rights reserved.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
 1. Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
 2. Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.
 3. The name of the author may not be used to endorse or promote products
    derived from this software without specific prior written permission.

 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

var tab_array = [];
var FORBIDDEN_URL_ORIG = ["chrome://", "chrome-extension://", "chrome-devtools://"];
var FORBIDDEN_URL = FORBIDDEN_URL_ORIG;
var TIMEOUT_TIMER = 15;
if (localStorage.getItem("timer") !== null)
    TIMEOUT_TIMER = localStorage["timer"];

if (localStorage.getItem("exclude_list") !== null)
    FORBIDDEN_URL = FORBIDDEN_URL_ORIG.concat(localStorage["exclude_list"].split('\n'));

window.addEventListener("storage", update_storage, false);
chrome.alarms.create({periodInMinutes: 1.0});

// When users changes the options, update the timer value
function update_storage(event_storage) {
    if (event_storage.key === "timer") {
        TIMEOUT_TIMER = event_storage.newValue;
    } else if (event_storage.key === "exclude_list") {
        if (event_storage.newValue === "") {
            FORBIDDEN_URL = FORBIDDEN_URL_ORIG;
            return;
        }
        FORBIDDEN_URL = FORBIDDEN_URL_ORIG.concat(event_storage.newValue.split('\n'));
    }
}

// Returns true if a url is forbidden, false otherwise
function is_forbidden(url) {
    var found = false;
    FORBIDDEN_URL.forEach(function(f_url) {
        if (url.indexOf(f_url) !== -1) found = true;
    });
    return found;
}

function findById(source, id) {
    return source.filter(function( obj ) {
        // coerce both obj.id and id to numbers
        // for val & type comparison
        return +obj.id === +id;
    })[ 0 ];
}

// On startup, get all tabs already created
chrome.windows.getAll({populate: true}, function (windows){
    windows.forEach(function(cwindow) {
        cwindow.tabs.forEach(function(tab) {
            if (is_forbidden(tab.url) == true) return;
            tab_array.push({id: tab.id, timer: 0, killed: false });
        });
    });
});

// When a tab gets a suitable URL and is not already in our array, add it.
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
    var new_tab = findById(tab_array, tabId);
    if (is_forbidden(tab.url) == true){
        // Tab does not exists
{'fraction_non_alphanumeric': 0.09528116990803558, 'fraction_numerical': 0.003015226895823911, 'mean_word_length': 3.6916548797736914, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1745630', 'n_tokens_mistral': 1921, 'n_tokens_neox': 1803, 'n_words': 712}