<commit_before>'use strict';

function init() {
  // Initialise la listHON
  hon_listHON.init();
}
init();

function debounce(func, wait, immediate) {
  var timeout;
  return function() {
    var context = this;
    var args = arguments;
    var later = function() {
      timeout = null;
      if (!immediate) {
        func.apply(context, args);
      }
    };
    var callNow = immediate && !timeout;
    clearTimeout(timeout);
    timeout = setTimeout(later, wait);
    if (callNow) {
      func.apply(context, args);
    }
  };
}

function checkHonCode(url) {
  hon_listHON.checkURL(hon_listHON.formatHREF(url)).then(function(code) {
    if (code) {
      chrome.browserAction.setIcon({path: 'images/icon-48.png'});
    } else {
      chrome.browserAction.setIcon({path: 'images/icon-invalid-48.png'});
    }
  });
}

chrome.omnibox.onInputEntered.addListener(function(text) {
  var url = 'https://www.hon.ch/HONcode/Search/search.html';
  if (text) {
    url += '?siteurl=&cref=http%3A%2F%2Fwww.hon.ch' +
    '%2FCSE%2FHONCODE%2Fcontextlink.xml&sa=Search&hl=en&cof=FORID%3A11&q=' +
    encodeURIComponent(text);
  }
  chrome.tabs.getSelected(null, function(tab) {
    chrome.tabs.update(tab.id, {url: url});
  });
});

chrome.tabs.onActivated.addListener(function(activeInfo) {
  chrome.tabs.get(activeInfo.tabId, function(tab) {
    checkHonCode(tab.url);
  });
});

chrome.tabs.onUpdated.addListener(function() {
  chrome.tabs.query({active: true}, function(tabs) {
    checkHonCode(tabs[0].url);
  });
});

chrome.browserAction.onClicked.addListener(function(tab) {
  hon_listHON.checkURL(hon_listHON.formatHREF(tab.url)).then(function(code) {
    if (code) {
      var action_url = 'https://www.hon.ch/HONcode/Conduct.html?' +
        code;
      chrome.tabs.create({ url: action_url });
    }
  });
});

chrome.webRequest.onCompleted.addListener(debounce(function(details) {
    chrome.tabs.executeScript(
      details.tabId, {
        file: 'bower_components/jquery/dist/jquery.min.js',
        allFrames: true,
      }
    );<commit_msg>select active tab in active window & add event listener onFocusChanged<commit_after>'use strict';

function init() {
  // Initialise la listHON
  hon_listHON.init();
}
init();

function debounce(func, wait, immediate) {
  var timeout;
  return function() {
    var context = this;
    var args = arguments;
    var later = function() {
      timeout = null;
      if (!immediate) {
        func.apply(context, args);
      }
    };
    var callNow = immediate && !timeout;
    clearTimeout(timeout);
    timeout = setTimeout(later, wait);
    if (callNow) {
      func.apply(context, args);
    }
  };
}

function checkHonCode(url) {
  hon_listHON.checkURL(hon_listHON.formatHREF(url)).then(function(code) {
    if (code) {
      chrome.browserAction.setIcon({path: 'images/icon-48.png'});
    } else {
      chrome.browserAction.setIcon({path: 'images/icon-invalid-48.png'});
    }
  });
}

chrome.omnibox.onInputEntered.addListener(function(text) {
  var url = 'https://www.hon.ch/HONcode/Search/search.html';
  if (text) {
    url += '?siteurl=&cref=http%3A%2F%2Fwww.hon.ch' +
    '%2FCSE%2FHONCODE%2Fcontextlink.xml&sa=Search&hl=en&cof=FORID%3A11&q=' +
    encodeURIComponent(text);
  }
  chrome.tabs.getSelected(null, function(tab) {
    chrome.tabs.update(tab.id, {url: url});
  });
});

chrome.tabs.onActivated.addListener(function(activeInfo) {
  chrome.tabs.get(activeInfo.tabId, function(tab) {
    checkHonCode(tab.url);
  });
});

chrome.tabs.onUpdated.addListener(function() {
  chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
    checkHonCode(tabs[0].url);
  });
});

chrome.windows.onFocusChanged.addListener(function() {
  chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
    checkHonCode(tabs[0].url);
  });
});

chrome.browserAction.onClicked.addListener(function(tab) {
  hon_listHON.checkURL(hon_listHON.formatHREF(tab.url)).then(function(code) {
    if (code) {
      var action_url = 'https://www.hon.ch/HONcode/Conduct.html?' +
        code;
      chrome.tabs.create({ url: action_url });
    }
  });
});

chrome.webRequest.onCompleted.addListener(debounce(function(details) {
    chrome.tabs.executeScript(
      details.tabId, {
        file: 'bower_components/jquery/dist/jquery.min.js',
        allFrames: true,
      }
    );
{'fraction_non_alphanumeric': 0.16364054240404505, 'fraction_numerical': 0.00666513445185015, 'mean_word_length': 3.576235541535226, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 6, 'xml': 2}, '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': '630187', 'n_tokens_mistral': 1573, 'n_tokens_neox': 1542, 'n_words': 210}