<commit_before>﻿var MasterTab = {
    session: {
        id: new Date().toISOString(),
        startTime: new Date(),
    },
    pages: {
        listPage: {
            name: 'list.html',
            url: chrome.extension.getURL('list.html'),
            open: function () {
                MasterTab.pages.open(this);
            },
        }
    }
};

MasterTab.getTabKey = function (tabId) {
    return this.id + '_' + tabId;
};

MasterTab.pages.open = function (page) {
    var optionsUrl = page.url;
    chrome.tabs.query({}, function (extensionTabs) {
        var found = false;
        for (var i = 0; i < extensionTabs.length; i++) {
            if (optionsUrl == extensionTabs[i].url) {
                found = true;
                console.log("tab id: " + extensionTabs[i].id);
                chrome.tabs.reload(extensionTabs[i].id, null, null);
            }
        }
        if (found == false) {
            chrome.tabs.create({ url: page.url });
        }
    });
};

MasterTab.session.tabs = {
    get: function(tabId){
        return this['_' + tabId];
    },

    add: function(nTabId, sUrl){
            var tabInfo = {
                session: MasterTab.session.id,
                storageKey: MasterTab.getTabKey(nTabId),
                url: sUrl,
                title: sUrl,
                favIconUrl: null,
            }
            this['_' + nTabId] = tabInfo;
            return tabInfo;
        },

    remove: function(tabId) {
        var key = MasterTab.getTabKey(tabId);
        MasterTab.history.remove(key);
        delete this['_' + tabId];
    }
};

MasterTab.history = {
    save: function(tabInfo) {
        var data = {};
        data[tabInfo.storageKey] = tabInfo;

        chrome.storage.local.set(data, function () {
            console.log('Saved %s to storage', tabInfo.url);
            MasterTab.pages.listPage.open();
        });
    },

    remove: function (key) {
        chrome.storage.local.remove(key, function () {
            console.log('Removed %s from storage', key);
            MasterTab.pages.listPage.open();
        });
    },

    getAll: function(callback) {
        chrome.storage.local.get(
			null,
            callback);
    },

    clear: function () {
        chrome.storage.local.clear(function () {
            console.log('Tab history was cleared.');
        });
    },
};<commit_msg>Improved how history.clear worked. Now it will clear the in memory list as well so that the scheduled scan can run and put those tabs back in history. Next improvement should be to run this scan immediately after clearing.<commit_after>﻿var MasterTab = {
    session: {
        id: new Date().toISOString(),
        startTime: new Date(),
    },
    pages: {
        listPage: {
            name: 'list.html',
            url: chrome.extension.getURL('list.html'),
            open: function () {
                MasterTab.pages.open(this);
            },
        }
    },
    config: {
        TABID_PREFIX : 'T_',
    },
};

MasterTab.getTabKey = function (tabId) {
    return this.id + '_' + tabId;
};

MasterTab.pages.open = function (page) {
    var optionsUrl = page.url;
    chrome.tabs.query({}, function (extensionTabs) {
        var found = false;
        for (var i = 0; i < extensionTabs.length; i++) {
            if (optionsUrl == extensionTabs[i].url) {
                found = true;
                console.log("tab id: " + extensionTabs[i].id);
                chrome.tabs.reload(extensionTabs[i].id, null, null);
            }
        }
        if (found == false) {
            chrome.tabs.create({ url: page.url });
        }
    });
};

MasterTab.session.tabs = {
    get: function(tabId){
        return this[MasterTab.config.TABID_PREFIX + tabId];
    },

    add: function(nTabId, sUrl){
            var tabInfo = {
                session: MasterTab.session.id,
                storageKey: MasterTab.getTabKey(nTabId),
                url: sUrl,
                title: sUrl,
                favIconUrl: null,
            }
            this[MasterTab.config.TABID_PREFIX + nTabId] = tabInfo;
            return tabInfo;
        },

    remove: function(tabId) {
        var key = MasterTab.getTabKey(tabId);
        MasterTab.history.remove(key);
        delete this[MasterTab.config.TABID_PREFIX + tabId];
    }
};

MasterTab.history = {
    save: function(tabInfo) {
        var data = {};
        data[tabInfo.storageKey] = tabInfo;

        chrome.storage.local.set(data, function () {
            console.log('Saved %s to storage', tabInfo.url);
            MasterTab.pages.listPage.open();
        });
    },

    remove: function (key) {
        chrome.storage.local.remove(key, function () {
            console.log('Removed %s from storage', key);
            MasterTab.pages.listPage.open();
        });
    },

    getAll: function(callback) {
        chrome.storage.local.get(
			null,
            callback);
    },

    clear: function () {
        // Remove the items that are in memory
        var tabs = MasterTab.session.tabs;
        for (var id in tabs) {
            if (tabs.hasOwnProperty(id) && id.substring(0, MasterTab.config.TABID_PREFIX.length) == MasterTab.config.TABID_PREFIX) {
                tabs.remove(id.substring(MasterTab.config.TABID_PREFIX.length));
            }
        };
        // Clear the history
        chrome.storage.local.clear(function () {
            console.log('Tab history was cleared.');
        });
    },
};
{'fraction_non_alphanumeric': 0.13313772235466714, 'fraction_numerical': 0.0005501558774986246, 'mean_word_length': 1.7352056168505516, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '297313', 'n_tokens_mistral': 1651, 'n_tokens_neox': 1588, 'n_words': 331}