<commit_before>/* SPDX-License-Identifier: MPL-2.0 */

import { DefaultOptions } from "../options/defaults.js";
import { FullLanguageList } from "../options/list-languages.js";

const AddonName = browser.runtime.getManifest().name;

/*
 * Paths.
 */
const gHLJSPath = "../highlightjs/highlight.min.js";
const gContentScript = "../scripts/enlight-content.js";

/*
 * Current page status: highlighted, or not.
 */
let isHighlighted = false;

/*
 * Initialize options with default values.
 */
const options = JSON.parse(JSON.stringify(DefaultOptions));

/*
 * Callback.
 */
function onError (error) {
    console.error(`[${AddonName}] Error:`, error);
}

/*
 * Reload one option from storage.
 */
function reloadOption (aId, aDefault) {
    const gettingItem = browser.storage.local.get(aId);
    return gettingItem.then((res) => {
        if (res[aId] !== undefined) {
            options[aId] = res[aId];
        }
    }, onError);
}

/*
 * Update button tooltip label ("title").
 */
function updateTitle (aLanguageId) {
    if (aLanguageId) {
        let title = "Enlight [";
        for (const l of FullLanguageList) {
            if (l.class === aLanguageId) {
                title += l.name;
                break;
            }
        }
        title += "]";
        browser.browserAction.setTitle({
            title: title,
        });
    } else {
        browser.browserAction.setTitle({ title: "Enlight" });
    }
}

/*
 * Actually trigger syntax highlighting by injecting content scripts.
 */
function doHighlight (aLanguageId) {
    browser.tabs.executeScript({
        file: gHLJSPath,
    }).then(() => {
        browser.tabs.executeScript({
            code:
        "window.enlightContentScriptOptions = {" +
        "  language: '" + aLanguageId + "'," +
        "  fileExt: " + options.fileext + "," +
        "  lineNumbers: " + options.linenumbers + "," +
        "  tabSize: " + options.tabsize + "," +
        "  langList: " + JSON.stringify(options.langlist) +
        "};",
        }).then(() => {
            browser.tabs.executeScript({
                file: gContentScript,<commit_msg>Name const variables with a capital letter<commit_after>/* SPDX-License-Identifier: MPL-2.0 */

import { DefaultOptions } from "../options/defaults.js";
import { FullLanguageList } from "../options/list-languages.js";

const AddonName = browser.runtime.getManifest().name;

/*
 * Paths.
 */
const HLJSPath = "../highlightjs/highlight.min.js";
const ContentScript = "../scripts/enlight-content.js";

/*
 * Current page status: highlighted, or not.
 */
let isHighlighted = false;

/*
 * Initialize options with default values.
 */
const options = JSON.parse(JSON.stringify(DefaultOptions));

/*
 * Callback.
 */
function onError (error) {
    console.error(`[${AddonName}] Error:`, error);
}

/*
 * Reload one option from storage.
 */
function reloadOption (aId, aDefault) {
    const gettingItem = browser.storage.local.get(aId);
    return gettingItem.then((res) => {
        if (res[aId] !== undefined) {
            options[aId] = res[aId];
        }
    }, onError);
}

/*
 * Update button tooltip label ("title").
 */
function updateTitle (aLanguageId) {
    if (aLanguageId) {
        let title = "Enlight [";
        for (const l of FullLanguageList) {
            if (l.class === aLanguageId) {
                title += l.name;
                break;
            }
        }
        title += "]";
        browser.browserAction.setTitle({
            title: title,
        });
    } else {
        browser.browserAction.setTitle({ title: "Enlight" });
    }
}

/*
 * Actually trigger syntax highlighting by injecting content scripts.
 */
function doHighlight (aLanguageId) {
    browser.tabs.executeScript({
        file: HLJSPath,
    }).then(() => {
        browser.tabs.executeScript({
            code:
        "window.enlightContentScriptOptions = {" +
        "  language: '" + aLanguageId + "'," +
        "  fileExt: " + options.fileext + "," +
        "  lineNumbers: " + options.linenumbers + "," +
        "  tabSize: " + options.tabsize + "," +
        "  langList: " + JSON.stringify(options.langlist) +
        "};",
        }).then(() => {
            browser.tabs.executeScript({
                file: ContentScript,
{'fraction_non_alphanumeric': 0.15478710891554928, 'fraction_numerical': 0.0009409550693954364, 'mean_word_length': 2.2935708752904724, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '7123895', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1256, 'n_words': 263}