<commit_before>var activeTabs = {};

chrome.browserAction.onClicked.addListener(function (tab) {
    if (activeTabs[tab.id]) {
        chrome.tabs.sendMessage(tab.id, {action: "undo-swap-images"});

        chrome.browserAction.setIcon({
            path: {
                '19': 'images/inactive19.png',
                '38': 'images/inactive38.png'
            },
            tabId: tab.id
        });
        delete activeTabs[tab.id];
    } else {
        chrome.tabs.sendMessage(tab.id, {action: "swap-images"});

        chrome.browserAction.setIcon({
            path: {
                '19': 'images/active19.png',
                '38': 'images/active38.png'
            },
            tabId: tab.id
        });
        activeTabs[tab.id] = true;
    }
});<commit_msg>Move into functions the logic for activating and deactivating the plugin on tabs<commit_after>var activeOnTabs = {};

function activateOnTab(tab) {
    chrome.tabs.sendMessage(tab.id, {action: "swap-images"});

    chrome.browserAction.setIcon({
        path: {
            '19': 'images/active19.png',
            '38': 'images/active38.png'
        },
        tabId: tab.id
    });
    activeOnTabs[tab.id] = true;
}

function deactivateOnTab(tab) {
    chrome.tabs.sendMessage(tab.id, {action: "undo-swap-images"});

    chrome.browserAction.setIcon({
        path: {
            '19': 'images/inactive19.png',
            '38': 'images/inactive38.png'
        },
        tabId: tab.id
    });
    delete activeOnTabs[tab.id];
}

chrome.browserAction.onClicked.addListener(function(tab) {
    if (activeOnTabs[tab.id]) {
        deactivateOnTab(tab);
    } else {
        activateOnTab(tab);
    }
});
{'fraction_non_alphanumeric': 0.1488095238095238, 'fraction_numerical': 0.01904761904761905, 'mean_word_length': 2.056363636363636, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3331212', 'n_tokens_mistral': 571, 'n_tokens_neox': 532, 'n_words': 83}