IdlePixel Chat Functions

Added functionality to chat. Currently only contains a mute function. Add users via the plugin menu.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         IdlePixel Chat Functions
// @namespace    com.evolsoulx.idlepixel
// @version      1.1.0
// @description  Added functionality to chat. Currently only contains a mute function. Add users via the plugin menu.
// @author       evolsoulx
// @license      MIT
// @match        *://idle-pixel.com/login/play*
// @grant        none
// @require      https://greasyfork.org/scripts/441206-idlepixel/code/IdlePixel+.js
// ==/UserScript==

(function() {
    'use strict';
    var styles = '.mutedMessage:hover{color:#FFF !important;}'

    var styleSheet = document.createElement("style");
    styleSheet.innerText = styles;
    styleSheet.id = 'chatFunctions';
    document.head.appendChild(styleSheet);

    function rebuildChatMessage(message, updateMessage) {
        var username = message.username;
        var sigil = message.sigil;
        var level = message.level;
        var chatmessage = message.message;
        if(updateMessage) {
            chatmessage = updateMessage;
        }
        return '<span style="color:red; font-weight:bold;">[MUTED] </span> <img src="https://d1xsc8x7nc5q8t.cloudfront.net/images/' + sigil + '.png"> <span class=""></span> <a target="_blank" class="chat-username" href="https://idle-pixel.com/hiscores/search?username=' + username + '">' + username + '</a><span class="color-grey"> (' + level + '): </span>' + chatmessage;
    }

    class CMTPlugin extends IdlePixelPlusPlugin {
        constructor() {
            super("chatfunctions", {
                about: {
                    name: GM_info.script.name,
                    version: GM_info.script.version,
                    author: GM_info.script.author,
                    description: GM_info.script.description
                },
                config: [{
                        type: "label",
                        label: "User Functions:"
                    },
                    {
                        id: "muteThese",
                        label: "List who you want to mute and be able to hover to see their messages",
                        type: "string",
                        max: 2000,
                        default: ""
                    },
                    {
                        id: "blockThese",
                        label: "List who you want to block and not see completely",
                        type: "string",
                        max: 2000,
                        default: ""
                    },
                    {
                        id: "blockConsoleDisplay",
                        label: "Display console message when blocked message is receieved",
                        type: "boolean",
                        default: true
                    }
                ]
            });
        }


        muteMessage(message) {
            var newMessage = "<span class='mutedMessage' style='color:black; background-color:black;'>" + message.message + "</span>";
            return rebuildChatMessage(message, newMessage);
        }

        onLogin() {}

        onConfigsChanged() {}

        onChat(data) {
            //            console.log(data);
            const el = $("#chat-area > *").last();
            const listOfMutes = this.getConfig("muteThese").split(',');
            const listOfBlocks = this.getConfig("blockThese").split(',');
            const displayBlockMessage = this.getConfig("blockConsoleDisplay");
            var chatFrom = data.username;
            if(listOfMutes.indexOf(chatFrom) != -1) {
                el.html(this.muteMessage(data));
            }
            if(listOfBlocks.indexOf(chatFrom) != -1) {
                el.remove();
                if(displayBlockMessage){console.log("Muted a message from " + chatFrom);}
            }


        }

    }

    const plugin = new CMTPlugin();
    IdlePixelPlus.registerPlugin(plugin);

})();