<commit_before>var panelId = undefined;

function onCreated(windowInfo) {
    console.log(`Create editor successfully: id = ${windowInfo.id}`);
    panelId = windowInfo.id;
}

function onError(error) {
    console.log(`Error: ${error}`);
}

function openPage() {
    var getContentWindowInfo = browser.windows.getLastFocused();
    var getSideexWindowInfo = browser.windows.create({
        url: browser.extension.getURL("panel.html"),
        type: "popup",
        height: 730,
        width: 695
    });

    Promise.all([getContentWindowInfo, getSideexWindowInfo])
    .then(function(windowInfo) {
        console.log("get the window info")
        let contentWindowInfo = windowInfo[0];
        let sideexWindowInfo = windowInfo[1];
        return new Promise(function(resolve, reject) {
            let count = 0;
            let interval = setInterval(function() {
                if (count > 100) {
                    reject("SideeX editor has no response");
                    clearInterval(interval);
                }

                browser.tabs.query({
                    active: true,
                    windowId: sideexWindowInfo.id
                }).then(function(tabs) {
                    if (tabs.length != 1) {
                        count++;
                        return;
                    }
                    let sideexTabInfo = tabs[0];
                    if (sideexTabInfo.status == "loading") {
                        count++;
                        return;
                    } else {
                        console.log("SideeX has been fully loaded")
                        resolve(windowInfo);
                        clearInterval(interval);
                    }
                })
            }, 200);
        });
    }).then(passWindowId)
    .catch(function(e) {
        console.log(e);
    });

    browser.contextMenus.create({
    id: "verifyText",
    title: "verifyText"
	});
	browser.contextMenus.create({
	    id: "verifyTitle",
	    title: "verifyTitle"
	});
	browser.contextMenus.create({
	    id: "assertText",
	    title: "assertText"
	});
	browser.contextMenus.create({
	    id: "assertTitle",
	    title: "assertTitle"
	});
	browser.contextMenus.create({
	    id: "storeText",
	    title: "storeText"
	    //contexts: ["all"]
	});
	browser.contextMenus.create({
	    id: "storeTitle",
	    title: "storeTitle"
	    //contexts: ["all"]
	});

}

browser.browserAction.onClicked.addListener(openPage);

function disconnectAllTabs(tabs) {
    for (let tab of tabs) {
        browser.tabs.sendMessage(tab.id, { active: false });
    }
}

function queryError(error) {
    console.log(`Error: ${error}`);
}

browser.windows.onRemoved.addListener(function(windowId) {
    if (windowId === panelId) {<commit_msg>Enable extension contextMenu in Sideex's panel<commit_after>var panelId = undefined;

function onCreated(windowInfo) {
    console.log(`Create editor successfully: id = ${windowInfo.id}`);
    panelId = windowInfo.id;
}

function onError(error) {
    console.log(`Error: ${error}`);
}

function openPage() {
    var getContentWindowInfo = browser.windows.getLastFocused();
    var getSideexWindowInfo = browser.windows.create({
        url: browser.extension.getURL("panel.html"),
        type: "popup",
        height: 730,
        width: 695
    });

    Promise.all([getContentWindowInfo, getSideexWindowInfo])
    .then(function(windowInfo) {
        console.log("get the window info")
        let contentWindowInfo = windowInfo[0];
        let sideexWindowInfo = windowInfo[1];
        console.log("ContentWindowInfo Id:" + contentWindowInfo.id);
        console.log("sideexWindowInfo Id:" + sideexWindowInfo.id);
        return new Promise(function(resolve, reject) {
            let count = 0;
            let interval = setInterval(function() {
                if (count > 100) {
                    reject("SideeX editor has no response");
                    clearInterval(interval);
                }

                browser.tabs.query({
                    active: true,
                    windowId: sideexWindowInfo.id
                }).then(function(tabs) {
                    if (tabs.length != 1) {
                        count++;
                        return;
                    }
                    let sideexTabInfo = tabs[0];
                    if (sideexTabInfo.status == "loading") {
                        count++;
                        return;
                    } else {
                        console.log("SideeX has been fully loaded")
                        resolve(windowInfo);
                        clearInterval(interval);
                    }
                })
            }, 200);
        });
    }).then(passWindowId)
    .catch(function(e) {
        console.log(e);
    });

    browser.contextMenus.create({
	    id: "verifyText",
	    title: "verifyText",
	    documentUrlPatterns: ["<all_urls>"]
	});
	browser.contextMenus.create({
	    id: "verifyTitle",
	    title: "verifyTitle",
    	documentUrlPatterns: ["<all_urls>"]
	});
	browser.contextMenus.create({
	    id: "assertText",
	    title: "assertText",
	    documentUrlPatterns: ["<all_urls>"]
	});
	browser.contextMenus.create({
	    id: "assertTitle",
	    title: "assertTitle",
	    documentUrlPatterns: ["<all_urls>"]
	});
	browser.contextMenus.create({
	    id: "storeText",
	    title: "storeText",
	    documentUrlPatterns: ["<all_urls>"]
	    //contexts: ["all"]
	});
	browser.contextMenus.create({
	    id: "storeTitle",
	    title: "storeTitle",
	    documentUrlPatterns: ["<all_urls>"]
	    //contexts: ["all"]
	});

}

browser.browserAction.onClicked.addListener(openPage);

function disconnectAllTabs(tabs) {
    for (let tab of tabs) {
        browser.tabs.sendMessage(tab.id, { active: false });
    }
}

function queryError(error) {
    console.log(`Error: ${error}`);
}

browser.windows.onRemoved.addListener(function(windowId) {
    if (windowId === panelId) {
{'fraction_non_alphanumeric': 0.12934071464519376, 'fraction_numerical': 0.005703740983056534, 'mean_word_length': 1.9340551181102361, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '5150335', 'n_tokens_mistral': 1762, 'n_tokens_neox': 1661, 'n_words': 319}