<commit_before>function init() {
    chrome.tabs.getSelected(null, function(tab) {
        chrome.tabs.sendRequest(tab.id, {getTitles: true}, function(titles) {
            appendItem(null);
            sortedKeys(titles).forEach(appendItem);
        });
    });
}

function appendItem(title) {
    var alternates = document.getElementById('alternates');
    var li = document.createElement('li');
    if (title === null) {
        li.innerHTML = '(None)';
        li.data = null;
    } else {
        li.innerHTML = title.length > 0 ? title : '(Default)';
        li.data = title;
    }
    li.onmouseup = function(event) {
        chrome.tabs.getSelected(null, function(tab) {
            chrome.tabs.sendRequest(tab.id, {
                selectStyle: true,
                style: li.data
            });
        });
    };
    alternates.appendChild(li);
}

function sortedKeys(obj) {
    var keys = [];
    for (var k in obj) keys.push(k);
    keys.sort();
    return keys;
}<commit_msg>Close popup after selecting an item<commit_after>function init() {
    chrome.tabs.getSelected(null, function(tab) {
        chrome.tabs.sendRequest(tab.id, {getTitles: true}, function(titles) {
            appendItem(null);
            sortedKeys(titles).forEach(appendItem);
        });
    });
}

function appendItem(title) {
    var alternates = document.getElementById('alternates');
    var li = document.createElement('li');
    if (title === null) {
        li.innerHTML = '(None)';
        li.data = null;
    } else {
        li.innerHTML = title.length > 0 ? title : '(Default)';
        li.data = title;
    }
    li.onmouseup = function(event) {
        chrome.tabs.getSelected(null, function(tab) {
            chrome.tabs.sendRequest(tab.id, {
                selectStyle: true,
                style: li.data
            });
            window.close();
        });
    };
    alternates.appendChild(li);
}

function sortedKeys(obj) {
    var keys = [];
    for (var k in obj) keys.push(k);
    keys.sort();
    return keys;
}
{'fraction_non_alphanumeric': 0.14468503937007873, 'fraction_numerical': 0.000984251968503937, 'mean_word_length': 2.1470588235294117, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4449746', 'n_tokens_mistral': 625, 'n_tokens_neox': 610, 'n_words': 118}