{"size": 2047, "ext": "js", "max_stars_repo_path": "src/js/modules/chat-controls.js", "max_stars_repo_name": "EGNEntertainment/cytube-enhanced", "max_stars_repo_stars_event_min_datetime": "2017-02-20T17:54:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-13T12:18:11.000Z", "max_issues_repo_path": "src/js/modules-build/chat-controls.js", "max_issues_repo_name": "demordor/cytube-enhanced", "max_issues_repo_issues_event_min_datetime": "2015-11-08T16:40:13.000Z", "max_issues_repo_issues_event_max_datetime": "2016-02-18T23:48:10.000Z", "max_forks_repo_path": "src/js/modules-build/chat-controls.js", "max_forks_repo_name": "demordor/cytube-enhanced", "max_forks_repo_forks_event_min_datetime": "2015-09-14T17:09:13.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-30T07:38:32.000Z"}
{"max_stars_count": 2, "max_issues_count": 2, "max_forks_count": 13, "avg_line_length": 26.5844155844, "max_line_length": 103, "alphanum_fraction": 0.5334636053}
window.cytubeEnhanced.addModule('chatControls', function (app, settings) {
    'use strict';
    var that = this;

    var defaultSettings = {
        afkButton: true,
        clearChatButton: true
    };
    settings = $.extend({}, defaultSettings, settings);



    this.handleAfkBtn = function () {
        window.socket.emit('chatMsg', {msg: '/afk'});
    };
    this.$afkBtn = $('<span id="afk-btn" class="label label-default pull-right pointer">')
        .text(app.t('AFK'))
        .appendTo('#chatheader')
        .on('click', function () {
            that.handleAfkBtn();
        });



    this.handleAfk = function (data) {
        if (data.name === window.CLIENT.name) {
            if (data.afk) {
                that.$afkBtn.removeClass('label-default');
                that.$afkBtn.addClass('label-success');
            } else {
                that.$afkBtn.addClass('label-default');
                that.$afkBtn.removeClass('label-success');
            }
        }
    };

    if (settings.afkButton) {
        window.socket.on('setAFK', function (data) {
            that.handleAfk(data);
        });
    } else {
        this.$afkBtn.hide();
    }




    this.handleClearBtn = function () {
        if (window.confirm(app.t('Are you sure, that you want to clear the chat?'))) {
            window.socket.emit("chatMsg", {msg: '/clear'});
        }
    };
    this.$clearChatBtn = $('<span id="clear-chat-btn" class="label label-default pull-right pointer">')
        .text(app.t('Clear'))
        .insertAfter(this.$afkBtn)
        .on('click', function () {
            that.handleClearBtn();
        });

    if (!window.hasPermission("chatclear")) {
        this.$clearChatBtn.hide();
    }


    this.handleChatClear = function () {
        if (window.hasPermission("chatclear") && settings.clearChatButton) {
            that.$clearChatBtn.show();
        } else {
            that.$clearChatBtn.hide();
        }
    };

    window.socket.on('setUserRank', function () {
        that.handleChatClear();
    });
});
