<commit_before># Performs communication with the background page.
#
# @author <NAME> (@bgotink)
# @license MIT

((module) ->
    exports = module.comm = {}
    onUpdate = ->
    lastUpdate = +new Date

    exports.send = (request, callback) ->
        request =
            request: request
            lastUpdate: lastUpdate
        lastUpdate = +new Date

        try
            module.extension.sendMessage request, (reply) ->
                    if not reply?
                        module.log.error module.extension.getLastError() if module.extension.getLastError
                        return

                    callback reply.reply if callback?

                    lastUpdate = +new Date
                    if reply.shouldUpdate
                        if onUpdate
                            onUpdate()
        catch e
            # couldn't contact the extension
            # that can only mean one thing: extension has been reloaded, disabled or removed
            # -> reload this page
            window.document.location.reload()

    module.extension.addMessageListener (request) ->
        if request.type is 'update'
            lastUpdate = +new Date

            onUpdate() if onUpdate?

        # ignore: the options page gets all the messages meant for the background
        # page as well... logging/throwing here would fill the console with junk
        false

    exports.hasPlayer = (oid, callback) ->
        @send { type: 'hasPlayer', oid: oid }, (result) ->
            callback result.result<commit_msg>[frontend] better logging when empty response is received<commit_after># Performs communication with the background page.
#
# @author <NAME> (@bgotink)
# @license MIT

((module) ->
    exports = module.comm = {}
    onUpdate = ->
    lastUpdate = +new Date

    exports.send = (request, callback) ->
        request =
            request: request
            lastUpdate: lastUpdate
        lastUpdate = +new Date

        try
            module.extension.sendMessage request, (reply) ->
                    if not reply?
                        module.log.error 'Got empty response to', request
                        module.log.error module.extension.getLastError() if module.extension.getLastError?()?
                        return

                    callback reply.reply if callback?

                    lastUpdate = +new Date
                    if reply.shouldUpdate
                        if onUpdate
                            onUpdate()
        catch e
            # couldn't contact the extension
            # that can only mean one thing: extension has been reloaded, disabled or removed
            # -> reload this page
            window.document.location.reload()

    module.extension.addMessageListener (request) ->
        if request.type is 'update'
            lastUpdate = +new Date

            onUpdate() if onUpdate?

        # ignore: the options page gets all the messages meant for the background
        # page as well... logging/throwing here would fill the console with junk
        false

    exports.hasPlayer = (oid, callback) ->
        @send { type: 'hasPlayer', oid: oid }, (result) ->
            callback result.result
{'fraction_non_alphanumeric': 0.07833957553058676, 'fraction_numerical': 0.0, 'mean_word_length': 1.6270491803278688, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '102839', 'n_tokens_mistral': 764, 'n_tokens_neox': 726, 'n_words': 260}