<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

async function handle_summary_button_click() {
    try {
        let url = browser.extension.getURL("summary/index.html"),
            // we have to query then filter because we can't query for
            // non-standard add-on url directly
            tabs = await browser.tabs.query({}),
            summaryTab = tabs.filter((t) => t.url === url);

        if (summaryTab[0]) {
            browser.windows.update(summaryTab[0].windowId, {focused: true});
            browser.tabs.update(summaryTab[0].id, {active: true});
        } else {
            browser.tabs.create({url: url});
        }
        window.close();
    } catch (e) {
        console.error(e);
    }
};

document.getElementById("summaryButton").addEventListener('click', handle_summary_button_click);
<commit_msg>Fix 'open summary page' so it always activates an open summary tab<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

async function handle_summary_button_click() {
    try {
        let url = browser.extension.getURL("summary/index.html"),
            // we have to query then filter because we can't query for
            // non-standard add-on url directly
            tabs = await browser.tabs.query({}),
            summaryTab = tabs.filter((t) => t.url === url);

        if (summaryTab[0]) {
            // We have to activate the tab first because if the active window
            // changes, the popup closes, taking this code down with it.
            await browser.tabs.update(summaryTab[0].id, {active: true});
            await browser.windows.update(summaryTab[0].windowId, {focused: true});
        } else {
            browser.tabs.create({url: url});
        }
        // Close the popup dropdown, if it is still open and this code is still
        // running.
        window.close();
    } catch (e) {
        console.error(e);
    }
};

document.getElementById("summaryButton").addEventListener('click', handle_summary_button_click);

{'fraction_non_alphanumeric': 0.11994840928632847, 'fraction_numerical': 0.0060189165950128975, 'mean_word_length': 2.4070278184480234, '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': '4205330', 'n_tokens_mistral': 647, 'n_tokens_neox': 625, 'n_words': 212}