PPPC

Pixel Place Parallel Connections

Από την 24/04/2022. Δείτε την τελευταία έκδοση.

Αυτός ο κώδικας δεν πρέπει να εγκατασταθεί άμεσα. Είναι μια βιβλιοθήκη για άλλους κώδικες που περιλαμβάνεται μέσω της οδηγίας meta // @require https://update.greasyfork.org/scripts/443907/1043361/PPPC.js

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         PPPC
// @description  Pixel Place Parallel Connections
// @version      1.4
// @author       0vC4
// @namespace    https://greasyfork.org/users/670183
// @match        https://pixelplace.io/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=pixelplace.io
// @license      MIT
// @grant        none
// @run-at       document-start
// ==/UserScript==





const PPPC = (() => {
    if (window.PPPC) return window.PPPC;



    const PPPC = {
        get settings() {
            return JSON.parse(localStorage.settings || '""')
        },
        set settings(json) {
            localStorage.settings = JSON.stringify(json);
        },
        
        
        
        async show() {
            return JSON.stringify([
                (await cookieStore.get('authId')).value,
                (await cookieStore.get('authToken')).value,
                (await cookieStore.get('authKey')).value
            ]);
        },
        async add(username, scheme) {
            const settings = this.settings;
            settings.userlist[username] = scheme;
            this.settings = settings;
            return true;
        },
        
        
        
        async save() {
            const settings = this.settings;
            
            settings.current = {
                authId: (await cookieStore.get('authId')).value,
                authToken: (await cookieStore.get('authToken')).value,
                authKey: (await cookieStore.get('authKey')).value
            };
            
            this.settings = settings;
        },
        
        async load(scheme = null) {
            const settings = this.settings;
            
            await cookieStore.set('authId', scheme ? scheme[0] : settings.current.authId);
            await cookieStore.set('authToken', scheme ? scheme[1] : settings.current.authToken);
            await cookieStore.set('authKey', scheme ? scheme[2] : settings.current.authKey);
            delete settings.current;
            
            this.settings = settings;
        },
        
        
        
        async join(username, server) {
            const settings = this.settings;
            if (!settings.userlist[username]) return false;
            const [id, token, key] = settings.userlist[username];
            
            await cookieStore.set('authId', id);
            await cookieStore.set('authToken', token);
            await cookieStore.set('authKey', key);
            
            await fetch(`https://pixelplace.io/api/get-painting.php?id=${server}&connected=1`);
            
            settings.userlist[username] = [
                (await cookieStore.get('authId')).value,
                (await cookieStore.get('authToken')).value,
                (await cookieStore.get('authKey')).value
            ];
            this.settings = settings;
            return settings.userlist[username];
        },
        
        
        
        timer: window,
        async connect(username, boardId) {
            const [authId, authToken, authKey] = this.join(username, boardId);
            
            const user = new WebSocket('wss://pixelplace.io/socket.io/?EIO=3&transport=websocket');
            user.headless = true;
            user.onmessage = ({data}) => {
                const [code, msg] = data.split(/(?<=^\d+)(?=[^\d])/);
                if (code == '40') user.send('42' + JSON.stringify(
                    ["init", { authKey, authToken, authId, boardId }]
                ));
                
                const message = JSON.parse(msg || '[]');
                if (message.pingInterval) this.timer.setInterval(() => user.send('2'), message.pingInterval);
                
                if (!message.length) return arguments;
                const [event, json] = message;
            };
            
            return user;
        }
    };
    
    
    
    if (!PPPC.settings) PPPC.settings = {
        userlist: {}
    };



    window.PPPC = PPPC;
    return PPPC;
})();
// 0vC4#7152