MPP - AdvancedChatLogger

8/6/2022, 1:13:53 AM

2022-08-07 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name        MPP - AdvancedChatLogger
// @namespace   Violentmonkey Scripts
// @match       https://mppclone.com/*
// @grant       none
// @version     1.2
// @author      Wolfy0615
// @description 8/6/2022, 1:13:53 AM
// ==/UserScript==

function init() {
    let logger = {
        messages: [],
        log: (msg, checkduplicate = false) => {
            msg = msg + "\n";
            if (this.messages.includes(msg) && checkduplicate) return;
            this.messages.push(msg);
        },
        clear: () => {
            this.messages = [];
        }
    };

    const protocol = {
        chatList: "c",
        chat: "a",
        directMessage: "dm",
        channelUpdate: "ch"
    };

    const client = MPP.client;
    
    let lastChannel = "";

    client.on(protocol.channelUpdate, (msg) => {
        if (lastChannel === msg.ch.id) return;
        logger.clear();
        console.log("Detected room change. Clearing logs...");
        lastChannel = msg.ch.id;
    });
    
    client.on(protocol.chatList, (msg) => {
        if (msg.c) {
            msg.c.forEach((cmsg) => {
                if (cmsg.m === "dm") {
                    const time = new Date(cmsg.t).toLocaleTimeString();
                    const sender = cmsg.sender;
                    const senderId = sender.id;
                    const senderName = sender.name;
                    const recipient = cmsg.recipient;
                    const recipientId = recipient.id;
                    const recipientName = recipient.name;

                    if (senderId === client.getOwnParticipant().id) {
                        logger.log(
                            `${time} ${senderId} (DM) ${senderName} to ${recipientId} ${recipientName}: ${cmsg.a}`,
                            true
                        );
                    } else {
                        logger.log(
                            `${time} ${recipientId} (DM) ${recipientName} from ${senderId} ${senderName}: ${cmsg.a}`,
                            true
                        );
                    }
                } else {
                    const time = new Date(cmsg.t).toLocaleTimeString();
                    logger.log(
                        `${time} ${cmsg.p.id} (--) ${cmsg.p.name}: ${cmsg.a}`,
                        true
                    );
                }
            });
        }
    });

    client.on(protocol.chat, (msg) => {
        const time = new Date(msg.t).toLocaleTimeString();
        logger.log(`${time} ${msg.p.id} (--) ${msg.p.name}: ${msg.a}`);
    });

    client.on(protocol.directMessage, (msg) => {
        const time = new Date(msg.t).toLocaleTimeString();
        const sender = msg.sender;
        const senderId = sender.id;
        const senderName = sender.name;
        const recipient = msg.recipient;
        const recipientId = recipient.id;
        const recipientName = recipient.name;

        if (senderId === client.getOwnParticipant().id) {
            logger.log(
                `${time} ${senderId} (DM) ${senderName} to ${recipientId} ${recipientName}: ${msg.a}`
            );
        } else {
            logger.log(
                `${time} ${recipientId} (DM) ${recipientName} from ${senderId} ${senderName}: ${msg.a}`
            );
        }
    });

    window.messages = logger.messages;

    const btn = `<div id="chat-download-btn" class="ugly-button">Download Chat</div>`;

    $("#bottom .relative").append(btn);

    $("#chat-download-btn").css({
        position: "absolute",
        left: "1020px",
        top: "32px",
    });

    $("#chat-download-btn").on("click", () => {
        let uri = URL.createObjectURL(
            new Blob(messages, { type: "text/plain" })
        );

        new MPP.Notification({
            id: "chat-download",
            class: "classic",
            title: "Chat Download",
            html: `<a href="${uri}" download="${client.channel.id}">Here</a> is your download.`,
            duration: 7000,
            target: "#piano",
        });
    });
}

const initInterval = setInterval(() => {
    if (window.MPP) {
        clearInterval(initInterval);
        init();
    }
});