<commit_before>define [
  "lib/utils"
], (utils) ->
  "use strict"

  WebSocketHandler =
    ###Helper mixin for adding websocket functionality to the
    target class and handling messages arrived via websocket.
    ###

    initWebSocket: ->
      # FIXME: Auto reconnects!
      @ws = new WebSocket utils.bnwWsUrl()
      # Check arrived message type and try to find appropriate callback
      # to handle it.
      @ws.onmessage = (e) =>
        message = JSON.parse e.data
        type = message.type
        # new_comment -> onNewComment
        type = "on" + type.replace /(?:^|_)(.)/g, (_m, p1) -> p1.toUpperCase()
        handler = @[type]
        handler.apply this, [message] if handler?
<commit_msg>Check for websockets aviability<commit_after>define [
  "lib/utils"
], (utils) ->
  "use strict"

  WebSocketHandler =
    ###Helper mixin for adding websocket functionality to the
    target class and handling messages arrived via websocket.
    ###

    isWsAvailable: ->
      window.location.pathname[...3] in ["/", "/u/", "/p/"]

    initWebSocket: ->
      return unless @isWsAvailable()
      # FIXME: Auto reconnects!
      @ws = new WebSocket utils.bnwWsUrl()
      # Check arrived message type and try to find appropriate callback
      # to handle it.
      @ws.onmessage = (e) =>
        message = JSON.parse e.data
        type = message.type
        # new_comment -> onNewComment
        type = "on" + type.replace /(?:^|_)(.)/g, (_m, p1) -> p1.toUpperCase()
        handler = @[type]
        handler.apply this, [message] if handler?

{'fraction_non_alphanumeric': 0.1282051282051282, 'fraction_numerical': 0.003205128205128205, 'mean_word_length': 2.4383259911894273, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, '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': '2119011', 'n_tokens_mistral': 478, 'n_tokens_neox': 470, 'n_words': 143}