<commit_before>import { getLocalSettings } from '../utils/settings';
import { GET } from '../utils/http';
// import $ from 'jquery';
/* eslint-disable new-cap */

function addStyle(css, storeId) {
  try {
    const styleTag = document.createElement('style');
    styleTag.type = 'text/css';
    styleTag.id = storeId;
    styleTag.appendChild(document.createTextNode(css.replace(/@-moz-document.*{/g, '@media all {')));
    document.getElementsByTagName('head')[0].appendChild(styleTag);
  } catch (e) {
    console.error(e);
  }
}

function checkAddStyle(userStyleUrl) {
  try {
    if (userStyleUrl === '') return;
    const userStyleId = userStyleUrl.match(/\/styles\/(\d+)\//)[1];
    const storeId = `voz_living_userstyle_${userStyleId}`;
    const oldCss = window.localStorage.getItem(storeId);
    if (oldCss !== null) {
      addStyle(oldCss, storeId);
      return;
    }
    GET(`https://userstyles.org/styles/${userStyleId}.css`, {
      credentials: 'same-origin',
    })
      .then((css) => {
        if (oldCss === null) {
          addStyle(css, storeId);
          window.localStorage.setItem(storeId, css);
        }
      });
  } catch (e) {
    console.error(e);
  }
}

export function UserStyle() {
  let isAdded = false;
  let uStyle = localStorage.getItem('userStyle');
  if (uStyle !== '') {
    uStyle = uStyle.split(',');
    setTimeout(() => {
      for (const eachStyle of uStyle) {
        checkAddStyle(eachStyle);
      }
    }, 50);
    isAdded = true;
  }
  getLocalSettings()
    .then((settings) => {
      let { userStyle } = settings;
      if (userStyle !== '' && !isAdded) {
        userStyle = userStyle.split(',');
        for (const eachStyle of userStyle) {
          checkAddStyle(eachStyle);
        }
      }
      localStorage.setItem('userStyle', userStyle);
    });
}<commit_msg>[hot-fix] prevent undefined || null split<commit_after>import { getLocalSettings } from '../utils/settings';
import { GET } from '../utils/http';
// import $ from 'jquery';
/* eslint-disable new-cap */

function addStyle(css, storeId) {
  try {
    const styleTag = document.createElement('style');
    styleTag.type = 'text/css';
    styleTag.id = storeId;
    styleTag.appendChild(document.createTextNode(css.replace(/@-moz-document.*{/g, '@media all {')));
    document.getElementsByTagName('head')[0].appendChild(styleTag);
  } catch (e) {
    console.error(e);
  }
}

function checkAddStyle(userStyleUrl) {
  try {
    if (userStyleUrl === '') return;
    const userStyleId = userStyleUrl.match(/\/styles\/(\d+)\//)[1];
    const storeId = `voz_living_userstyle_${userStyleId}`;
    const oldCss = window.localStorage.getItem(storeId);
    if (oldCss !== null) {
      addStyle(oldCss, storeId);
      return;
    }
    GET(`https://userstyles.org/styles/${userStyleId}.css`, {
      credentials: 'same-origin',
    })
      .then((css) => {
        if (oldCss === null) {
          addStyle(css, storeId);
          window.localStorage.setItem(storeId, css);
        }
      });
  } catch (e) {
    console.error(e);
  }
}

export function UserStyle() {
  let isAdded = false;
  let uStyle = localStorage.getItem('userStyle');
  if (uStyle && uStyle !== '') {
    uStyle = uStyle.split(',');
    setTimeout(() => {
      for (const eachStyle of uStyle) {
        checkAddStyle(eachStyle);
      }
    }, 50);
    isAdded = true;
  }
  getLocalSettings()
    .then((settings) => {
      let { userStyle } = settings;
      if (userStyle && userStyle !== '' && !isAdded) {
        userStyle = userStyle.split(',');
        for (const eachStyle of userStyle) {
          checkAddStyle(eachStyle);
        }
      }
      localStorage.setItem('userStyle', userStyle);
    });
}
{'fraction_non_alphanumeric': 0.1707580253574319, 'fraction_numerical': 0.002158079309414621, 'mean_word_length': 2.779816513761468, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 2, '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': '7457359', 'n_tokens_mistral': 1200, 'n_tokens_neox': 1205, 'n_words': 220}