Discord Token Extractor

一键提取并复制Discord Token到剪贴板

  1. // ==UserScript==
  2. // @name Discord Token Extractor
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @license MIT
  6. // @description 一键提取并复制Discord Token到剪贴板
  7. // @author cwser
  8. // @match https://discord.com/*
  9. // @grant GM_addStyle
  10. // @grant GM_setClipboard
  11. // @connect discord.com
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // 创建浮动按钮
  18. function createButton() {
  19. const button = document.createElement('button');
  20. button.id = 'discord-token-extractor';
  21. button.textContent = '📌 获取Discord Token';
  22. button.style.cssText = `
  23. position: fixed;
  24. bottom: 74px;
  25. right: 20px;
  26. z-index: 9999;
  27. background-color: #5865F2;
  28. color: white;
  29. border: none;
  30. border-radius: 5px;
  31. padding: 10px 15px;
  32. font-size: 14px;
  33. cursor: pointer;
  34. box-shadow: 0 2px 10px rgba(0,0,0,0.2);
  35. transition: all 0.3s ease;
  36. `;
  37.  
  38. // 按钮悬停效果
  39. button.addEventListener('mouseenter', () => {
  40. button.style.transform = 'scale(1.05)';
  41. button.style.boxShadow = '0 4px 15px rgba(88, 101, 242, 0.4)';
  42. });
  43.  
  44. button.addEventListener('mouseleave', () => {
  45. button.style.transform = 'scale(1)';
  46. button.style.boxShadow = '0 2px 10px rgba(0,0,0,0.2)';
  47. });
  48.  
  49. // 添加按钮到页面
  50. document.body.appendChild(button);
  51. return button;
  52. }
  53.  
  54. // 创建通知元素
  55. function createNotification(message) {
  56. const notification = document.createElement('div');
  57. notification.textContent = message;
  58. notification.style.cssText = `
  59. position: fixed;
  60. bottom: 80px;
  61. right: 20px;
  62. z-index: 9999;
  63. background-color: #2C2F33;
  64. color: white;
  65. border-radius: 5px;
  66. padding: 10px 15px;
  67. font-size: 14px;
  68. box-shadow: 0 2px 10px rgba(0,0,0,0.2);
  69. opacity: 0;
  70. transform: translateY(10px);
  71. transition: all 0.3s ease;
  72. `;
  73.  
  74. document.body.appendChild(notification);
  75.  
  76. // 显示通知
  77. setTimeout(() => {
  78. notification.style.opacity = '1';
  79. notification.style.transform = 'translateY(0)';
  80. }, 10);
  81.  
  82. // 自动隐藏通知
  83. setTimeout(() => {
  84. notification.style.opacity = '0';
  85. notification.style.transform = 'translateY(10px)';
  86. setTimeout(() => notification.remove(), 300);
  87. }, 3000);
  88.  
  89. return notification;
  90. }
  91.  
  92. // 提取并复制Token
  93. function extractAndCopyToken() {
  94. const notification = createNotification('正在查找Token...');
  95.  
  96. // 尝试从localStorage提取
  97. try {
  98. const token = JSON.parse(localStorage.getItem('token')).replace(/"/g, '');
  99. if (token) {
  100. GM_setClipboard(token);
  101. notification.textContent = '✅ Token已复制到剪贴板!';
  102. console.log('[Discord Token Extractor] 已成功提取并复制Token:', token);
  103. return;
  104. }
  105. } catch (e) {
  106. console.log('[Discord Token Extractor] 无法从localStorage提取Token:', e);
  107. }
  108.  
  109. // 如果localStorage方法失败,尝试从网络请求提取
  110. try {
  111. // 创建一个临时的XHR拦截器
  112. const originalXhr = window.XMLHttpRequest;
  113. window.XMLHttpRequest = function() {
  114. const xhr = new originalXhr();
  115. xhr.addEventListener('readystatechange', function() {
  116. if (xhr.readyState === 4 && xhr.status === 200) {
  117. const authHeader = xhr.getResponseHeader('Authorization');
  118. if (authHeader) {
  119. GM_setClipboard(authHeader);
  120. notification.textContent = '✅ Token已复制到剪贴板!';
  121. console.log('[Discord Token Extractor] 已成功从XHR请求提取并复制Token:', authHeader);
  122. // 恢复原始XHR
  123. window.XMLHttpRequest = originalXhr;
  124. }
  125. }
  126. });
  127. return xhr;
  128. };
  129.  
  130. // 触发一个无害的请求来尝试获取Token
  131. fetch('https://discord.com/api/v9/users/@me', {
  132. method: 'GET',
  133. headers: {
  134. 'Content-Type': 'application/json',
  135. },
  136. credentials: 'include'
  137. }).catch(() => {}); // 忽略错误,只关心是否能获取到Token
  138.  
  139. notification.textContent = '🔍 正在监听网络请求,请稍候...';
  140. notification.textContent = '⚠️ 未能自动提取Token,请确保已登录或尝试刷新页面';
  141.  
  142. } catch (e) {
  143. console.error('[Discord Token Extractor] 提取Token时出错:', e);
  144. notification.textContent = '❌ 提取Token失败,请手动检查控制台';
  145. }
  146. }
  147.  
  148. // 初始化
  149. window.addEventListener('load', function() {
  150. const button = createButton();
  151. button.addEventListener('click', extractAndCopyToken);
  152. });
  153. })();