<commit_before>/**
 * tab-group.js
 */

/* shared */
import {
  addElementContentEditable, getType, isObjectNotEmpty,
  removeElementContentEditable, throwErr
} from './common.js';
import { getStorage, getTab, queryTabs } from './browser.js';
import { moveTabsInOrder } from './browser-tabs.js';
import { bookmarkTabs } from './bookmark.js';
import {
  activateTab, createUrlMatchString, getSidebarTab, getSidebarTabContainer,
  getSidebarTabId, getSidebarTabIndex, getTemplate, requestSaveSession
} from './util.js';
import {
  ACTIVE,
  CLASS_GROUP, CLASS_HEADING, CLASS_HEADING_LABEL, CLASS_HEADING_LABEL_EDIT,
  CLASS_TAB_COLLAPSED, CLASS_TAB_CONTAINER_TMPL, CLASS_TAB_CONTEXT,
  CLASS_TAB_CONTAINER, CLASS_TAB_GROUP, CLASS_UNGROUP,
  HIGHLIGHTED, NEW_TAB, PINNED, TAB_GROUP_COLLAPSE, TAB_GROUP_ENABLE,
  TAB_GROUP_EXPAND, TAB_GROUP_LABEL_EDIT, TAB_QUERY
} from './constant.js';

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

/**
 * restore sidebar tab containers
 *
 * @returns {void}
 */
export const restoreTabContainers = async () => {
  const body = document.querySelector('body');
  const items =
    document.querySelectorAll(`.${CLASS_TAB_CONTAINER}:not(#${NEW_TAB})`);
  let group;
  for (const item of items) {
    const { classList, id, parentNode } = item;
    const tabLength = item.querySelectorAll(TAB_QUERY).length;
    switch (tabLength) {
      case 0:
        id !== PINNED && parentNode.removeChild(item);
        break;
      case 1:
        classList.remove(CLASS_TAB_GROUP);
        break;
      default:
        classList.add(CLASS_TAB_GROUP);
        group = true;
    }
  }
  if (group) {
    body.classList.add(CLASS_GROUP);
  } else {
    body.classList.remove(CLASS_GROUP);
  }
};

/**
 * collapse tab group
 *
 * @param {object} elm - element
 * @param {boolean} activate - activate element
 * @returns {void}
 */
export const collapseTabGroup = async (elm, activate) => {
  const body = document.querySelector('body');
  if (elm && elm.nodeType === Node.ELEMENT_NODE &&
      elm.classList.contains(CLASS_TAB_GROUP) &&
      !body.classList.contains(CLASS_UNGROUP)) {
    const heading = elm.querySelector(`.${CLASS_HEADING}:not([hidden])`);
    const controller = heading || elm.querySelector(TAB_QUERY);
    const { firstElementChild: context } = controller;
    const { firstElementChild: toggleIcon } = context;
    elm.classList.add(CLASS_TAB_COLLAPSED);
    if (heading) {
      if (activate) {
        heading.classList.add(ACTIVE);
      } else {
        heading.classList.remove(ACTIVE);
      }
    }
    context.title = i18n.getMessage(`${TAB_GROUP_EXPAND}_tooltip`);
    toggleIcon.alt = i18n.getMessage(TAB_GROUP_EXPAND);
  }
};

/**
 * expand tab group
 *
 * @param {object} elm - element
 * @returns {void}
 */
export const expandTabGroup = async elm => {
  if (elm && elm.nodeType === Node.ELEMENT_NODE &&
      elm.classList.contains(CLASS_TAB_GROUP)) {
    const heading = elm.querySelector(`.${CLASS_HEADING}:not([hidden])`);
    const controller = heading || elm.querySelector(TAB_QUERY);
    const { firstElementChild: context } = controller;
    const { firstElementChild: toggleIcon } = context;
    elm.classList.remove(CLASS_TAB_COLLAPSED);
    heading && heading.classList.remove(ACTIVE);
    context.title = i18n.getMessage(`${TAB_GROUP_COLLAPSE}_tooltip`);
    toggleIcon.alt = i18n.getMessage(TAB_GROUP_COLLAPSE);
  }
};

/**
 * toggle enable / disable tab grouping
 *
 * @returns {Promise.<Array>} - results of each handler
 */
export const toggleTabGrouping = async () => {
  const body = document.querySelector('body');
  const store = await getStorage([TAB_GROUP_ENABLE]);
  const items =
    document.querySelectorAll(`.${CLASS_TAB_CONTAINER}:not(#${NEW_TAB})`);
  const func = [];
  let enable;
  if (isObjectNotEmpty(store)) {
    const { enableTabGroup } = store;
    enable = !!enableTabGroup.checked;
  } else {
    enable = true;
  }
  if (enable) {<commit_msg>Update tab-group.js<commit_after>/**
 * tab-group.js
 */

/* shared */
import {
  addElementContentEditable, getType, isObjectNotEmpty,
  removeElementContentEditable, throwErr
} from './common.js';
import { getStorage, getTab, queryTabs } from './browser.js';
import { moveTabsInOrder } from './browser-tabs.js';
import { bookmarkTabs } from './bookmark.js';
import {
  activateTab, createUrlMatchString, getSidebarTab, getSidebarTabContainer,
  getSidebarTabId, getSidebarTabIndex, getTemplate, requestSaveSession
} from './util.js';
import {
  ACTIVE,
  CLASS_GROUP, CLASS_HEADING, CLASS_HEADING_LABEL, CLASS_HEADING_LABEL_EDIT,
  CLASS_TAB_COLLAPSED, CLASS_TAB_CONTAINER_TMPL, CLASS_TAB_CONTEXT,
  CLASS_TAB_CONTAINER, CLASS_TAB_GROUP, CLASS_UNGROUP,
  HIGHLIGHTED, NEW_TAB, PINNED, TAB_GROUP_COLLAPSE, TAB_GROUP_ENABLE,
  TAB_GROUP_EXPAND, TAB_GROUP_LABEL_EDIT, TAB_QUERY
} from './constant.js';

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

/**
 * restore sidebar tab containers
 *
 * @returns {void}
 */
export const restoreTabContainers = async () => {
  const body = document.querySelector('body');
  const items =
    document.querySelectorAll(`.${CLASS_TAB_CONTAINER}:not(#${NEW_TAB})`);
  let group;
  for (const item of items) {
    const { classList, id, parentNode } = item;
    const tabLength = item.querySelectorAll(TAB_QUERY).length;
    switch (tabLength) {
      case 0:
        id !== PINNED && parentNode.removeChild(item);
        break;
      case 1:
        classList.remove(CLASS_TAB_GROUP);
        break;
      default:
        classList.add(CLASS_TAB_GROUP);
        group = true;
    }
  }
  if (group) {
    body.classList.add(CLASS_GROUP);
  } else {
    body.classList.remove(CLASS_GROUP);
  }
};

/**
 * collapse tab group
 *
 * @param {object} elm - element
 * @param {boolean} activate - activate element
 * @returns {void}
 */
export const collapseTabGroup = async (elm, activate) => {
  const body = document.querySelector('body');
  if (elm && elm.nodeType === Node.ELEMENT_NODE &&
      elm.classList.contains(CLASS_TAB_GROUP) &&
      !body.classList.contains(CLASS_UNGROUP)) {
    const heading = elm.querySelector(`.${CLASS_HEADING}:not([hidden])`);
    const controller = heading || elm.querySelector(TAB_QUERY);
    const { firstElementChild: context } = controller;
    const { firstElementChild: toggleIcon } = context;
    elm.classList.add(CLASS_TAB_COLLAPSED);
    if (heading) {
      if (activate) {
        heading.classList.add(ACTIVE);
      } else {
        heading.classList.remove(ACTIVE);
      }
    }
    context.title = i18n.getMessage(`${TAB_GROUP_EXPAND}_tooltip`);
    toggleIcon.alt = i18n.getMessage(TAB_GROUP_EXPAND);
  }
};

/**
 * expand tab group
 *
 * @param {object} elm - element
 * @returns {void}
 */
export const expandTabGroup = async elm => {
  if (elm && elm.nodeType === Node.ELEMENT_NODE &&
      elm.classList.contains(CLASS_TAB_GROUP)) {
    const heading = elm.querySelector(`.${CLASS_HEADING}:not([hidden])`);
    const controller = heading || elm.querySelector(TAB_QUERY);
    const { firstElementChild: context } = controller;
    const { firstElementChild: toggleIcon } = context;
    elm.classList.remove(CLASS_TAB_COLLAPSED);
    heading && heading.classList.remove(ACTIVE);
    context.title = i18n.getMessage(`${TAB_GROUP_COLLAPSE}_tooltip`);
    toggleIcon.alt = i18n.getMessage(TAB_GROUP_COLLAPSE);
  }
};

/**
 * toggle enable / disable tab grouping
 *
 * @returns {Promise.<Array>} - results of each handler
 */
export const toggleTabGrouping = async () => {
  const body = document.querySelector('body');
  const items =
    document.querySelectorAll(`.${CLASS_TAB_CONTAINER}:not(#${NEW_TAB})`);
  const store = await getStorage([TAB_GROUP_ENABLE]);
  const func = [];
  let enable;
  if (isObjectNotEmpty(store)) {
    const { enableTabGroup } = store;
    enable = !!enableTabGroup.checked;
  } else {
    enable = true;
  }
  if (enable) {
{'fraction_non_alphanumeric': 0.1337903021071338, 'fraction_numerical': 0.0030464584920030465, 'mean_word_length': 3.8877171215880892, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '6498898', 'n_tokens_mistral': 2618, 'n_tokens_neox': 2573, 'n_words': 507}