ggu_userData

userdata do ggutils

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greatest.deepsurf.us/scripts/487863/1359256/ggu_userData.js

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

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

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

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

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

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

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

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

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

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

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

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

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

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

const config = {
    "endpoint_user": "https://ggmax.com.br/api/user",
    "endpoint_auth": "https://ggmax.com.br/api/auth",
    "endpoint_orders": "https://ggmax.com.br/api/orders",
    "endpoint_announcements": "https://ggmax.com.br/api/announcements",
}
async function refreshToken(ref_token) {
    ref_token = ref_token.replace('Bearer ', '');
    let body = JSON.stringify({
        refresh_token: ref_token
    });
    var req = await fetch(`${config.endpoint_auth}/refresh-token`, {
        "headers": {
            "content-type": "application/json",
        },
        "body": body,
        "method": "POST",
        "mode": "cors",
        "credentials": "include"
    });

    let json = await req.json();
    return json;
}

class user {
    constructor() {
        this.data = () => {
            let cookies = document.cookie.split('; ');
            let authData = cookies.find(cookie => cookie.startsWith('auth='));
            authData = JSON.parse(decodeURIComponent(authData.split('=')[1]));
            return {
                token: authData.accessToken,
                refreshToken: authData.refreshToken
            }
        }
    }
    cookies() {
        return {
            get: (cname) => {
                let name = cname + "=";
                let decodedCookie = decodeURIComponent(document.cookie);
                let ca = decodedCookie.split(';');
                for (let i = 0; i < ca.length; i++) {
                    let c = ca[i];
                    while (c.charAt(0) == ' ') {
                        c = c.substring(1);
                    }
                    if (c.indexOf(name) == 0) {
                        return c.substring(name.length, c.length);
                    }
                }
                return "";
            },
            set: (cname, cvalue) => {
                document.cookie = `${encodeURIComponent(cname)}=${encodeURIComponent(cvalue)}`;
            }
        }
    }

    async refresh() {
        let data = this.data();
        const json = await refreshToken(data.refreshToken);

        if (json.success) {
            this.cookies().set('auth._refresh_token.local', json.data.token);
        }
    }

    async data() {
        let data = this.data();
        return data;
    }


}