Login Via Token

Adds a native looking button to the login screen for your token.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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         Login Via Token
// @namespace    https://v15.studio/
// @version      v4.0.0
// @description  Adds a native looking button to the login screen for your token.
// @author       Emmet_v15
// @license      BSD
// @match        *://discord.com/login
// @grant        none
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @run-at       document-end
// ==/UserScript==

if (window.location.pathname === '/login' && localStorage.token && !localStorage.working) {
    localStorage.removeItem('token');
    window.location.reload();
} else if (localStorage.working) {
    localStorage.removeItem('working');
}

function waitForElm(selector) {
    return new Promise(resolve => {
        if (document.querySelector(selector)) {
            return resolve(document.querySelector(selector));
        }

        const observer = new MutationObserver(mutations => {
            if (document.querySelector(selector)) {
                resolve(document.querySelector(selector));
                observer.disconnect();
            }
        });

        observer.observe(document.body, {
            childList: true,
            subtree: true
        });
    });
}
waitForElm('button[type="submit"][class*="button__"]').then((elm) => {

    const customButton = elm.cloneNode(true);
    customButton.id = 'tokenLoginBtn';
    customButton.type = 'button';
    const buttonText = customButton.querySelector('[class*="contents__"]');
    if (buttonText) buttonText.textContent = 'Log In Via Token';

    elm.className = elm.className.replace(/marginBottom8_(\S+)/g, 'marginBottom20_$1');
    elm.addEventListener('click', function() {
        document.getElementById('tokenInput').value = " ";
    });

    const passwordField = document.querySelector('[name="password"]');
    const fieldWrapper = passwordField.closest('[class*="container__"][data-layout="vertical"]');

    const tokenFieldHTML = fieldWrapper.outerHTML
        .replace(/password/g, 'token')
        .replace(/Password/g, 'Token')
        .replace(/uid_\d+/g, 'tokenInput')
        .replace(/:r\d+:/g, 'tokenLabel');

    const container = document.createElement('div');
    container.innerHTML = tokenFieldHTML;
    const tokenField = container.firstChild;

    const marginClass = document.querySelector('[class*="marginBottom20"]').className.match(/marginBottom20\S+/)[0];
    if (marginClass) {
        tokenField.classList.add(marginClass);
    } else {
        tokenField.style.marginBottom = '20px';
    }

    elm.parentNode.insertBefore(tokenField, elm.nextSibling);
    elm.parentNode.insertBefore(customButton, tokenField.nextSibling);

    customButton.addEventListener('click', function() {
        const token = document.getElementById('tokenInput').value.trim();
        const iframe = document.body.appendChild(document.createElement('iframe'));
        iframe.contentWindow.localStorage.token = `"${token}"`;
        iframe.contentWindow.localStorage.working = `1`;
        window.location.reload();
    });
});