<commit_before>/**
 * options-main.js
 */

import {
  isObjectNotEmpty, isString, logErr, throwErr,
} from "./common.js";
import {
  getStorage, removePermission, requestPermission,
} from "./browser.js";

/* api */
const {i18n, runtime} = browser;

/* constants */
import {
  EDITOR_CONFIG_RES, EDITOR_FILE_NAME, EDITOR_LABEL, EXT_RELOAD,
  HOST_CONNECTION, HOST_ERR_NOTIFY, HOST_STATUS, HOST_STATUS_GET, HOST_VERSION,
  HOST_VERSION_LATEST, STORAGE_SET, SYNC_AUTO_URL, WARN,
} from "./constant.js";
const PORT_NAME = "portOptions";

/* port */
export const port = runtime.connect({name: PORT_NAME});

/**
 * post message
 * @param {*} msg - message
 * @returns {void}
 */
export const postMsg = async msg => {
  if (msg) {
    port.postMessage(msg);
  }
};

/**
 * get host status
 * @returns {AsyncFunction} - port message
 */
export const getHostStatus = async () => postMsg({[HOST_STATUS_GET]: true});

/**
 * create pref
 * @param {Object} elm - element
 * @param {boolean} executable - executable
 * @returns {Object} - pref data
 */
export const createPref = async (elm, executable = false) => {
  const id = elm && elm.id;
  return id && {
    [STORAGE_SET]: {
      [id]: {
        id,
        app: {
          executable: !!executable,
        },
        checked: !!elm.checked,
        value: elm.value || "",
      },
    },
  } || null;
};

/**
 * extract editor config
 * @param {string} obj - editor config object
 * @returns {void}
 */
export const extractEditorConfig = async (obj = {}) => {
  const {editorLabel, editorName, executable} = obj;
  const name = document.getElementById(EDITOR_FILE_NAME);
  const label = document.getElementById(EDITOR_LABEL);
  if (name) {
    name.value = editorName || "";
  }
  if (label) {
    if (executable && (editorLabel || editorName)) {
      label.value = editorLabel || editorName;
      label.disabled = false;
    } else {
      label.value = "";
      label.disabled = true;
    }
  }
};

/**
 * extract host status
 * @param {Object} status - host status
 * @returns {void}
 */
export const extractHostStatus = async status => {
  const {hostCompatibility, hostConnection, hostLatestVersion} = status;
  const latest = document.getElementById(HOST_VERSION_LATEST);
  const connect = document.getElementById(HOST_CONNECTION);
  const version = document.getElementById(HOST_VERSION);
  if (latest && hostLatestVersion) {
    latest.textContent =
      i18n.getMessage("hostLatestVersion", `v${hostLatestVersion}`);
  }
  if (connect) {
    connect.textContent = i18n.getMessage(`hostConnection_${hostConnection}`);
    if (hostConnection) {
      connect.classList.remove(WARN);
    } else {
      connect.classList.add(WARN);
    }
  }
  if (version) {
    version.textContent = i18n.getMessage(`hostVersion_${hostCompatibility}`);
    if (hostCompatibility) {
      version.classList.remove(WARN);
    } else {
      version.classList.add(WARN);
    }
  }
};

/**
 * extract sync urls input
 * @param {!Object} evt - Event
 * @returns {?AsyncFunction} - post message
 */
export const extractSyncUrls = async evt => {<commit_msg>Update options-main.js<commit_after>/**
 * options-main.js
 */

import {
  isObjectNotEmpty, isString, logErr, throwErr,
} from "./common.js";
import {
  getStorage, removePermission, requestPermission,
} from "./browser.js";

/* api */
const {i18n, runtime} = browser;

/* constants */
import {
  EDITOR_CONFIG_RES, EDITOR_FILE_NAME, EDITOR_LABEL, EXT_RELOAD,
  HOST_CONNECTION, HOST_ERR_NOTIFY, HOST_STATUS, HOST_STATUS_GET, HOST_VERSION,
  HOST_VERSION_LATEST, STORAGE_SET, SYNC_AUTO_URL, WARN,
} from "./constant.js";
const PORT_NAME = "portOptions";

/* port */
export const port = runtime.connect({name: PORT_NAME});

/**
 * post message
 * @param {*} msg - message
 * @returns {void}
 */
export const postMsg = async msg => {
  if (msg) {
    port.postMessage(msg);
  }
};

/**
 * get host status
 * @returns {AsyncFunction} - port message
 */
export const getHostStatus = async () => postMsg({[HOST_STATUS_GET]: true});

/**
 * create pref
 * @param {Object} elm - element
 * @param {boolean} executable - executable
 * @returns {Object} - pref data
 */
export const createPref = async (elm, executable = false) => {
  const id = elm && elm.id;
  return id && {
    [STORAGE_SET]: {
      [id]: {
        id,
        app: {
          executable: !!executable,
        },
        checked: !!elm.checked,
        value: elm.value || "",
      },
    },
  } || null;
};

/**
 * extract editor config
 * @param {string} obj - editor config object
 * @returns {void}
 */
export const extractEditorConfig = async (obj = {}) => {
  const {editorLabel, editorName, executable} = obj;
  const name = document.getElementById(EDITOR_FILE_NAME);
  const label = document.getElementById(EDITOR_LABEL);
  if (name) {
    name.value = editorName || "";
  }
  if (label) {
    if (executable && (editorLabel || editorName)) {
      label.value = editorLabel || editorName;
      label.disabled = false;
    } else {
      label.value = "";
      label.disabled = true;
    }
  }
};

/**
 * extract host status
 * @param {Object} status - host status
 * @returns {void}
 */
export const extractHostStatus = async status => {
  const {hostCompatibility, hostConnection, hostLatestVersion} = status;
  const latest = document.getElementById(HOST_VERSION_LATEST);
  const connect = document.getElementById(HOST_CONNECTION);
  const version = document.getElementById(HOST_VERSION);
  if (latest && hostLatestVersion) {
    latest.textContent =
      i18n.getMessage("hostLatestVersion", `v${hostLatestVersion}`);
  } else {
    latest.textContent = "";
  }
  if (connect) {
    connect.textContent = i18n.getMessage(`hostConnection_${hostConnection}`);
    if (hostConnection) {
      connect.classList.remove(WARN);
    } else {
      connect.classList.add(WARN);
    }
  }
  if (version) {
    version.textContent = i18n.getMessage(`hostVersion_${hostCompatibility}`);
    if (hostCompatibility) {
      version.classList.remove(WARN);
    } else {
      version.classList.add(WARN);
    }
  }
};

/**
 * extract sync urls input
 * @param {!Object} evt - Event
 * @returns {?AsyncFunction} - post message
 */
export const extractSyncUrls = async evt => {
{'fraction_non_alphanumeric': 0.14413981080647748, 'fraction_numerical': 0.002565335898669232, 'mean_word_length': 3.353105373342638, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '4003325', 'n_tokens_mistral': 1977, 'n_tokens_neox': 1990, 'n_words': 459}