token switcher

try to take over your tokens!

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         token switcher
// @namespace    https://tampermonkey.net/
// @version      2.0.2
// @description  try to take over your tokens!
// @author       sophb.chan
// @core_author  sophb.chan
// @core_version 1.1.0
// @match        https://multiplayerpiano.org/*
// @match        https://multiplayerpiano.net/*
// @match        https://dev.multiplayerpiano.net/*
// @match        https://piano.mpp.community/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @license      CC BY-NC-SA 4.0
// @require      https://update.greasyfork.org/scripts/582107/1848144/MPP%20Userscript%20Core.js
// ==/UserScript==

prefix = '~';
private = true

const tokens = readItem('knownTokens', {});
tokens.current = localStorage.token;
tokens.ipbound = '';
let defaultToken = readItem('defaultToken', localStorage.token);

function setDefaultToken(name) {
    if (!user)
        throw new Error('Token name must be specified.');

    if (tokens[name] != null) {
        defaultToken = name;
        storeItem('defaultToken', name);
    } else throw new ReferenceError(`Unknown token "${name}"`);
}
function addToken() {
    const token = prompt(`
(In-built UI coming soon!)
Please specify the token you want to save:
        `.trim());

    if (token == null) return;
    if (!token) {
        alert('Cannot save empty token!');    
        return addToken();
    }

    const name = prompt(`
(In-built UI coming soon!)
Please specify the token's name:
        `.trim());

    if (!name) {
        const label = i => `unnamed-token-${i}`; 
        let unnamedIndex = 0;
        do {
            unnamedIndex++;
        } while (tokens[label(unnamedIndex)] == null);

        name = label(unnamedIndex);
    }

    const isCorrect = confirm(`
Token registered.
Name: ${name}
Token: ${token}

Press Cancel to change the information.
    `.trim());

    if (isCorrect) {
        tokens[name] = token;
        return storeItem('knownTokens', tokens);
    }
    else return addToken();
}

registerCommand('help', (({
    args
} = {}) => {
    receive(`Commands: \`${
        prefix +
        Object.keys(cmds).join(
            `\`, \`${prefix}`
        )
    }\``);
}), {
    aliases: ['h']
});
registerCommand('set', (({
    args
} = {}) => {
    if (args.length === 0) {
        receive('Please specify a user token to set to.');
        receive(`Tokens: \`${Object.keys(tokens).join('`, `')}\``);
        return;
    }
    if (tokens[args[0]]) {
        localStorage.token = tokens[args[0]];
        receive('Token set. Reconnecting...');
        MPP.client.stop();
        MPP.client.start();
    } else receive(`The token \`${args[0]}\` was not found.`);
}));
registerCommand('reset', (() => {
    localStorage.token = tokens[defaultToken];
    send('Token set to default. Reconnecting...');
    MPP.client.stop();
    MPP.client.start();
}));
registerCommand('default', (({
    args
} = {}) => {
    if (args.length === 0) {
        receive('Please specify a user token to set as the default.');
        receive(`Tokens: \`${Object.keys(tokens).join('`, `')}\``);
        return;
    }
    if (tokens[args[0]]) {
        setDefaultToken(args[0]);
        receive(`Default token now set to \`${args[0]}\`.`);
        MPP.client.stop();
        MPP.client.start();
    } else receive(`The token \`${args[0]}\` was not found.`);
}));
registerCommand('add', addToken);