<commit_before>import ContextMenu from './contextmenu';
import BrowserAction from './browseraction';

import { copyToClipboard } from './utils';
import { saveOption, saveAccordionState } from './options';

/**
 * Initialize listeners for the background page
 */
const init = () => {
  chrome.extension.onRequest.addListener(function(
    request,
    sender,
    sendResponse
  ) {
    let response;
    switch (request.name) {
      case 'activateBrowserAction':
        BrowserAction.activate(sender.tab);
        break;

      case 'unhighlightBrowserAction':
        BrowserAction.unhighlight(sender.tab);
        break;

      case 'highlightBrowserAction':
        BrowserAction.highlight(sender.tab);
        break;

      case 'copyToClipboard':
        copyToClipboard(request.text);
        break;

      case 'save':
        window.cache.styles.save(request.url, request.rules, request.data);
        break;

      case 'doesStyleExist':
        sendResponse(window.cache.styles.exists(request.url));
        break;

      case 'transfer':
        window.cache.styles.transfer(request.source, request.destination);
        break;

      case 'getGlobalRules':
        sendResponse(window.cache.styles.getGlobalRules());
        break;

      case 'getStyleUrlMetadataForTab':
        {
          const styleUrlMetadata = window.cache.styles.getStyleUrlMetadataForTab(
            request.tab
          );

          if (styleUrlMetadata) {
            response = { styleUrlMetadata, success: true };
          } else {
            response = { success: false };
          }
        }

        sendResponse(response);
        break;

      case 'getComputedStylesForTab':
        if (window.cache.styles.getComputedStylesForTab) {
          response = window.cache.styles.getComputedStylesForTab(sender.tab);
          response.success = true;
        } else {
          response = {
            success: false,
          };
        }

        sendResponse(response);
        break;

      case 'getComputedStylesForIframe':
        if (window.cache.styles.getComputedStylesForIframe) {
          response = window.cache.styles.getComputedStylesForIframe(
            request.url,
            sender.tab
          );

          response.success = true;
        } else {
          response = {
            success: false,
          };
        }

        sendResponse(response);
        break;

      case 'enableStyleUrl':
        {
          window.cache.styles.toggle(request.styleUrl, true, true);
          window.cache.styles.enableStylesForTab(request.styleUrl, request.tab);

          // BrowserAction.highlight(request.tab);
        }

        break;

      case 'disableStyleUrl':
        {
          window.cache.styles.toggle(request.styleUrl, false, true);
          window.cache.styles.disableStylesForTab(
            request.styleUrl,
            request.tab
          );

          // BrowserAction.unhighlight(request.tab);
        }

        break;

      case 'fetchOptions':
        sendResponse({
          options: window.cache.options,
        });
        break;

      case 'showOptions':
        chrome.tabs.create({
          url: 'options/index.html',
          active: true,
        });

        break;

      case 'saveAccordionState':
        saveAccordionState(request.accordions);
        break;

      case 'saveOption':
        saveOption(request.option.name, request.option.value);<commit_msg>update browser action on enable/disable of styles<commit_after>import ContextMenu from './contextmenu';
import BrowserAction from './browseraction';

import { copyToClipboard } from './utils';
import { saveOption, saveAccordionState } from './options';

/**
 * Initialize listeners for the background page
 */
const init = () => {
  chrome.extension.onRequest.addListener(function(
    request,
    sender,
    sendResponse
  ) {
    let response;
    switch (request.name) {
      case 'activateBrowserAction':
        BrowserAction.activate(sender.tab);
        break;

      case 'unhighlightBrowserAction':
        BrowserAction.unhighlight(sender.tab);
        break;

      case 'highlightBrowserAction':
        BrowserAction.highlight(sender.tab);
        break;

      case 'copyToClipboard':
        copyToClipboard(request.text);
        break;

      case 'save':
        window.cache.styles.save(request.url, request.rules, request.data);
        break;

      case 'doesStyleExist':
        sendResponse(window.cache.styles.exists(request.url));
        break;

      case 'transfer':
        window.cache.styles.transfer(request.source, request.destination);
        break;

      case 'getGlobalRules':
        sendResponse(window.cache.styles.getGlobalRules());
        break;

      case 'getStyleUrlMetadataForTab':
        {
          const styleUrlMetadata = window.cache.styles.getStyleUrlMetadataForTab(
            request.tab
          );

          if (styleUrlMetadata) {
            response = { styleUrlMetadata, success: true };
          } else {
            response = { success: false };
          }
        }

        sendResponse(response);
        break;

      case 'getComputedStylesForTab':
        if (window.cache.styles.getComputedStylesForTab) {
          response = window.cache.styles.getComputedStylesForTab(sender.tab);
          response.success = true;
        } else {
          response = {
            success: false,
          };
        }

        sendResponse(response);
        break;

      case 'getComputedStylesForIframe':
        if (window.cache.styles.getComputedStylesForIframe) {
          response = window.cache.styles.getComputedStylesForIframe(
            request.url,
            sender.tab
          );

          response.success = true;
        } else {
          response = {
            success: false,
          };
        }

        sendResponse(response);
        break;

      case 'enableStyleUrl':
        {
          window.cache.styles.toggle(request.styleUrl, true, true);
          window.cache.styles.enableStylesForTab(request.styleUrl, request.tab);

          const styleUrlMetadata = window.cache.styles.getStyleUrlMetadataForTab(
            request.tab
          );

          if (styleUrlMetadata) {
            const enabledStyleUrls = styleUrlMetadata.filter(
              item => item.enabled
            );

            if (enabledStyleUrls.length > 0) {
              BrowserAction.highlight(request.tab);
            }
          }
        }

        break;

      case 'disableStyleUrl':
        {
          window.cache.styles.toggle(request.styleUrl, false, true);
          window.cache.styles.disableStylesForTab(
            request.styleUrl,
            request.tab
          );

          const styleUrlMetadata = window.cache.styles.getStyleUrlMetadataForTab(
            request.tab
          );

          if (styleUrlMetadata) {
            const enabledStyleUrls = styleUrlMetadata.filter(
              item => item.enabled
            );

            if (enabledStyleUrls.length === 0) {
              BrowserAction.unhighlight(request.tab);
            }
          }
        }

        break;

      case 'fetchOptions':
        sendResponse({
          options: window.cache.options,
        });
        break;

      case 'showOptions':
        chrome.tabs.create({
          url: 'options/index.html',
          active: true,
        });

        break;

      case 'saveAccordionState':
        saveAccordionState(request.accordions);
        break;

      case 'saveOption':
        saveOption(request.option.name, request.option.value);
{'fraction_non_alphanumeric': 0.10071090047393365, 'fraction_numerical': 0.0002632964718272775, 'mean_word_length': 1.8667924528301887, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '4863782', 'n_tokens_mistral': 2033, 'n_tokens_neox': 1960, 'n_words': 347}