Discord Token Getter

Gets your token on discord.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Discord Token Getter
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Gets your token on discord.
// @author       You
// @match        https://*.discord.com/@me*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    window.onload = function() {
        let popup;
        popup = window.open('');
        if (!popup) return alert('Popup blocked! Please allow popups and try again.');
        popup.document.write("Getting token...")
        window.dispatchEvent(new Event('beforeunload'));
        window.tkn = JSON.parse(popup.localStorage.token);
        popup.close()
    }

    setInterval(function() {
        let userInfo = document.querySelector('div div[class*="children-"] div[class*="background-"] div[class*="fieldList"]');
        if(!userInfo) return;

        let editButton = userInfo.querySelector('button[class*="fieldButton-"]')

        let tokenField = document.getElementById("get-token-field");
        if(tokenField) {
            if(editButton) {
                tokenField.style.display = "";
            } else {
                tokenField.style.display = "none";
            }
            return;
        };

        tokenField = document.createElement("div")
        tokenField.id = "get-token-field"
        tokenField.className = editButton.parentElement.nextElementSibling.className

        let constrainedRow = document.createElement("div")
        constrainedRow.className = userInfo.querySelector('div[class*="constrainedRow-"]').className

        let tokenFieldTitle = document.createElement("h5")
        tokenFieldTitle.innerHTML = "TOKEN"
        tokenFieldTitle.className = editButton.parentElement.querySelector('h5').className

        let tokenFieldContent = document.createElement("span")
        tokenFieldContent.innerHTML = "Token"
        tokenFieldContent.className = editButton.parentElement.querySelector('div div span[class*="colorHeaderPrimary"]').className

        constrainedRow.appendChild(document.createElement("div")).appendChild(tokenFieldTitle).parentElement.appendChild(document.createElement("div")).appendChild(tokenFieldContent)
        tokenField.appendChild(constrainedRow)

        let fieldButtonList = document.createElement("div")
        fieldButtonList.className = userInfo.querySelector('div[class*="fieldButtonList"]').className

        let tokenFieldCopy = document.createElement("button")
        tokenFieldCopy.onclick = function() {
            if(tkn) {
                let tkn2 = tkn.split('')
                tkn2.shift()
                tkn2.pop()
                tkn2 = tkn2.join('')

                let popup = window.open("")

                popup.document.body.innerHTML = `Your token is <input placeholder="Token" readonly>.<br>To reset it, change your username or password.`
                popup.eval(`document.querySelector('input').value = "${tkn2}"`)
                popup.eval(`document.querySelector('input').onclick = function() {
                    let copy = document.querySelector('input')
                    copy.select();
                    copy.setSelectionRange(0, 99999);
                    document.execCommand("copy");

                    let token = copy.value
                    copy.value = "Copied!"

                    setTimeout(function() {
                        copy.value = token
                    }, 1000)
                }`)
            } else {
                alert("Error getting token. Please try again.")
            }
        }
        tokenFieldCopy.innerHTML = "Get"
        tokenFieldCopy.className = editButton.className
        fieldButtonList.appendChild(tokenFieldCopy)

        tokenField.appendChild(fieldButtonList)

        userInfo.appendChild(tokenField)
    }, 50)
})();