<commit_before>LICENSE_ID = "fdocciflgajbbcgmnfifnmoamjgiefip"
activeTab = null

window.Events = {
  sendTrigger: (eventName, eventData) ->
    chrome.tabs.sendMessage activeTab?.id, { event: eventName, data: eventData }
}

Events.$ = $ Events
chrome.runtime.onMessage.addListener (req, sender) ->
  activeTab = sender.tab
  window.Events.$.trigger(req.event, req.data) if req.event

chrome.browserAction.onClicked.addListener (tab) ->
  activeTab = tab
  chrome.tabs.executeScript null, {
    code: "chrome.runtime.sendMessage({
      event: 'toggle.app',
      data: window._BACKTICK_LOADED
    });"
  }

Events.$.on
  "toggle.app": (e, loaded) ->
    if loaded
      Events.sendTrigger "toggle.app"
    else
      chrome.tabs.insertCSS null, file: "styles/container.css"
      chrome.tabs.executeScript null, file: "vendor/requirejs/require.js"
      chrome.tabs.executeScript null, file: "scripts/app.js"

  "ready.app": ->
    CommandStore.init()

  "open.settings": ->
    chrome.tabs.create url: "options.html"

  "execute.commands": (e, command) ->
    $.ajax
      url: command.src
      success: (response) ->
        url = "javascript:#{response}"
        chrome.tabs.update activeTab.id, {url: url}, ->
          Events.sendTrigger "executed.commands", command

      error: Events.sendTrigger.bind Events, "executionError.commands", command

isLicensed = (callback) ->
  port = chrome.runtime.connect LICENSE_ID

  done = (result) ->
    port.onMessage.removeListener yep
    port.onDisconnect.removeListener nope<commit_msg>Trigger command executed event right away,<commit_after>LICENSE_ID = "fdocciflgajbbcgmnfifnmoamjgiefip"
activeTab = null

window.Events = {
  sendTrigger: (eventName, eventData) ->
    chrome.tabs.sendMessage activeTab?.id, { event: eventName, data: eventData }
}

Events.$ = $ Events
chrome.runtime.onMessage.addListener (req, sender) ->
  activeTab = sender.tab
  window.Events.$.trigger(req.event, req.data) if req.event

chrome.browserAction.onClicked.addListener (tab) ->
  activeTab = tab
  chrome.tabs.executeScript null, {
    code: "chrome.runtime.sendMessage({
      event: 'toggle.app',
      data: window._BACKTICK_LOADED
    });"
  }

Events.$.on
  "toggle.app": (e, loaded) ->
    if loaded
      Events.sendTrigger "toggle.app"
    else
      chrome.tabs.insertCSS null, file: "styles/container.css"
      chrome.tabs.executeScript null, file: "vendor/requirejs/require.js"
      chrome.tabs.executeScript null, file: "scripts/app.js"

  "ready.app": ->
    CommandStore.init()

  "open.settings": ->
    chrome.tabs.create url: "options.html"

  "execute.commands": (e, command) ->
    $.ajax
      url: command.src
      success: (response) ->
        url = "javascript:#{response}"
        chrome.tabs.update activeTab.id, {url: url}
        Events.sendTrigger "executed.commands", command

      error: Events.sendTrigger.bind Events, "executionError.commands", command

isLicensed = (callback) ->
  port = chrome.runtime.connect LICENSE_ID

  done = (result) ->
    port.onMessage.removeListener yep
    port.onDisconnect.removeListener nope
{'fraction_non_alphanumeric': 0.1335914811229429, 'fraction_numerical': 0.0, 'mean_word_length': 3.353932584269663, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 24, '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': '3072568', 'n_tokens_mistral': 1012, 'n_tokens_neox': 977, 'n_words': 198}