IMVU-Desktop-Message-Tracker

Toolyx
by Toolyx · 2 posts
1 year ago in Javascript
Posted 1 year ago · Author
Code
// Initialize variables
let lastMessage = "";
let timeout = null;
let scriptEnabled = true;

// Create button element
const toggleScriptBtn = document.createElement("button");
toggleScriptBtn.innerHTML = "Run Script";
toggleScriptBtn.style.position = "absolute";
toggleScriptBtn.style.top = "0";
toggleScriptBtn.style.left = "0";
toggleScriptBtn.style.zIndex = "9999";



// Add click event listener to button
toggleScriptBtn.addEventListener("click", () => {
    scriptEnabled = !scriptEnabled;
    if (scriptEnabled) {
        toggleScriptBtn.innerHTML = "Disable Script";
    } else {
        toggleScriptBtn.innerHTML = "Enable Script";
    }
});

// Append button to body
document.body.appendChild(toggleScriptBtn);

if (scriptEnabled) {
    async function sendToWebhook(data) {
        // Replace this with your Discord webhook URL
        const webhookURL = "YOUR WEBHOOK URL!";
        // Send message to webhook
        const response = await fetch(webhookURL, {
            method: "POST",
            headers: { "Content-Type": "application/json" },
            body: JSON.stringify(data),
        });

        if (!response.ok) {
            throw new Error(`Failed to send data to webhook: ${response.status}`);
        }
    }
    function listen(fn) {
        fn = fn || console.log;
        let property = Object.getOwnPropertyDescriptor(MessageEvent.prototype, "data");
        const data = property.get;
        function lookAtMessage() {
            let socket = this.currentTarget instanceof WebSocket;
            if (!socket) {
                return data.call(this);
            }
            let msg = data.call(this);
            Object.defineProperty(this, "data", { value: msg });
            fn({ data: msg, socket: this.currentTarget, event: this });
            return msg;
        }
        property.get = lookAtMessage;
        Object.defineProperty(MessageEvent.prototype, "data", property);
    }
    // Listen for websocket messages
    listen(({ data }) => {
        if (scriptEnabled) {
            // Parse data
            const parse = JSON.parse(data);
            if (parse.record === "msg_g2c_send_message") {
                // Base 64 decode the msg
                let message = JSON.parse(atob(parse.message));
                if (!message.message) {
                    return;
                }
                // Check if message is different from last message
                if (lastMessage !== message.message) {
                    if (timeout) {
                        clearTimeout(timeout);
                    }
                    // check if message should be filtered (You can add the other ones in here!)
                    if (message.message.startsWith("*use") || message.message.startsWith("*imvu:isPureUser") || message.message.startsWith("*putOnOutfit") || message.message.startsWith("*msg")) {
                        return;
                    }
                    lastMessage = message.message;
                    timeout = setTimeout(() => {
                        sendToWebhook({
                            content: message.message,
                            username: message.userId,
                            avatar_url: `https://www.imvu.com/catalog/web_mugshot.php?user=${message.userId}`,
                        });
                    }, 1000);
                }
            }
        }
    });
}


(This code is meant to run in the web-page-console)






I created this script as a part of my experimentation with IMVU Desktop. Despite having some positive results, it is not yet fully optimized! I'm not a big js guy and you will find lots of bugs. Additionally, I have spent significant time and effort in the development and redesign of my GhostVu project, and I am excited to announce that a new version of the web-application, with a wide range of new features, will be released soon. :)
Posted 1 year ago
Thank you ill be checking your posts :)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Sign in

Already have an account? Sign in here

SIGN IN NOW

Create an account

Sign up for a new account in our community. It's easy!

REGISTER A NEW ACCOUNT