token switcher

try to take over your tokens!

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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.greatest.deepsurf.us/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);