Dismiss Notice
Hey Guest,
If you are interested in ghosting, the Ghosting Awards for January 2025 has just been announced:

Click here to check it out!

Quick login

Discussion in 'Third Party Scripting & Development' started by Calculus, Mar 27, 2022.

  1. Calculus

    Calculus Community Developer Staff Member Administrator Ghost Moderator

    Awarded Medals
    Hey y'all,

    Due to the abnormally high amount of accounts created per user, I thought it would be a good idea to make this. I wrote a script allowing me to log in/out of accounts without having to reenter the password each time. I didn't plan on releasing this, but it might be useful to some people.
    Preview (open)
    upload_2022-3-27_1-15-41.png
    Script (open)
    Code:
    // ==UserScript==
    // @name         Switch Accounts
    // @version      0.15
    // @author       Calculamatrise
    // @match        *://frhd.kanoapps.com/*
    // @match        *://www.freeriderhd.com/*
    // @grant        none
    // ==/UserScript==
    
    Application.events.subscribe('mainview.loaded', load);
    window.addEventListener('load', load);
    
    function load() {
        let logout = document.querySelector('a.logout');
        logout.removeAttribute('id');
        logout.innerText = 'Switch';
        logout.addEventListener('click', function() {
            let overlay = createElement('div', {
                className: 'simplemodal-overlay',
                id: 'simplemodal-overlay',
                style: {
                    inset: 0,
                    opacity: 0.5,
                    position: 'fixed',
                    zIndex: 1001
                }
            });
    
            let container = createElement('div', {
                children: [
                    createElement('span', {
                        className: 'core_icons core_icons-icon_close signup-login-modal-close',
                        onclick() {
                            overlay.remove();
                            container.remove();
                        }
                    }),
                    createElement('div', {
                        children: (JSON.parse(localStorage.getItem('switcher-accounts')) ?? []).map(createUserElement),
                        id: 'accounts-container',
                        style: {
                            display: 'flex',
                            flexDirection: 'column',
                            gap: '0.4rem'
                        }
                    }),
                    createElement('button', {
                        className: 'btn new-button button-type-2',
                        innerText: 'Add account',
                        onclick() {
                            if (container.querySelector('div#login-container')) {
                                this.innerText = 'Add account';
                                this.classList.remove('moderator-remove-race');
                                container.querySelector('div#login-container').remove();
                                return;
                            }
    
                            this.before(createElement('div', {
                                children: [
                                    createElement('input', {
                                        className: 'field auth-field',
                                        id: 'save-account-login',
                                        placeholder: 'Username or Email',
                                        style: {
                                            borderRadius: '2rem'
                                        },
                                        type: 'text'
                                    }),
                                    createElement('input', {
                                        className: 'field auth-field',
                                        id: 'save-account-password',
                                        placeholder: 'Password',
                                        style: {
                                            borderRadius: '2rem'
                                        },
                                        type: 'password'
                                    }),
                                    createElement('button', {
                                        className: 'new-button button-type-1',
                                        innerText: 'Save account',
                                        onclick() {
                                            Application.Helpers.AjaxHelper.post('/auth/standard_login', {
                                                login: document.querySelector('#save-account-login')?.value,
                                                password: document.querySelector('#save-account-password')?.value
                                            }).done(response => {
                                                if (response.result) {
                                                    let accounts = JSON.parse(localStorage.getItem('switcher-accounts')) || [];
                                                    if (accounts.find(({ login }) => login === response.data.user.d_name)) {
                                                        return;
                                                    }
    
                                                    accounts.push({
                                                        login: response.data.user.d_name,
                                                        password: document.querySelector('#save-account-password')?.value
                                                    });
    
                                                    container.querySelector('#accounts-container')?.append(createUserElement(accounts.at(-1)));
                                                    localStorage.setItem('switcher-accounts', JSON.stringify(accounts));
                                                    this.parentElement.remove();
                                                }
                                            });
                                        }
                                    })
                                ],
                                id: 'login-container',
                                style: {
                                    display: 'flex',
                                    flexDirection: 'column',
                                    gap: '0.4rem',
                                    marginTop: '1rem'
                                }
                            }));
                            this.classList.add('moderator-remove-race');
                            this.innerText = 'Cancel';
                        }
                    })
                ],
                className: 'simplemodal-container',
                id: 'signup_login_container',
                style: {
                    display: 'flex',
                    flexDirection: 'column',
                    gap: '0.6rem',
                    height: 'fit-content',
                    inset: 0,
                    margin: 'auto',
                    maxHeight: '50vmin',
                    overflow: 'hidden auto',
                    padding: '50px',
                    position: 'fixed',
                    width: '360px',
                    zIndex: 1002
                }
            });
    
            document.body.append(overlay, container);
        });
    }
    
    function createElement(type, options) {
        const callback = arguments[arguments.length - 1];
        const element = document.createElement(type);
        if ('innerText' in options) {
            element.innerText = options.innerText;
            delete options.innerText;
        }
    
        for (const attribute in options) {
            if (typeof options[attribute] == 'object') {
                if (options[attribute] instanceof Array) {
                    if (/^children$/i.test(attribute)) {
                        element.append(...options[attribute]);
                    } else if (/^on/i.test(attribute)) {
                        for (const listener of options[attribute]) {
                            element.addEventListener(attribute.slice(2), listener);
                        }
                    }
                } else if (/^style$/i.test(attribute)) {
                    Object.assign(element[attribute.toLowerCase()], options[attribute]);
                }
    
                delete options[attribute];
            }
        }
    
        Object.assign(element, options);
        return typeof callback == 'function' && callback(element), element;
    }
    
    function createUserElement({ login, password }) {
        let container = createElement('div', {
            children: [
                createElement('button', {
                    className: 'new-button button-type-1',
                    innerText: login,
                    style: {
                        width: '-webkit-fill-available'
                    },
                    onclick() {
                        document.querySelector('#simplemodal-overlay')?.remove();
                        document.querySelector('#signup_login_container')?.remove();
                        Application.Helpers.AjaxHelper.post('/auth/standard_login', { login, password }).done(function(response) {
                            response.result && Application.events.publish('auth.login', response.data.user, response.data.user_stats);
                        });
                    }
                }),
                createElement('button', {
                    className: 'btn new-button button-type-1 moderator-remove-race',
                    innerText: 'X',
                    style: {
                        aspectRatio: 1,
                        backgroundImage: 'linear-gradient(#ee5f5b,#c43c35)',
                        marginRight: 0
                    },
                    onclick() {
                        let accounts = JSON.parse(localStorage.getItem('switcher-accounts')) ?? [];
                        accounts.splice(accounts.indexOf(accounts.find((account) => account.login === login)), 1);
                        localStorage.setItem('switcher-accounts', JSON.stringify(accounts));
                        container.remove();
                    }
                })
            ],
            style: {
                display: 'flex',
                gap: '0.25rem'
            }
        });
    
        return container;
    }
    

    Previous versions:

    P.S. Creating (an) alternative account(s) is against the rules
     
    Last edited: May 6, 2023
  2. Innominate

    Innominate Well-Known Member Official Author

    Personally this would be of use to me, and I think it’s a really cool idea. People like you shape the game more than the Kano turds ever will. Thanks for another wonderful addition to the community.
     
    Blank_Guy, Calculus and Egway like this.
  3. Zycerak

    Zycerak Lone Wolf Elite Author Team Truck Rotten Flesh Official Author

    Awarded Medals
    having multiple accounts is against the rules. anyone who uses multiple accounts should be torn apart limb by limb
     
    Vince0, Azgr00, RadiumRC and 7 others like this.
  4. Fluoride

    Fluoride Well-Known Member Official Author

    Why do I feel personally attacked
     
  5. robbieraysfan

    robbieraysfan Well-Known Member Official Author

    hello calculus. i thinkthat this is a great idea and that you should release this script. good job busddy.
     
    Blank_Guy, pawflix and Fluoride like this.
  6. Calculus

    Calculus Community Developer Staff Member Administrator Ghost Moderator

    Awarded Medals
    I really lost myself with this script. I'll only update it when necessary.

    **Moved the script to the main post.
     
    Last edited: Mar 28, 2022
  7. Trainer.John

    Trainer.John Well-Known Member

    what are these x buttons doing in the ghosts btw?
     
  8. Calculus

    Calculus Community Developer Staff Member Administrator Ghost Moderator

    Awarded Medals
    I just needed them as a reference to make the "remove account" button.
     
    Trainer.John likes this.
  9. MrFishyFriend

    MrFishyFriend Well-Known Member Official Author

    Can I post it on GitHub for people who like that better?
     
  10. Innominate

    Innominate Well-Known Member Official Author

    Its calculus' to post, not yours.
     
  11. Calculus

    Calculus Community Developer Staff Member Administrator Ghost Moderator

    Awarded Medals
    You are free to do whatever you like with the script. I actually like GitHub better as well. I forgot about gists.
    https://gist.github.com/Calculamatrise/02a179e4d1980a8f852f40887af323c5

    It's a public script. They're welcome to post it wherever they like. They can modify it to their liking if they please. It's entirely up to them.
     
    Last edited: Mar 28, 2022
    pawflix likes this.
  12. RandomTurtleBoi

    RandomTurtleBoi Well-Known Member Official Author

    isnt stultus one of your alts or something
     
    pawflix likes this.
  13. Calculus

    Calculus Community Developer Staff Member Administrator Ghost Moderator

    Awarded Medals
    Updated the script in the main post. The previous version wouldn't adjust to screen size very well. This version should be slightly improved.
    Code:
    // ==UserScript==
    // @name         Switch Accounts
    // @version      0.15
    // @author       Calculamatrise
    // @match        *://frhd.kanoapps.com/*
    // @match        *://www.freeriderhd.com/*
    // @grant        none
    // ==/UserScript==
    
    Application.events.subscribe('mainview.loaded', load);
    window.addEventListener('load', load);
    
    function load() {
        let logout = document.querySelector('a.logout');
        logout.removeAttribute('id');
        logout.innerText = 'Switch';
        logout.addEventListener('click', function() {
            let overlay = createElement('div', {
                className: 'simplemodal-overlay',
                id: 'simplemodal-overlay',
                style: {
                    inset: 0,
                    opacity: 0.5,
                    position: 'fixed',
                    zIndex: 1001
                }
            });
    
            let container = createElement('div', {
                children: [
                    createElement('span', {
                        className: 'core_icons core_icons-icon_close signup-login-modal-close',
                        onclick() {
                            overlay.remove();
                            container.remove();
                        }
                    }),
                    createElement('div', {
                        children: (JSON.parse(localStorage.getItem('switcher-accounts')) ?? []).map(createUserElement),
                        id: 'accounts-container',
                        style: {
                            display: 'flex',
                            flexDirection: 'column',
                            gap: '0.4rem'
                        }
                    }),
                    createElement('button', {
                        className: 'btn new-button button-type-2',
                        innerText: 'Add account',
                        onclick() {
                            if (container.querySelector('div#login-container')) {
                                this.innerText = 'Add account';
                                this.classList.remove('moderator-remove-race');
                                container.querySelector('div#login-container').remove();
                                return;
                            }
    
                            this.before(createElement('div', {
                                children: [
                                    createElement('input', {
                                        className: 'field auth-field',
                                        id: 'save-account-login',
                                        placeholder: 'Username or Email',
                                        style: {
                                            borderRadius: '2rem'
                                        },
                                        type: 'text'
                                    }),
                                    createElement('input', {
                                        className: 'field auth-field',
                                        id: 'save-account-password',
                                        placeholder: 'Password',
                                        style: {
                                            borderRadius: '2rem'
                                        },
                                        type: 'password'
                                    }),
                                    createElement('button', {
                                        className: 'new-button button-type-1',
                                        innerText: 'Save account',
                                        onclick() {
                                            Application.Helpers.AjaxHelper.post('/auth/standard_login', {
                                                login: document.querySelector('#save-account-login')?.value,
                                                password: document.querySelector('#save-account-password')?.value
                                            }).done(response => {
                                                if (response.result) {
                                                    let accounts = JSON.parse(localStorage.getItem('switcher-accounts')) || [];
                                                    if (accounts.find(({ login }) => login === response.data.user.d_name)) {
                                                        return;
                                                    }
    
                                                    accounts.push({
                                                        login: response.data.user.d_name,
                                                        password: document.querySelector('#save-account-password')?.value
                                                    });
    
                                                    container.querySelector('#accounts-container')?.append(createUserElement(accounts.at(-1)));
                                                    localStorage.setItem('switcher-accounts', JSON.stringify(accounts));
                                                    this.parentElement.remove();
                                                }
                                            });
                                        }
                                    })
                                ],
                                id: 'login-container',
                                style: {
                                    display: 'flex',
                                    flexDirection: 'column',
                                    gap: '0.4rem',
                                    marginTop: '1rem'
                                }
                            }));
                            this.classList.add('moderator-remove-race');
                            this.innerText = 'Cancel';
                        }
                    })
                ],
                className: 'simplemodal-container',
                id: 'signup_login_container',
                style: {
                    display: 'flex',
                    flexDirection: 'column',
                    gap: '0.6rem',
                    height: 'fit-content',
                    inset: 0,
                    margin: 'auto',
                    maxHeight: '50vmin',
                    overflow: 'hidden auto',
                    padding: '50px',
                    position: 'fixed',
                    width: '360px',
                    zIndex: 1002
                }
            });
    
            document.body.append(overlay, container);
        });
    }
    
    function createElement(type, options) {
        const callback = arguments[arguments.length - 1];
        const element = document.createElement(type);
        if ('innerText' in options) {
            element.innerText = options.innerText;
            delete options.innerText;
        }
    
        for (const attribute in options) {
            if (typeof options[attribute] == 'object') {
                if (options[attribute] instanceof Array) {
                    if (/^children$/i.test(attribute)) {
                        element.append(...options[attribute]);
                    } else if (/^on/i.test(attribute)) {
                        for (const listener of options[attribute]) {
                            element.addEventListener(attribute.slice(2), listener);
                        }
                    }
                } else if (/^style$/i.test(attribute)) {
                    Object.assign(element[attribute.toLowerCase()], options[attribute]);
                }
    
                delete options[attribute];
            }
        }
    
        Object.assign(element, options);
        return typeof callback == 'function' && callback(element), element;
    }
    
    function createUserElement({ login, password }) {
        let container = createElement('div', {
            children: [
                createElement('button', {
                    className: 'new-button button-type-1',
                    innerText: login,
                    style: {
                        width: '-webkit-fill-available'
                    },
                    onclick() {
                        document.querySelector('#simplemodal-overlay')?.remove();
                        document.querySelector('#signup_login_container')?.remove();
                        Application.Helpers.AjaxHelper.post('/auth/standard_login', { login, password }).done(function(response) {
                            response.result && Application.events.publish('auth.login', response.data.user, response.data.user_stats);
                        });
                    }
                }),
                createElement('button', {
                    className: 'btn new-button button-type-1 moderator-remove-race',
                    innerText: 'X',
                    style: {
                        aspectRatio: 1,
                        backgroundImage: 'linear-gradient(#ee5f5b,#c43c35)',
                        marginRight: 0
                    },
                    onclick() {
                        let accounts = JSON.parse(localStorage.getItem('switcher-accounts')) ?? [];
                        accounts.splice(accounts.indexOf(accounts.find((account) => account.login === login)), 1);
                        localStorage.setItem('switcher-accounts', JSON.stringify(accounts));
                        container.remove();
                    }
                })
            ],
            style: {
                display: 'flex',
                gap: '0.25rem'
            }
        });
    
        return container;
    }
    
     
    RandomTurtleBoi, Azgr00 and Vince0 like this.

Share This Page