<commit_before>const isURLAvailable = url => {
  const req = new Request(url, {
    method: "HEAD",
    redirect: "follow"
  });

  return fetch(req).then(resp => resp.ok).catch(() => false);
};

const getHostname = () => {
  const u = new URL(document.URL);
  return `${u.protocol}//${u.hostname}`;
};

const reportCouldNotConnect = url => {
  /* eslint-disable no-console */
  console.error(`livereloaded: could not find livereload script at ${url}`);
  console.error(`livereloaded: check that livereload server is running`);
  /* eslint-enable no-console */
};

const injectLivereload = port => {
  const host = getHostname();
  const url = `${host}:${port}/livereload.js`;

  return isURLAvailable(url).then(isAvailable => {
    if (!isAvailable) {
      reportCouldNotConnect(url);
      return false;
    }

    const script = document.createElement("script");
    script.setAttribute("src", url);
    document.head.appendChild(script);

    return true;
  });
};

browser.runtime.onMessage.addListener(msg => {
  switch (msg.command) {
    case "inject":<commit_msg>Tell about preferences if livereload inject fails<commit_after>const isURLAvailable = url => {
  const req = new Request(url, {
    method: "HEAD",
    redirect: "follow"
  });

  return fetch(req).then(resp => resp.ok).catch(() => false);
};

const getHostname = () => {
  const u = new URL(document.URL);
  return `${u.protocol}//${u.hostname}`;
};

const reportCouldNotConnect = url => {
  /* eslint-disable no-console */
  console.error("livereloaded: could not find livereload script at", url);
  console.error(
    "livereloaded: check that livereload server is running or set correct port in the addon preferences"
  );
  /* eslint-enable no-console */
};

const injectLivereload = port => {
  const host = getHostname();
  const url = `${host}:${port}/livereload.js`;

  return isURLAvailable(url).then(isAvailable => {
    if (!isAvailable) {
      reportCouldNotConnect(url);
      return false;
    }

    const script = document.createElement("script");
    script.setAttribute("src", url);
    document.head.appendChild(script);

    return true;
  });
};

browser.runtime.onMessage.addListener(msg => {
  switch (msg.command) {
    case "inject":
{'fraction_non_alphanumeric': 0.15673981191222572, 'fraction_numerical': 0.0, 'mean_word_length': 3.743099787685775, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 19, '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': '4994570', 'n_tokens_mistral': 697, 'n_tokens_neox': 693, 'n_words': 162}